repository

package
v0.0.0-...-1f25b16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package repository provides data access implementations.

Package repository provides data access implementations.

Package repository provides data access implementations.

Package repository provides data access implementations.

Package repository provides data access implementations.

Index

Constants

This section is empty.

Variables

ProviderSet provides all repository layer dependencies.

Functions

func Count

func Count(ctx context.Context, db *gorm.DB, model any, filters map[string]any, notFilters map[string]any) (int64, error)

Count is a generic function to count the number of records in the database.

func IsExists

func IsExists(ctx context.Context, db *gorm.DB, model any, filters map[string]any, notFilters map[string]any) (bool, error)

IsExists is a generic function to check if a record exists in the database.

func NewDepartmentRepository

func NewDepartmentRepository(data *Data) usecase.DepartmentRepository

NewDepartmentRepository creates a new instance of department repository.

func NewRoleRepository

func NewRoleRepository(data *Data) usecase.RoleRepository

NewRoleRepository creates a new instance of role repository.

func NewTransaction

func NewTransaction(d *Data) usecase.Transaction

func NewUserRepository

func NewUserRepository(data *Data) usecase.UserRepository

NewUserRepository creates a new instance of user repository.

Types

type Data

type Data struct {
	// contains filtered or unexported fields
}

Data manages data access resources and their lifecycle.

func NewData

func NewData(cfgPG *config.PG, cfgRedis *config.Redis, cfgRabbitMQ *config.RabbitMQ, logger *zap.Logger) (*Data, func(), error)

NewData creates a new Data instance with database, redis, and optional RabbitMQ connections. Returns Data instance and a cleanup function.

func (*Data) DB

func (d *Data) DB(ctx context.Context) *gorm.DB

DB returns the database connection, honoring any transaction in the context.

func (*Data) RabbitMQ

func (d *Data) RabbitMQ() *mq.RabbitMQ

RabbitMQ returns the RabbitMQ client if initialized, or nil otherwise.

func (*Data) Redis

func (d *Data) Redis() *redis.Client

Redis returns the Redis client.

func (*Data) Transaction

func (d *Data) Transaction(ctx context.Context, fn func(ctx context.Context) error) error

Transaction executes a function within a database transaction. It automatically commits the transaction if the function returns without error, and automatically rolls back the transaction otherwise.

type DepartmentRepository

type DepartmentRepository struct {
	// contains filtered or unexported fields
}

DepartmentRepository is an implementation of the department repository.

func (*DepartmentRepository) Count

func (r *DepartmentRepository) Count(ctx context.Context, filters map[string]any, notFilters map[string]any) (int64, error)

Count counts the number of departments.

func (*DepartmentRepository) Create

func (r *DepartmentRepository) Create(ctx context.Context, department *model.Department) error

Create adds a new department to the database.

func (*DepartmentRepository) Delete

func (r *DepartmentRepository) Delete(ctx context.Context, id uint) error

Delete removes a department by ID.

func (*DepartmentRepository) FindByID

func (r *DepartmentRepository) FindByID(ctx context.Context, id uint) (*model.Department, error)

FindByID retrieves a department by ID.

func (*DepartmentRepository) IsExists

func (r *DepartmentRepository) IsExists(ctx context.Context, filters map[string]any, notFilters map[string]any) (bool, error)

IsExists checks if a department exists in the database.

func (*DepartmentRepository) List

func (r *DepartmentRepository) List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*model.Department, int, error)

List retrieves departments with pagination and filtering.

func (*DepartmentRepository) Update

func (r *DepartmentRepository) Update(ctx context.Context, department *model.Department, params map[string]any) error

Update updates a department.

type RoleRepository

type RoleRepository struct {
	// contains filtered or unexported fields
}

RoleRepository is an implementation of the role repository.

func (*RoleRepository) Count

func (r *RoleRepository) Count(ctx context.Context, filters map[string]any, notFilters map[string]any) (int64, error)

Count counts the number of roles.

func (*RoleRepository) Create

func (r *RoleRepository) Create(ctx context.Context, role *model.Role) error

Create adds a new role to the database.

func (*RoleRepository) Delete

func (r *RoleRepository) Delete(ctx context.Context, id uint) error

Delete removes a role by ID.

func (*RoleRepository) FindByID

func (r *RoleRepository) FindByID(ctx context.Context, id uint) (*model.Role, error)

FindByID retrieves a role by ID.

func (*RoleRepository) IsExists

func (r *RoleRepository) IsExists(ctx context.Context, filters map[string]any, notFilters map[string]any) (bool, error)

func (*RoleRepository) List

func (r *RoleRepository) List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*model.Role, int, error)

List retrieves roles with pagination and filtering.

func (*RoleRepository) Update

func (r *RoleRepository) Update(ctx context.Context, role *model.Role, params map[string]any) error

Update updates a role.

type UserRepository

type UserRepository struct {
	// contains filtered or unexported fields
}

UserRepository is an implementation of the user repository.

func (*UserRepository) Count

func (r *UserRepository) Count(ctx context.Context, filters map[string]any, notFilters map[string]any) (int64, error)

func (*UserRepository) Create

func (r *UserRepository) Create(ctx context.Context, user *model.User) error

Create adds a new user to the database.

func (*UserRepository) Delete

func (r *UserRepository) Delete(ctx context.Context, id uint) error

Delete removes a user by ID.

func (*UserRepository) DeleteRSAPrivateKey

func (r *UserRepository) DeleteRSAPrivateKey(ctx context.Context, cacheKey string) error

DeleteRSAPrivateKey removes the RSA private key from the cache.

func (*UserRepository) FindByID

func (r *UserRepository) FindByID(ctx context.Context, id uint) (*model.User, error)

FindByID retrieves a user by ID.

func (*UserRepository) FindByUsername

func (r *UserRepository) FindByUsername(ctx context.Context, username string) (*model.User, error)

FindByUsername retrieves a user by username.

func (*UserRepository) GetRSAPrivateKey

func (r *UserRepository) GetRSAPrivateKey(ctx context.Context, cacheKey string) ([]byte, error)

func (*UserRepository) IsExists

func (r *UserRepository) IsExists(ctx context.Context, filters map[string]any, notFilters map[string]any) (bool, error)

func (*UserRepository) List

func (r *UserRepository) List(ctx context.Context, filters map[string]any, limit, offset int, sortClause string) ([]*model.User, int, error)

List retrieves users with pagination and filtering.

func (*UserRepository) SetRSAPrivateKey

func (r *UserRepository) SetRSAPrivateKey(ctx context.Context, cacheKey string, privateKey []byte) error

SetRSAPrivateKey sets the RSA private key in the cache.

func (*UserRepository) Update

func (r *UserRepository) Update(ctx context.Context, user *model.User, params map[string]any) error

Update updates a user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL