Rename users table fields and loan documents table, expand branch billing credentials, switch to /api/admin prefix, refactor auth endpoints, replace PATCH with PUT for status updates, remove file upload APIs, and regenerate Swagger with ordered tags. Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.4 KiB
Go
Executable File
53 lines
1.4 KiB
Go
Executable File
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"online-back/internal/admin/auth"
|
|
"online-back/pkg/client/postgresql"
|
|
"online-back/pkg/logging"
|
|
)
|
|
|
|
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,
|
|
}
|
|
}
|
|
|
|
const (
|
|
loginQuery = `SELECT id, password FROM users WHERE email = $1`
|
|
userByIDQuery = `SELECT id, password FROM users WHERE id = $1`
|
|
profileQuery = `SELECT id, fullname, phone_number, avatar, created_at
|
|
FROM users WHERE id = $1`
|
|
)
|
|
|
|
func (r *repository) Login(ctx context.Context, dto auth.LoginDTO) (auth.UserCredentials, error) {
|
|
var result auth.UserCredentials
|
|
err := r.client.QueryRow(ctx, loginQuery, dto.Email).Scan(&result.Id, &result.Password)
|
|
return result, err
|
|
}
|
|
|
|
func (r *repository) GetUserByID(ctx context.Context, id int) (auth.UserCredentials, error) {
|
|
var result auth.UserCredentials
|
|
err := r.client.QueryRow(ctx, userByIDQuery, id).Scan(&result.Id, &result.Password)
|
|
return result, err
|
|
}
|
|
|
|
func (r *repository) GetProfile(ctx context.Context, id int) (auth.UserProfileDTO, error) {
|
|
var profile auth.UserProfileDTO
|
|
err := r.client.QueryRow(ctx, profileQuery, id).Scan(
|
|
&profile.Id,
|
|
&profile.FullName,
|
|
&profile.PhoneNumber,
|
|
&profile.Avatar,
|
|
&profile.CreatedAt,
|
|
)
|
|
return profile, err
|
|
}
|