package db import ( "bankline/internal/admin/auth" "bankline/pkg/client/postgresql" "bankline/pkg/logging" "context" "strconv" _ "github.com/lib/pq" ) type repository struct { client postgresql.Client logger *logging.Logger } func NewRepository(client postgresql.Client, logger *logging.Logger) auth.Repository { return &repository{ client: client, logger: logger, } } func (r *repository) Login(ctx context.Context, dto auth.LoginDTO) (auth.ResLoginDTO, error) { var ( result auth.ResLoginDTO ) q := `select id, password from admin where login = $1 ;` err := r.client.QueryRow(ctx, q, dto.Login).Scan(&result.Id, &result.Password) if err != nil { return result, err } return result, nil } func (r *repository) CheckAdmin(ctx context.Context, id int) (auth.ResLoginDTO, error) { var ( result auth.ResLoginDTO ) q := `select id, password from admin where id = $1 ;` err := r.client.QueryRow(ctx, q, id).Scan(&result.Id, &result.Password) if err != nil { return result, err } return result, nil } func (r *repository) GetProfile(ctx context.Context, uuid string) (auth.ResUserDTO, error) { var ( ad auth.ResUserDTO ) id, _ := strconv.Atoi(uuid) q := `select id, fullname, phone_number, avatar, created_at from admin where id = $1;` err := r.client.QueryRow(ctx, q, id).Scan( &ad.Id, &ad.FullName, &ad.PhoneNumber, &ad.Avatar, &ad.CreatedAt, ) if err != nil { return ad, err } return ad, nil }