Files
tp/main_dc/yalarba/api_yal/internal/domain/account/dto.go
T
valitovgaziz 75b2f3f6b2 On branch main
modified:   main_dc/yalarba/api_yal/internal/domain/account/dto.go
	new file:   main_dc/yalarba/api_yal/internal/domain/account/errors.go
	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
	new file:   main_dc/yalarba/api_yal/internal/domain/account/types.go
	new file:   main_dc/yalarba/api_yal/internal/middleware/admin.go
	modified:   main_dc/yalarba/api_yal/internal/middleware/auth.go
	new file:   main_dc/yalarba/api_yal/internal/middleware/context.go
	new file:   main_dc/yalarba/api_yal/internal/middleware/logging.go
	modified:   main_dc/yalarba/api_yal/internal/router/router.go
last but not yet commit
2026-03-31 09:43:18 +05:00

220 lines
7.7 KiB
Go

package account
import (
"time"
"api_yal/internal/models"
)
// ==================== Request DTOs ====================
// CreateAccountRequest - DTO для создания нового аккаунта
type CreateAccountRequest struct {
Email string `json:"email" validate:"required,email"`
Password string `json:"password" validate:"required,min=6"`
FullName string `json:"full_name" validate:"required"`
FirstName string `json:"first_name" validate:"required"`
LastName string `json:"last_name" validate:"required"`
Phone string `json:"phone"`
City string `json:"city"`
// Бизнес информация
OrganizationForm string `json:"organization_form"`
OrganizationName string `json:"organization_name"`
OrganizationShort string `json:"organization_short"`
INN string `json:"inn"`
PersonalINN string `json:"personal_inn"`
}
// UpdateAccountRequest - DTO для обновления аккаунта
type UpdateAccountRequest struct {
FullName string `json:"full_name"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Phone string `json:"phone"`
City string `json:"city"`
// Бизнес информация
OrganizationForm string `json:"organization_form"`
OrganizationName string `json:"organization_name"`
OrganizationShort string `json:"organization_short"`
INN string `json:"inn"`
PersonalINN string `json:"personal_inn"`
}
// ChangePasswordRequest - DTO для смены пароля
type ChangePasswordRequest struct {
CurrentPassword string `json:"current_password" validate:"required"`
NewPassword string `json:"new_password" validate:"required,min=6"`
}
// ForgotPasswordRequest - DTO для запроса сброса пароля
type ForgotPasswordRequest struct {
Email string `json:"email" validate:"required,email"`
}
// ResetPasswordRequest - DTO для сброса пароля по токену
type ResetPasswordRequest struct {
Token string `json:"token" validate:"required"`
NewPassword string `json:"new_password" validate:"required,min=6"`
}
// VerifyAccountRequest - DTO для верификации аккаунта (админ)
type VerifyAccountRequest struct {
IsVerified bool `json:"is_verified"`
}
// UpdateAccountStatusRequest - DTO для изменения статуса аккаунта (админ)
type UpdateAccountStatusRequest struct {
IsActive bool `json:"is_active"`
Role string `json:"role" validate:"omitempty,oneof=user admin moderator"`
}
// ListAccountsRequest - DTO для фильтрации списка аккаунтов
type ListAccountsRequest struct {
Page int `form:"page" validate:"min=1"`
PageSize int `form:"page_size" validate:"min=1,max=100"`
Search string `form:"search"`
Role string `form:"role" validate:"omitempty,oneof=user admin moderator"`
IsActive *bool `form:"is_active"`
}
// ==================== Response DTOs ====================
// AccountResponse - базовый DTO для ответа с данными аккаунта (без чувствительной информации)
type AccountResponse struct {
ID uint `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Основная информация
Email string `json:"email"`
FullName string `json:"full_name"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Phone string `json:"phone"`
City string `json:"city"`
// Бизнес информация
OrganizationForm string `json:"organization_form,omitempty"`
OrganizationName string `json:"organization_name,omitempty"`
OrganizationShort string `json:"organization_short,omitempty"`
INN string `json:"inn,omitempty"`
PersonalINN string `json:"personal_inn,omitempty"`
// Статус
IsActive bool `json:"is_active"`
IsVerified bool `json:"is_verified"`
Role string `json:"role"`
}
// AccountWithObjectsResponse - DTO с объектами аккаунта
type AccountWithObjectsResponse struct {
AccountResponse
Objects []ObjectBriefResponse `json:"objects,omitempty"`
}
// ObjectBriefResponse - краткая информация об объекте для вложенных ответов
type ObjectBriefResponse struct {
ID uint `json:"id"`
ShortName string `json:"short_name"`
LongName string `json:"long_name"`
Type string `json:"type"`
IsActive bool `json:"is_active"`
Address string `json:"address"`
}
// AccountListResponse - DTO для списка аккаунтов с пагинацией
type AccountListResponse struct {
Items []AccountResponse `json:"items"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
TotalPages int `json:"total_pages"`
}
// AccountProfileResponse - DTO для личного кабинета (более детальная информация)
type AccountProfileResponse struct {
AccountResponse
Stats AccountStats `json:"stats"`
}
// AccountStats - статистика аккаунта
type AccountStats struct {
ObjectsCount int `json:"objects_count"`
FeedbacksCount int `json:"feedbacks_count"`
CommentsCount int `json:"comments_count"`
RatingsCount int `json:"ratings_count"`
AppealsCount int `json:"appeals_count"`
}
// AuthResponse - DTO для ответа при авторизации
type AuthResponse struct {
Token string `json:"token"`
TokenType string `json:"token_type"`
ExpiresAt int64 `json:"expires_at"`
Account AccountResponse `json:"account"`
}
// PasswordResetResponse - DTO для ответа о сбросе пароля
type PasswordResetResponse struct {
Message string `json:"message"`
Token string `json:"token,omitempty"` // только при создании, не для продакшена
}
// ==================== Helper functions ====================
// ToAccountResponse преобразует модель Account в AccountResponse
func ToAccountResponse(account *models.Account) AccountResponse {
return AccountResponse{
ID: account.ID,
CreatedAt: account.CreatedAt,
UpdatedAt: account.UpdatedAt,
Email: account.Email,
FullName: account.FullName,
FirstName: account.FirstName,
LastName: account.LastName,
Phone: account.Phone,
City: account.City,
OrganizationForm: account.OrganizationForm,
OrganizationName: account.OrganizationName,
OrganizationShort: account.OrganizationShort,
INN: account.INN,
PersonalINN: account.PersonalINN,
IsActive: account.IsActive,
IsVerified: account.IsVerified,
Role: account.Role,
}
}
// ToAccountWithObjectsResponse преобразует модель Account в AccountWithObjectsResponse
func ToAccountWithObjectsResponse(account *models.Account) AccountWithObjectsResponse {
resp := AccountWithObjectsResponse{
AccountResponse: ToAccountResponse(account),
Objects: make([]ObjectBriefResponse, 0, len(account.Objects)),
}
for _, obj := range account.Objects {
resp.Objects = append(resp.Objects, ObjectBriefResponse{
ID: obj.ID,
ShortName: obj.ShortName,
LongName: obj.LongName,
Type: obj.Type,
IsActive: obj.IsActive,
Address: obj.Address,
})
}
return resp
}
// ToObjectBriefResponse преобразует модель Object в ObjectBriefResponse
func ToObjectBriefResponse(object *models.Object) ObjectBriefResponse {
return ObjectBriefResponse{
ID: object.ID,
ShortName: object.ShortName,
LongName: object.LongName,
Type: object.Type,
IsActive: object.IsActive,
Address: object.Address,
}
}