Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Pool = &Repositories{
&roleRepository{},
&userRepository{},
}
Pool a repository pool to store all
Functions ¶
Types ¶
type IRoleRepository ¶
type IRoleRepository interface {
// GetRolesByUserID retrieves all roles associated with the given user ID.
// Returns a slice of Role models containing the role data.
//
// Parameters:
// - userID (int): The unique identifier of the user
//
// Returns:
// - []models.Role: Slice of Role models containing the role data
GetRolesByUserID(userID int) []models.Role
// GetRolesBySlug retrieves a list of roles that match the specified slug values.
// Parameters:
// - roleSlugs (...types.Role): A variadic parameter representing the slugs to filter roles by.
// Returns:
// - ([]models.Role): A slice of roles matching the provided slugs.
GetRolesBySlug(roleSlugs ...types.Role) []models.Role
// AddRoleForUserID assigns a role to a user by their ID.
// Creates a new user-role mapping in the database.
//
// Parameters:
// - userID (int): The unique identifier of the user
// - roleSlug (types.Role): The slug name of the role to assign
//
// Returns:
// - error: Returns nil on success, error on failure
AddRoleForUserID(userID int, roleSlug types.Role) error
// SyncRolesWithUser synchronizes ro
// les for a given user.
// It associates the user with the specified roles by slug.
// Parameters:
// - userID (int): The unique identifier of the user.
// - roleSlugs (...types.Role): A variadic parameter representing the slugs of roles to synchronize.
// Returns:
// - (error): An error if the synchronization fails.
SyncRolesWithUser(userID int, roleSlugs ...types.Role) (err error)
}
IRoleRepository defines the interface for managing user roles. It provides methods for retrieving and assigning roles to users.
Methods:
- GetRolesByUserID(userID int) []models.Role: Retrieves roles of specific user. Retrieves all roles associated with a specific user ID.
- GetRolesBySlug(roleSlugs ...types.Role) []models.Role: Retrieves a list of roles that match the specified slug values.
- AddRoleForUserID(userID int, roleSlug types.Role) error: Add a role via slug for user. Creates a new user-role mapping in the database.
- SyncRolesWithUser(userID int, roleSlugs ...types.Role) (err error): Synchronizes roles for a given user, associating the user with the specified roles.
type IUserRepository ¶
type IUserRepository interface {
// GetUserByEmail retrieves a user by their email address.
// Parameters:
// - email (string): The email address of the user to retrieve.
//
// Returns:
// - (*models.User): The user associated with the given email address, or nil if not found.
GetUserByEmail(email string) *models.User
// GetUserByToken retrieves a user based on their authentication token.
// Parameters:
// - token (string): The authentication token of the user to retrieve.
//
// Returns:
// - (*models.User): The user associated with the given token, or nil if not found.
GetUserByToken(token string) *models.User
}
IUserRepository represents the interface for managing user-related data in the repository. It provides methods for CRUD operations and additional utility functions.
Methods:
- GetUserByEmail(email string) *models.User: Retrieves a user by their email address.
- GetUserByToken(token string) *models.User: Retrieves a user by their authentication token.
- SelectUser(page, limit int) ([]*models.User, int, error): Retrieves a paginated list of users with the total count.
type Repositories ¶
type Repositories struct {
IRoleRepository
IUserRepository
}
Repositories struct for collect all app repositories.
Click to show internal directories.
Click to hide internal directories.