settings section
This commit is contained in:
58
internal/admin/auth/db/postgresql.go
Executable file
58
internal/admin/auth/db/postgresql.go
Executable file
@@ -0,0 +1,58 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"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 admin WHERE login = $1`
|
||||
adminQuery = `SELECT id, password FROM admin WHERE id = $1`
|
||||
profileQuery = `SELECT id, fullname, phone_number, avatar, created_at
|
||||
FROM admin WHERE id = $1`
|
||||
)
|
||||
|
||||
func (r *repository) Login(ctx context.Context, dto auth.LoginDTO) (auth.ResLoginDTO, error) {
|
||||
var result auth.ResLoginDTO
|
||||
err := r.client.QueryRow(ctx, loginQuery, dto.Login).Scan(&result.Id, &result.Password)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *repository) CheckAdmin(ctx context.Context, id int) (auth.ResLoginDTO, error) {
|
||||
var result auth.ResLoginDTO
|
||||
err := r.client.QueryRow(ctx, adminQuery, id).Scan(&result.Id, &result.Password)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *repository) GetProfile(ctx context.Context, id string) (auth.ResUserDTO, error) {
|
||||
var profile auth.ResUserDTO
|
||||
adminID, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
return profile, err
|
||||
}
|
||||
|
||||
err = r.client.QueryRow(ctx, profileQuery, adminID).Scan(
|
||||
&profile.Id,
|
||||
&profile.FullName,
|
||||
&profile.PhoneNumber,
|
||||
&profile.Avatar,
|
||||
&profile.CreatedAt,
|
||||
)
|
||||
return profile, err
|
||||
}
|
||||
Reference in New Issue
Block a user