Documentation
¶
Index ¶
- Variables
- type AuthUser
- type LoginInput
- type LoginResponse
- type RegisterInput
- type UserPayload
- type UserService
- func (s *UserService) DeleteUser(id uint, currentUserID uint) error
- func (s *UserService) HasUsers() (bool, error)
- func (s *UserService) ListUsers() ([]UserPayload, error)
- func (s *UserService) Login(in LoginInput) (*LoginResponse, error)
- func (s *UserService) Register(in RegisterInput) (*LoginResponse, error)
- func (s *UserService) UpdateLastActivity(userID uint) error
- func (s *UserService) UpdateUserRole(id uint, newRole string, currentUserID uint) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type LoginInput ¶
LoginInput is the input for Login.
type LoginResponse ¶
type LoginResponse struct {
Token string `json:"token"`
User *UserPayload `json:"user"`
}
LoginResponse is the response for login/register.
type RegisterInput ¶
RegisterInput is the input for Register.
type UserPayload ¶
type UserPayload struct {
ID uint `json:"id"`
Username string `json:"username"`
Role string `json:"role"`
}
UserPayload is the user data returned in API responses.
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService handles user business logic.
func NewUserService ¶
func NewUserService(db *gorm.DB, cfg *config.Config) *UserService
NewUserService creates a UserService.
func (*UserService) DeleteUser ¶
func (s *UserService) DeleteUser(id uint, currentUserID uint) error
DeleteUser deletes a user (admin only). Cannot delete self.
func (*UserService) HasUsers ¶
func (s *UserService) HasUsers() (bool, error)
HasUsers returns true if any users exist.
func (*UserService) ListUsers ¶
func (s *UserService) ListUsers() ([]UserPayload, error)
ListUsers returns all users (admin only).
func (*UserService) Login ¶
func (s *UserService) Login(in LoginInput) (*LoginResponse, error)
Login authenticates a user and returns a token.
func (*UserService) Register ¶
func (s *UserService) Register(in RegisterInput) (*LoginResponse, error)
Register creates a new user. First user becomes admin.
func (*UserService) UpdateLastActivity ¶
func (s *UserService) UpdateLastActivity(userID uint) error
UpdateLastActivity sets LastActivityAt for the user.
func (*UserService) UpdateUserRole ¶
func (s *UserService) UpdateUserRole(id uint, newRole string, currentUserID uint) error
UpdateUserRole updates a user's role (admin only). Cannot change own role.
Click to show internal directories.
Click to hide internal directories.