ЛР 2: PostgreSQL, сессии в Valkey, кэш истории (трек 1)

This commit is contained in:
Нурлыгаянова Екатерина
2026-10-29 11:29:38 +03:00
parent 65003b6119
commit 1503b5db81
132 changed files with 15114 additions and 20 deletions
+44
View File
@@ -0,0 +1,44 @@
package service
import (
"context"
"gitflic.ru/project/relationskatie/mtusi2026lab1-ashchkl/internal/domain"
"gitflic.ru/project/relationskatie/mtusi2026lab1-ashchkl/internal/password"
"gitflic.ru/project/relationskatie/mtusi2026lab1-ashchkl/internal/store"
"gitflic.ru/project/relationskatie/mtusi2026lab1-ashchkl/internal/validate"
)
var (
_ UsersService = (*Users)(nil)
)
type Users struct {
store store.UserStore
hasher *password.Hasher
}
func NewUsers(s store.UserStore, h *password.Hasher) *Users {
return &Users{store: s, hasher: h}
}
func (u *Users) Register(ctx context.Context, username, displayName, plainPassword string) (domain.User, error) {
if err := validate.Username(username); err != nil {
return domain.User{}, err
}
if err := validate.DisplayName(displayName); err != nil {
return domain.User{}, err
}
if err := validate.Password(plainPassword); err != nil {
return domain.User{}, err
}
hash, err := u.hasher.Hash(ctx, plainPassword)
if err != nil {
return domain.User{}, err
}
return u.store.CreateUser(ctx, username, displayName, hash)
}
func (u *Users) Me(ctx context.Context, callerID string) (domain.User, error) {
return u.store.UserByID(ctx, callerID)
}