Documentation ¶
Index ¶
- Variables
- type Paginated
- type User
- type UserCore
- type UserRepository
- func (repo *UserRepository) Create(ctx context.Context, user *UserCore) (uint, error)
- func (repo *UserRepository) DeleteById(ctx context.Context, id uint) error
- func (repo *UserRepository) GetAll(ctx context.Context, page uint) (*Paginated[*User], error)
- func (repo *UserRepository) GetByEmail(ctx context.Context, email string) (*User, error)
- func (repo *UserRepository) GetById(ctx context.Context, userId uint) (*User, error)
- func (repo *UserRepository) Update(ctx context.Context, id uint, updates map[string]any) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrUserAlreadyExists = errors.New("user already exists") ErrUserNotFound = errors.New("user not found") UserRepo = NewUserRepo(PostgresDB) )
View Source
var MongoDBClient = func() *mongo.Client { client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(env.MONGODB_URL)) if err != nil { panic("could not connect to mongodb: " + err.Error()) } util.RegisterCleanUp("mongodb connection", func() error { return client.Disconnect(context.TODO()) }) return client }()
View Source
var PostgresDB = func() *sql.DB { db, err := sql.Open("postgres", env.DB_URL) if err != nil { panic("could not connect to PostgreSQL database: " + err.Error()) } util.RegisterCleanUp("postgres connection", func() error { return db.Close() }) return db }()
View Source
var RedisClient = func() *redis.Client { client := redis.NewClient(&redis.Options{ Addr: env.REDIS_HOST + ":" + env.REDIS_PORT, Username: env.REDIS_USERNAME, Password: env.REDIS_PASSWORD, }) util.RegisterCleanUp("redis connection", func() error { return client.Close() }) return client }()
View Source
var SQLiteDB = func() *sql.DB { db, err := sql.Open("sqlite", "sqlite.db") if err != nil { panic("could not open SQLite database: " + err.Error()) } util.RegisterCleanUp("sqlite connection", func() error { return db.Close() }) return db }()
Functions ¶
This section is empty.
Types ¶
type User ¶
type User struct { UserCore Id uint `json:"id"` Role string `json:"role"` FullName string `json:"full_name,omitempty"` Username string `json:"username,omitempty"` DateOfBirth string `json:"date_of_birth"` Gender string `json:"gender,omitempty"` PhoneNumber string `json:"phone_number,omitempty"` AccountStatus string `json:"account_status"` ImageUrl string `json:"image_url"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` }
type UserRepository ¶
type UserRepository struct {
// contains filtered or unexported fields
}
func NewUserRepo ¶
func NewUserRepo(db *sql.DB) *UserRepository
func (*UserRepository) DeleteById ¶
func (repo *UserRepository) DeleteById(ctx context.Context, id uint) error
func (*UserRepository) GetByEmail ¶
Click to show internal directories.
Click to hide internal directories.