894415e3ac
modified: main_dc/yalarba/api_yal/internal/domain/feetback/dto.go modified: main_dc/yalarba/api_yal/internal/domain/feetback/service.go last
89 lines
4.4 KiB
Go
89 lines
4.4 KiB
Go
package feetback
|
|
|
|
import (
|
|
"api_yal/internal/domain/account"
|
|
"api_yal/internal/domain/comment"
|
|
"api_yal/internal/domain/object"
|
|
"api_yal/internal/models"
|
|
"time"
|
|
)
|
|
|
|
// CreateFeedbackRequest - DTO для создания отзыва
|
|
// Обязательные поля: ObjectID, Platform, Score, Text
|
|
// Score должен быть от 1 до 5
|
|
// Platform должен быть одним из допустимых значений (entrepreneur, tourist)
|
|
type CreateFeedbackRequest struct {
|
|
ObjectID uint `json:"object_id" binding:"required"`
|
|
Platform models.PlatformType `json:"platform" binding:"required,oneof=entrepreneur tourist"`
|
|
Score int `json:"score" binding:"required,min=1,max=5"`
|
|
Text string `json:"text" binding:"required"`
|
|
}
|
|
|
|
// UpdateFeedbackRequest - DTO для обновления отзыва
|
|
// Все поля опциональны, позволяют обновлять только указанные данные
|
|
type UpdateFeedbackRequest struct {
|
|
Score *int `json:"score" binding:"omitempty,min=1,max=5"`
|
|
Text *string `json:"text"`
|
|
}
|
|
|
|
// FeedbackResponse - DTO для полного ответа с отзывом
|
|
// Включает всю информацию о отзыве, включая связанные данные
|
|
// Owner и Object могут быть nil, если предзагрузка не была выполнена
|
|
type FeedbackResponse struct {
|
|
ID uint `json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
|
OwnerID uint `json:"owner_id"`
|
|
Owner *account.AccountResponse `json:"owner,omitempty"`
|
|
ObjectID uint `json:"object_id"`
|
|
Object *object.ObjectShortResponse `json:"object,omitempty"`
|
|
Platform models.PlatformType `json:"platform"`
|
|
Score int `json:"score"`
|
|
Text string `json:"text"`
|
|
CommentCount int `json:"comment_count"`
|
|
Comments []comment.CommentShortResponse `json:"comments,omitempty"`
|
|
}
|
|
|
|
// FeedbackShortResponse - DTO для краткого ответа (вложенный в объект)
|
|
// Используется при возврате отзывов в составе других объектов
|
|
// OwnerName берется из Account.OwnerName или формируется из имени пользователя
|
|
type FeedbackShortResponse struct {
|
|
ID uint `json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
OwnerID uint `json:"owner_id"`
|
|
OwnerName string `json:"owner_name,omitempty"`
|
|
Platform models.PlatformType `json:"platform"`
|
|
Score int `json:"score"`
|
|
Text string `json:"text"`
|
|
}
|
|
|
|
// FeedbackListResponse - DTO для списка отзывов с пагинацией
|
|
// Структура для возврата списка отзывов с метаданными пагинации
|
|
type FeedbackListResponse struct {
|
|
Items []FeedbackShortResponse `json:"items"`
|
|
Total int64 `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"page_size"`
|
|
TotalPages int `json:"total_pages"`
|
|
}
|
|
|
|
// SearchFeedbacksRequest - DTO для поиска отзывов
|
|
// Используется для параметров поиска
|
|
// Запрос должен быть не пустым
|
|
type SearchFeedbacksRequest struct {
|
|
Query string `json:"q" binding:"required"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"page_size"`
|
|
}
|
|
|
|
// FeedbackStatsResponse - DTO для статистики по отзывам
|
|
// Используется для агрегированной информации
|
|
// AverageScore может быть 0, если нет отзывов
|
|
type FeedbackStatsResponse struct {
|
|
TotalCount int `json:"total_count"`
|
|
AverageScore float64 `json:"average_score"`
|
|
PlatformStats map[models.PlatformType]int `json:"platform_stats"`
|
|
ScoreDistribution map[int]int `json:"score_distribution"` // распределение по баллам (1-5)
|
|
}
|