Documentation ¶
Index ¶
- Constants
- type CreateUserInput
- type DefaultService
- func (s *DefaultService) Create(ctx context.Context, in CreateUserInput) (*User, error)
- func (s *DefaultService) Delete(ctx context.Context, id string) error
- func (s *DefaultService) FetchByID(ctx context.Context, id string) (*User, error)
- func (s *DefaultService) GenerateToken(ctx context.Context, email, password string) (string, error)
- func (s *DefaultService) SendEmailVerification(ctx context.Context, userID, username, to string) error
- func (s *DefaultService) VerifyToken(ctx context.Context, token string) (*VerifyTokenResponse, error)
- type E
- type MockService
- func (m *MockService) Create(ctx context.Context, in CreateUserInput) (*User, error)
- func (m *MockService) Delete(ctx context.Context, id string) error
- func (m *MockService) FetchByID(ctx context.Context, id string) (*User, error)
- func (m *MockService) GenerateToken(ctx context.Context, email, password string) (string, error)
- func (m *MockService) SendEmailVerification(ctx context.Context, userID, username, to string) error
- func (m *MockService) VerifyToken(ctx context.Context, token string) (*VerifyTokenResponse, error)
- type ParsableError
- type Service
- type ServiceOption
- type User
- type VerifyTokenResponse
Constants ¶
View Source
const ( RoleAdmin role = "admin" RoleUser role = "user" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateUserInput ¶
type CreateUserInput struct { Fullname string Username string Birthdate string Email string Password string ConfirmPassword string }
CreateUserInput represents the input data for creating a user
type DefaultService ¶
type DefaultService struct {
// contains filtered or unexported fields
}
func New ¶
func New(logger *zap.Logger, jwtSigningKey string, repo repo, opts ...ServiceOption) *DefaultService
New instantiates a new users service
func (*DefaultService) Create ¶
func (s *DefaultService) Create(ctx context.Context, in CreateUserInput) (*User, error)
Create creates a new user and returns the created user
func (*DefaultService) Delete ¶
func (s *DefaultService) Delete(ctx context.Context, id string) error
func (*DefaultService) GenerateToken ¶
GenerateToken generates a JWT token for the user
func (*DefaultService) SendEmailVerification ¶
func (s *DefaultService) SendEmailVerification(ctx context.Context, userID, username, to string) error
func (*DefaultService) VerifyToken ¶
func (s *DefaultService) VerifyToken(ctx context.Context, token string) (*VerifyTokenResponse, error)
VerifyToken verifies a JWT token and returns the authentication data
type MockService ¶
type MockService struct { CreateFunc func(ctx context.Context, in CreateUserInput) (*User, error) DeleteFunc func(ctx context.Context, id string) error FetchByIDFunc func(ctx context.Context, id string) (*User, error) GenerateTokenFunc func(ctx context.Context, email, password string) (string, error) VerifyTokenFunc func(ctx context.Context, token string) (*VerifyTokenResponse, error) SendEmailVerificationFunc func(ctx context.Context, userID, username, to string) error }
func (*MockService) Create ¶
func (m *MockService) Create(ctx context.Context, in CreateUserInput) (*User, error)
func (*MockService) GenerateToken ¶
func (*MockService) SendEmailVerification ¶
func (m *MockService) SendEmailVerification(ctx context.Context, userID, username, to string) error
func (*MockService) VerifyToken ¶
func (m *MockService) VerifyToken(ctx context.Context, token string) (*VerifyTokenResponse, error)
type ParsableError ¶
type ParsableError interface {
Error() string
}
type Service ¶
type Service interface { // Create creates a new user and returns the created user with its ID and "user" role Create(ctx context.Context, in CreateUserInput) (*User, error) // Delete soft deletes a user by id Delete(ctx context.Context, id string) error // FetchByID fetches a non-deleted user by id and returns the user FetchByID(ctx context.Context, id string) (*User, error) // GenerateToken generates a JWT token for the user GenerateToken(ctx context.Context, email, password string) (string, error) // VerifyToken verifies a JWT token and returns the user username, id and role VerifyToken(ctx context.Context, token string) (*VerifyTokenResponse, error) // SendEmailVerification sends an email verification to the user. // The user must be created before calling this method. SendEmailVerification(ctx context.Context, userID, username, to string) error }
Service defines the service interface
type ServiceOption ¶ added in v0.0.4
type ServiceOption func(*DefaultService)
func WithEmailVerification ¶ added in v0.0.4
func WithEmailVerification(fromName, fromAddr, endpoint string, emailer emailer) ServiceOption
type User ¶
type User struct { ID string Fullname string Username string Birthdate string Email string EmailVerified bool Role role CreatedAt time.Time UpdatedAt time.Time }
User represents a user domain model
type VerifyTokenResponse ¶
type VerifyTokenResponse struct {
ID, Username, Role string
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.