On branch main
modified: main_dc/yalarba/api_yal/go.sum modified: main_dc/yalarba/api_yal/internal/domain/account/dto.go modified: main_dc/yalarba/api_yal/internal/models/account.go modified: main_dc/yalarba/api_yal/internal/models/appeal.go modified: main_dc/yalarba/api_yal/internal/models/comment.go modified: main_dc/yalarba/api_yal/internal/models/feedback.go modified: main_dc/yalarba/api_yal/internal/models/password_reset.go modified: main_dc/yalarba/api_yal/internal/models/rating.go modified: "main_dc/yalarba/api_yal/internal/models/\320\276bject.go" set embedded base model anonimus as realy embedded struct without set name for field base
This commit is contained in:
@@ -1 +1,220 @@
|
||||
package account
|
||||
package account
|
||||
|
||||
import (
|
||||
"time"
|
||||
"api_yal/internal/models"
|
||||
)
|
||||
|
||||
// ==================== Request DTOs ====================
|
||||
|
||||
// CreateAccountRequest - DTO для создания нового аккаунта
|
||||
type CreateAccountRequest struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Password string `json:"password" binding:"required,min=6"`
|
||||
FullName string `json:"full_name" binding:"required"`
|
||||
FirstName string `json:"first_name" binding:"required"`
|
||||
LastName string `json:"last_name" binding:"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" binding:"required"`
|
||||
NewPassword string `json:"new_password" binding:"required,min=6"`
|
||||
}
|
||||
|
||||
// ForgotPasswordRequest - DTO для запроса сброса пароля
|
||||
type ForgotPasswordRequest struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
}
|
||||
|
||||
// ResetPasswordRequest - DTO для сброса пароля по токену
|
||||
type ResetPasswordRequest struct {
|
||||
Token string `json:"token" binding:"required"`
|
||||
NewPassword string `json:"new_password" binding:"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" binding:"omitempty,oneof=user admin moderator"`
|
||||
}
|
||||
|
||||
// ListAccountsRequest - DTO для фильтрации списка аккаунтов
|
||||
type ListAccountsRequest struct {
|
||||
Page int `form:"page" binding:"min=1"`
|
||||
PageSize int `form:"page_size" binding:"min=1,max=100"`
|
||||
Search string `form:"search"`
|
||||
Role string `form:"role" binding:"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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user