repo

package
v0.0.0-...-a78aad3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

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 Paginated

type Paginated[T any] struct {
	TotalItems  uint `json:"total_items"`
	TotalPages  uint `json:"total_pages"`
	CurrentPage uint `json:"current_page"`
	Items       []T  `json:"items"`
}

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 UserCore

type UserCore struct {
	Email        string `json:"email"`
	PasswordHash string `json:"-"`
}

type UserRepository

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

func NewUserRepo

func NewUserRepo(db *sql.DB) *UserRepository

func (*UserRepository) Create

func (repo *UserRepository) Create(ctx context.Context, user *UserCore) (uint, error)

func (*UserRepository) DeleteById

func (repo *UserRepository) DeleteById(ctx context.Context, id uint) error

func (*UserRepository) GetAll

func (repo *UserRepository) GetAll(ctx context.Context, page uint) (*Paginated[*User], error)

func (*UserRepository) GetByEmail

func (repo *UserRepository) GetByEmail(ctx context.Context, email string) (*User, error)

func (*UserRepository) GetById

func (repo *UserRepository) GetById(ctx context.Context, userId uint) (*User, error)

func (*UserRepository) Update

func (repo *UserRepository) Update(ctx context.Context, id uint, updates map[string]any) error

Jump to

Keyboard shortcuts

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