initial commit
This commit is contained in:
78
internal/repository/user_repository.go
Normal file
78
internal/repository/user_repository.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.kirlllll.ru/volontery/backend/internal/database"
|
||||
)
|
||||
|
||||
// UserRepository предоставляет методы для работы с пользователями
|
||||
type UserRepository struct {
|
||||
queries *database.Queries
|
||||
}
|
||||
|
||||
// NewUserRepository создает новый UserRepository
|
||||
func NewUserRepository(queries *database.Queries) *UserRepository {
|
||||
return &UserRepository{queries: queries}
|
||||
}
|
||||
|
||||
// GetByID получает пользователя по ID
|
||||
func (r *UserRepository) GetByID(ctx context.Context, id int64) (*database.GetUserByIDRow, error) {
|
||||
result, err := r.queries.GetUserByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GetByEmail получает пользователя по email
|
||||
func (r *UserRepository) GetByEmail(ctx context.Context, email string) (*database.GetUserByEmailRow, error) {
|
||||
result, err := r.queries.GetUserByEmail(ctx, email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// Create создает нового пользователя
|
||||
func (r *UserRepository) Create(ctx context.Context, params database.CreateUserParams) (*database.CreateUserRow, error) {
|
||||
result, err := r.queries.CreateUser(ctx, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// EmailExists проверяет существование email
|
||||
func (r *UserRepository) EmailExists(ctx context.Context, email string) (bool, error) {
|
||||
return r.queries.EmailExists(ctx, email)
|
||||
}
|
||||
|
||||
// UpdateLastLogin обновляет время последнего входа
|
||||
func (r *UserRepository) UpdateLastLogin(ctx context.Context, id int64) error {
|
||||
return r.queries.UpdateLastLogin(ctx, id)
|
||||
}
|
||||
|
||||
// GetProfile получает профиль пользователя
|
||||
func (r *UserRepository) GetProfile(ctx context.Context, id int64) (*database.GetUserProfileRow, error) {
|
||||
result, err := r.queries.GetUserProfile(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// UpdateProfile обновляет профиль пользователя
|
||||
func (r *UserRepository) UpdateProfile(ctx context.Context, params database.UpdateUserProfileParams) error {
|
||||
return r.queries.UpdateUserProfile(ctx, params)
|
||||
}
|
||||
|
||||
// UpdateLocation обновляет геолокацию пользователя
|
||||
func (r *UserRepository) UpdateLocation(ctx context.Context, params database.UpdateUserLocationParams) error {
|
||||
return r.queries.UpdateUserLocation(ctx, params)
|
||||
}
|
||||
|
||||
// VerifyEmail подтверждает email пользователя
|
||||
func (r *UserRepository) VerifyEmail(ctx context.Context, id int64) error {
|
||||
return r.queries.VerifyUserEmail(ctx, id)
|
||||
}
|
||||
Reference in New Issue
Block a user