6cc9354cce
modified: main_dc/yalarba/api_yal/internal/models/account.go new file: main_dc/yalarba/api_yal/internal/models/rating.go modified: "main_dc/yalarba/api_yal/internal/models/\320\276bject.go" add rating objects, mogration for them
58 lines
2.0 KiB
Go
58 lines
2.0 KiB
Go
package models
|
|
|
|
import ()
|
|
|
|
// Типы платформ
|
|
type PlatformType string
|
|
|
|
const (
|
|
PlatformEntrepreneur PlatformType = "entrepreneur" // Платформа для предпринимателей
|
|
PlatformTourist PlatformType = "tourist" // Платформа для туристов
|
|
)
|
|
|
|
type Rating struct {
|
|
|
|
/*ID, CreatedAt, UpdatedAt, DeletedAt (Update's history)*/
|
|
Base Base `gorm:"embedded"`
|
|
|
|
// owner account ID
|
|
OwnerID uint `json:"owner_id"`
|
|
Owner Account `gorm:"foreignKey:OwnerID;references:ID" json:"owner"`
|
|
|
|
// object ID
|
|
ObjectID uint `json:"object_id"`
|
|
Object Object `gorm:"foreignKey:ObjectID;references:ID" json:"object"`
|
|
|
|
Platform PlatformType `json:"platform"` // К какой платформе относится
|
|
AverageScore float64 `json:"average_score"` // Средняя оценка
|
|
TotalVotes int `json:"total_votes"` // Общее количество голосов
|
|
VoteBreakdown VoteBreakdown `json:"vote_breakdown"` // Детализация оценок
|
|
|
|
}
|
|
|
|
// VoteBreakdown - детализация по баллам
|
|
type VoteBreakdown struct {
|
|
Base Base `gorm:"embedded"`
|
|
|
|
RatingID uint `json:"rating_id"`
|
|
Rating Rating `gorm:"foreignKey:RatingID;references:ID" json:"rating"`
|
|
|
|
Score1 int `json:"score_1"` // Количество оценок 1
|
|
Score2 int `json:"score_2"` // Количество оценок 2
|
|
Score3 int `json:"score_3"` // Количество оценок 3
|
|
Score4 int `json:"score_4"` // Количество оценок 4
|
|
Score5 int `json:"score_5"` // Количество оценок 5
|
|
}
|
|
|
|
// RatingVote - отдельный голос в рейтинге
|
|
type RatingVote struct {
|
|
|
|
/*ID, CreatedAt, UpdatedAt, DeletedAt (Update's history)*/
|
|
Base Base `gorm:"embedded"`
|
|
|
|
Platform PlatformType `json:"platform"`
|
|
TargetID uint `json:"target_id"`
|
|
VoterID uint `json:"voter_id"` // ID голосующего (предприниматель/турист)
|
|
Score int `json:"score"` // Оценка от 1 до 5
|
|
}
|