github.com/resonatecoop/id@v1.1.0-43/oauth/role.go (about)

     1  package oauth
     2  
     3  import (
     4  	"context"
     5  	"database/sql"
     6  	"errors"
     7  
     8  	"github.com/resonatecoop/user-api/model"
     9  )
    10  
    11  var (
    12  	// ErrRoleNotFound ...
    13  	ErrRoleNotFound = errors.New("Role not found")
    14  )
    15  
    16  // FindRoleByID looks up a role by ID and returns it
    17  func (s *Service) FindRoleByID(id int32) (*model.AccessRole, error) {
    18  	role := new(model.Role)
    19  	err := s.db.NewSelect().Model(role).Where("id = ?", id).Scan(context.Background())
    20  
    21  	if err == sql.ErrNoRows {
    22  		return nil, ErrRoleNotFound
    23  	}
    24  	return (*model.AccessRole)(&role.ID), nil
    25  }