On branch main

modified:   main_dc/yalarba/api_yal/internal/domain/account/handler.go
	modified:   main_dc/yalarba/api_yal/internal/domain/account/router.go
	modified:   main_dc/yalarba/api_yal/internal/domain/account/service.go
	modified:   main_dc/yalarba/api_yal/internal/domain/auth/router.go
	new file:   main_dc/yalarba/api_yal/internal/domain/comment/dto.go
	new file:   main_dc/yalarba/api_yal/internal/domain/feetback/dto.go
	new file:   main_dc/yalarba/api_yal/internal/domain/object/dto.go
	new file:   main_dc/yalarba/api_yal/internal/domain/object/errors.go
	new file:   main_dc/yalarba/api_yal/internal/domain/object/handler.go
	new file:   main_dc/yalarba/api_yal/internal/domain/object/router.go
	new file:   main_dc/yalarba/api_yal/internal/domain/object/service.go
	new file:   main_dc/yalarba/api_yal/internal/domain/object/types.go
	new file:   main_dc/yalarba/api_yal/internal/domain/rating/dto.go
	modified:   main_dc/yalarba/api_yal/internal/models/rating.go
add and not tested Object's domain
This commit is contained in:
2026-03-31 16:53:24 +05:00
parent 15eed69a45
commit 979c265e36
14 changed files with 1392 additions and 142 deletions
@@ -4,6 +4,8 @@ import (
"api_yal/internal/logger"
"api_yal/internal/models"
"api_yal/internal/repository"
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"time"
@@ -13,29 +15,27 @@ import (
"gorm.io/gorm"
)
// Service интерфейс сервиса аккаунтов
type Service interface {
// AccountService интерфейс сервиса аккаунтов
type AccountService interface {
// Основные операции
GetAccountByID(id uint) (*AccountResponse, error)
GetAccountByEmail(email string) (*AccountResponse, error)
GetAccountWithObjects(id uint) (*AccountWithObjectsResponse, error)
UpdateAccount(id uint, req UpdateAccountRequest) (*AccountResponse, error)
DeleteAccount(id uint) error
// Управление паролем
ChangePassword(userID uint, req ChangePasswordRequest) error
ForgotPassword(email string) (string, error)
ResetPassword(token, newPassword string) error
// Административные функции
ListAccounts(req ListAccountsRequest) (*AccountListResponse, error)
VerifyAccount(accountID uint, req VerifyAccountRequest) error
UpdateAccountStatus(accountID uint, req UpdateAccountStatusRequest) error
// Статистика
GetAccountStats(userID uint) (*AccountStats, error)
GetAccountProfile(userID uint) (*AccountProfileResponse, error)
// Внутренние методы для auth сервиса
GetAccountModelByID(id uint) (*models.Account, error)
GetAccountModelByEmail(email string) (*models.Account, error)
@@ -43,20 +43,20 @@ type Service interface {
UpdateAccountModel(account *models.Account) error
}
// serviceImpl реализация сервиса аккаунтов
type serviceImpl struct {
// accountServiceImpl реализация сервиса аккаунтов
type accountServiceImpl struct {
accountRepo repository.AccountRepository
}
// NewService создает новый экземпляр сервиса аккаунтов
func NewService(accountRepo repository.AccountRepository) Service {
return &serviceImpl{
func NewService(accountRepo repository.AccountRepository) AccountService {
return &accountServiceImpl{
accountRepo: accountRepo,
}
}
// GetAccountByID получает аккаунт по ID
func (s *serviceImpl) GetAccountByID(id uint) (*AccountResponse, error) {
func (s *accountServiceImpl) GetAccountByID(id uint) (*AccountResponse, error) {
l := logger.Get()
l.Debug("Получение аккаунта по ID", zap.Uint("id", id))
@@ -74,7 +74,7 @@ func (s *serviceImpl) GetAccountByID(id uint) (*AccountResponse, error) {
}
// GetAccountByEmail получает аккаунт по email
func (s *serviceImpl) GetAccountByEmail(email string) (*AccountResponse, error) {
func (s *accountServiceImpl) GetAccountByEmail(email string) (*AccountResponse, error) {
l := logger.Get()
l.Debug("Получение аккаунта по email", zap.String("email", email))
@@ -92,7 +92,7 @@ func (s *serviceImpl) GetAccountByEmail(email string) (*AccountResponse, error)
}
// GetAccountWithObjects получает аккаунт с его объектами
func (s *serviceImpl) GetAccountWithObjects(id uint) (*AccountWithObjectsResponse, error) {
func (s *accountServiceImpl) GetAccountWithObjects(id uint) (*AccountWithObjectsResponse, error) {
l := logger.Get()
l.Debug("Получение аккаунта с объектами", zap.Uint("id", id))
@@ -117,7 +117,7 @@ func (s *serviceImpl) GetAccountWithObjects(id uint) (*AccountWithObjectsRespons
}
// UpdateAccount обновляет информацию об аккаунте
func (s *serviceImpl) UpdateAccount(id uint, req UpdateAccountRequest) (*AccountResponse, error) {
func (s *accountServiceImpl) UpdateAccount(id uint, req UpdateAccountRequest) (*AccountResponse, error) {
l := logger.Get()
l.Info("Обновление аккаунта", zap.Uint("id", id))
@@ -171,7 +171,7 @@ func (s *serviceImpl) UpdateAccount(id uint, req UpdateAccountRequest) (*Account
}
// DeleteAccount удаляет аккаунт (мягкое удаление)
func (s *serviceImpl) DeleteAccount(id uint) error {
func (s *accountServiceImpl) DeleteAccount(id uint) error {
l := logger.Get()
l.Info("Удаление аккаунта", zap.Uint("id", id))
@@ -184,7 +184,7 @@ func (s *serviceImpl) DeleteAccount(id uint) error {
}
// ChangePassword изменяет пароль пользователя
func (s *serviceImpl) ChangePassword(userID uint, req ChangePasswordRequest) error {
func (s *accountServiceImpl) ChangePassword(userID uint, req ChangePasswordRequest) error {
l := logger.Get()
l.Info("Смена пароля", zap.Uint("userID", userID))
@@ -220,7 +220,7 @@ func (s *serviceImpl) ChangePassword(userID uint, req ChangePasswordRequest) err
}
// ForgotPassword запрашивает сброс пароля
func (s *serviceImpl) ForgotPassword(email string) (string, error) {
func (s *accountServiceImpl) ForgotPassword(email string) (string, error) {
l := logger.Get()
l.Info("Запрос сброса пароля", zap.String("email", email))
@@ -235,7 +235,11 @@ func (s *serviceImpl) ForgotPassword(email string) (string, error) {
// Генерируем reset token (используем метод из auth сервиса)
// В реальном приложении здесь должна быть генерация токена
resetToken := generateResetToken()
resetToken, err := generateResetToken()
if err != nil {
l.Error("Ошибка генерации reset token", zap.Error(err))
return "", err
}
passwordReset := &models.PasswordReset{
AccountID: account.ID,
@@ -254,7 +258,7 @@ func (s *serviceImpl) ForgotPassword(email string) (string, error) {
}
// ResetPassword сбрасывает пароль по токену
func (s *serviceImpl) ResetPassword(token, newPassword string) error {
func (s *accountServiceImpl) ResetPassword(token, newPassword string) error {
l := logger.Get()
l.Info("Сброс пароля по токену")
@@ -307,7 +311,7 @@ func (s *serviceImpl) ResetPassword(token, newPassword string) error {
}
// ListAccounts возвращает список аккаунтов с пагинацией
func (s *serviceImpl) ListAccounts(req ListAccountsRequest) (*AccountListResponse, error) {
func (s *accountServiceImpl) ListAccounts(req ListAccountsRequest) (*AccountListResponse, error) {
l := logger.Get()
l.Debug("Получение списка аккаунтов", zap.Any("request", req))
@@ -320,7 +324,7 @@ func (s *serviceImpl) ListAccounts(req ListAccountsRequest) (*AccountListRespons
}
offset := (req.Page - 1) * req.PageSize
var accounts []models.Account
var total int64
var err error
@@ -341,14 +345,14 @@ func (s *serviceImpl) ListAccounts(req ListAccountsRequest) (*AccountListRespons
}
total, err = s.accountRepo.Count()
}
if err != nil {
return nil, err
}
// Фильтруем по роли и статусу (если нужно)
filteredAccounts := s.filterAccounts(accounts, req.Role, req.IsActive)
items := make([]AccountResponse, len(filteredAccounts))
for i, acc := range filteredAccounts {
items[i] = ToAccountResponse(&acc)
@@ -369,7 +373,7 @@ func (s *serviceImpl) ListAccounts(req ListAccountsRequest) (*AccountListRespons
}
// VerifyAccount верифицирует аккаунт
func (s *serviceImpl) VerifyAccount(accountID uint, req VerifyAccountRequest) error {
func (s *accountServiceImpl) VerifyAccount(accountID uint, req VerifyAccountRequest) error {
l := logger.Get()
l.Info("Верификация аккаунта", zap.Uint("id", accountID))
@@ -392,7 +396,7 @@ func (s *serviceImpl) VerifyAccount(accountID uint, req VerifyAccountRequest) er
}
// UpdateAccountStatus обновляет статус аккаунта (админ)
func (s *serviceImpl) UpdateAccountStatus(accountID uint, req UpdateAccountStatusRequest) error {
func (s *accountServiceImpl) UpdateAccountStatus(accountID uint, req UpdateAccountStatusRequest) error {
l := logger.Get()
l.Info("Обновление статуса аккаунта", zap.Uint("id", accountID))
@@ -419,13 +423,13 @@ func (s *serviceImpl) UpdateAccountStatus(accountID uint, req UpdateAccountStatu
}
// GetAccountStats получает статистику аккаунта
func (s *serviceImpl) GetAccountStats(userID uint) (*AccountStats, error) {
func (s *accountServiceImpl) GetAccountStats(userID uint) (*AccountStats, error) {
l := logger.Get()
l.Debug("Получение статистики аккаунта", zap.Uint("userID", userID))
// Здесь должна быть реальная логика подсчета статистики
// В реальном приложении нужно запрашивать данные из соответствующих репозиториев
stats := &AccountStats{
ObjectsCount: 0,
FeedbacksCount: 0,
@@ -433,14 +437,14 @@ func (s *serviceImpl) GetAccountStats(userID uint) (*AccountStats, error) {
RatingsCount: 0,
AppealsCount: 0,
}
// TODO: Получить реальную статистику из базы данных
return stats, nil
}
// GetAccountProfile получает профиль пользователя со статистикой
func (s *serviceImpl) GetAccountProfile(userID uint) (*AccountProfileResponse, error) {
func (s *accountServiceImpl) GetAccountProfile(userID uint) (*AccountProfileResponse, error) {
l := logger.Get()
l.Debug("Получение профиля пользователя", zap.Uint("userID", userID))
@@ -465,17 +469,17 @@ func (s *serviceImpl) GetAccountProfile(userID uint) (*AccountProfileResponse, e
}
// GetAccountModelByID получает модель аккаунта по ID (для внутреннего использования)
func (s *serviceImpl) GetAccountModelByID(id uint) (*models.Account, error) {
func (s *accountServiceImpl) GetAccountModelByID(id uint) (*models.Account, error) {
return s.accountRepo.GetByID(id)
}
// GetAccountModelByEmail получает модель аккаунта по email (для внутреннего использования)
func (s *serviceImpl) GetAccountModelByEmail(email string) (*models.Account, error) {
func (s *accountServiceImpl) GetAccountModelByEmail(email string) (*models.Account, error) {
return s.accountRepo.GetByEmail(email)
}
// CreateAccount создает новый аккаунт
func (s *serviceImpl) CreateAccount(req CreateAccountRequest) (*models.Account, error) {
func (s *accountServiceImpl) CreateAccount(req CreateAccountRequest) (*models.Account, error) {
l := logger.Get()
l.Info("Создание аккаунта", zap.String("email", req.Email))
@@ -526,21 +530,21 @@ func (s *serviceImpl) CreateAccount(req CreateAccountRequest) (*models.Account,
}
// UpdateAccountModel обновляет модель аккаунта
func (s *serviceImpl) UpdateAccountModel(account *models.Account) error {
func (s *accountServiceImpl) UpdateAccountModel(account *models.Account) error {
return s.accountRepo.Update(account)
}
// Вспомогательные методы
func (s *serviceImpl) getSearchTotal(query string) (int64, error) {
func (s *accountServiceImpl) getSearchTotal(query string) (int64, error) {
// Здесь должна быть реализация подсчета общего количества результатов поиска
// Для простоты возвращаем 0
return 0, nil
}
func (s *serviceImpl) filterAccounts(accounts []models.Account, role string, isActive *bool) []models.Account {
func (s *accountServiceImpl) filterAccounts(accounts []models.Account, role string, isActive *bool) []models.Account {
var filtered []models.Account
for _, acc := range accounts {
if role != "" && acc.Role != role {
continue
@@ -550,12 +554,17 @@ func (s *serviceImpl) filterAccounts(accounts []models.Account, role string, isA
}
filtered = append(filtered, acc)
}
return filtered
}
// Генерация reset токена
func generateResetToken() string {
// В реальном приложении используйте криптографически безопасную генерацию
return fmt.Sprintf("reset_%d_%d", time.Now().UnixNano(), time.Now().Unix())
}
func generateResetToken() (string, error) {
// Генерируем 32 байта (64 символа в hex) — достаточно для безопасности
bytes := make([]byte, 32)
_, err := rand.Read(bytes)
if err != nil {
return "", fmt.Errorf("failed to generate token: %w", err)
}
return hex.EncodeToString(bytes), nil
}