Documentation
¶
Index ¶
Constants ¶
View Source
const ( // Field names for validation messages EMAIL_FIELD = "email" PASSWORD_FIELD = "password" NAME_FIELD = "name" PHONE_FIELD = "phone" ROLE_IDS_FIELD = "role_ids" ROLE_NAMES_FIELD = "role_names" USER_ID_FIELD = "user_id" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssignRolesRequest ¶
type AssignRolesRequest struct {
RoleNames []string `json:"role_names"`
}
AssignRolesRequest represents the request to assign roles to a user
func (*AssignRolesRequest) Validate ¶
func (a *AssignRolesRequest) Validate() []response.ErrorInfo
type AuthHandler ¶
type AuthHandler interface { // Registration and authentication Register(c *fiber.Ctx) error Login(c *fiber.Ctx) error Logout(c *fiber.Ctx) error // User management GetUserByID(c *fiber.Ctx) error UpdateUser(c *fiber.Ctx) error // Role management AssignRoles(c *fiber.Ctx) error GetUserRoles(c *fiber.Ctx) error }
AuthHandler defines the interface for auth-related HTTP handlers
type AuthRepository ¶
type AuthRepository interface { // User operations CreateUser(ctx context.Context, user *User) error GetUserByEmail(ctx context.Context, email string) (*User, error) GetUserByID(ctx context.Context, id uuid.UUID) (*User, error) UpdateUser(ctx context.Context, user *User) error DeleteUser(ctx context.Context, id uuid.UUID) error // Role operations GetRolesByNames(ctx context.Context, names []string) ([]Role, error) GetRoleByID(ctx context.Context, id uuid.UUID) (*Role, error) AssignRolesToUser(ctx context.Context, userID uuid.UUID, roleIDs []uuid.UUID) error GetUserRoles(ctx context.Context, userID uuid.UUID) ([]Role, error) // Token management CreateUserToken(ctx context.Context, token *UserToken) (*UserToken, error) GetUserTokenByID(ctx context.Context, tokenID uuid.UUID) (*UserToken, error) InvalidateUserToken(ctx context.Context, tokenID uuid.UUID) error InvalidateUserTokens(ctx context.Context, userID uuid.UUID) error }
AuthRepository defines the interface for auth-related database operations
type AuthUsecase ¶
type AuthUsecase interface { // User operations Register(ctx context.Context, req *RegisterRequest) (*RegisterResponse, error) Login(ctx context.Context, req *LoginRequest) (*LoginResponse, error) Logout(ctx context.Context, tokenID string) error UpdateUser(ctx context.Context, user *User) error GetUserByID(ctx context.Context, userID uuid.UUID) (*User, error) // Role operations AssignRoles(ctx context.Context, userID uuid.UUID, roleNames []string) error GetUserRoles(ctx context.Context, userID uuid.UUID) ([]Role, error) // Token operations GetUserTokenByID(ctx context.Context, tokenID uuid.UUID) (*UserToken, error) ValidateUserToken(ctx context.Context, tokenID string, token string) error InvalidateUserToken(ctx context.Context, tokenID uuid.UUID) error InvalidateUserTokens(ctx context.Context, userID uuid.UUID) error }
AuthUsecase defines the interface for auth-related business logic
type LoginRequest ¶
type LoginRequest struct { Email string `json:"email" validate:"required,email"` Password string `json:"password" validate:"required"` }
LoginRequest represents the login request payload
func (*LoginRequest) Validate ¶
func (l *LoginRequest) Validate() []response.ErrorInfo
type LoginResponse ¶
type LoginResponse struct { ID uuid.UUID `json:"id"` Email string `json:"email"` Name string `json:"name"` Phone string `json:"phone"` Status string `json:"status"` Token string `json:"token"` ExpiredAt time.Time `json:"expired_at"` }
LoginResponse represents the response after successful login
type RegisterRequest ¶
type RegisterRequest struct { Email string `json:"email" validate:"required,email"` Password string `json:"password" validate:"required,min=8"` Name string `json:"name" validate:"required"` Phone string `json:"phone" validate:"required"` RoleNames []string `json:"role_names" validate:"required,min=1"` }
RegisterRequest represents the registration request payload
func (*RegisterRequest) Validate ¶
func (r *RegisterRequest) Validate() []response.ErrorInfo
type RegisterResponse ¶
type RegisterResponse struct {
User *User `json:"user"`
}
RegisterResponse represents the registration response
type UpdateUserRequest ¶
type UpdateUserRequest struct { Email string `json:"email"` Password string `json:"-"` // Never expose password in JSON Name string `json:"name"` Phone string `json:"phone"` Status string `json:"status"` }
UpdateUserRequest represents the request to update user details
func (*UpdateUserRequest) Validate ¶
func (u *UpdateUserRequest) Validate() []response.ErrorInfo
type User ¶
type User struct { ID uuid.UUID `json:"id"` Email string `json:"email"` Password string `json:"-"` // Never expose password in JSON Name string `json:"name"` Phone string `json:"phone"` Status string `json:"status"` EmailVerifiedAt *time.Time `json:"email_verified_at"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"deleted_at,omitempty"` Roles []Role `json:"roles,omitempty"` }
type UserToken ¶
type UserToken struct { ID uuid.UUID `json:"id"` UserID uuid.UUID `json:"user_id"` Token string `json:"token"` Ability []string `json:"ability"` ExpiredAt time.Time `json:"expired_at"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"deleted_at,omitempty"` }
UserToken represents a user's authentication token
Source Files
¶
Click to show internal directories.
Click to hide internal directories.