diff --git a/main_dc/yalarba/api_yal/internal/database/psql_db.go b/main_dc/yalarba/api_yal/internal/database/psql_db.go index 59288ef..9a18a9a 100644 --- a/main_dc/yalarba/api_yal/internal/database/psql_db.go +++ b/main_dc/yalarba/api_yal/internal/database/psql_db.go @@ -44,6 +44,9 @@ func autoMigrate(db *gorm.DB) error { &models.Account{}, &models.UpdateHistory{}, &models.Object{}, + &models.RatingVote{}, + &models.VoteBreakdown{}, + &models.Rating{}, } for _, model := range models { diff --git a/main_dc/yalarba/api_yal/internal/models/account.go b/main_dc/yalarba/api_yal/internal/models/account.go index 4e82adf..53599ff 100644 --- a/main_dc/yalarba/api_yal/internal/models/account.go +++ b/main_dc/yalarba/api_yal/internal/models/account.go @@ -30,4 +30,6 @@ type Account struct { // Связь: один Account имеет много Objects Objects []Object `gorm:"foreignKey:OwnerID" json:"objects"` + + } diff --git a/main_dc/yalarba/api_yal/internal/models/rating.go b/main_dc/yalarba/api_yal/internal/models/rating.go new file mode 100644 index 0000000..1dc7719 --- /dev/null +++ b/main_dc/yalarba/api_yal/internal/models/rating.go @@ -0,0 +1,57 @@ +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 +} diff --git a/main_dc/yalarba/api_yal/internal/models/оbject.go b/main_dc/yalarba/api_yal/internal/models/оbject.go index 6f8fb2f..27ddaa6 100644 --- a/main_dc/yalarba/api_yal/internal/models/оbject.go +++ b/main_dc/yalarba/api_yal/internal/models/оbject.go @@ -19,4 +19,6 @@ type Object struct { Site string `json:"site"` Description string `json:"description"` Address string `json:"address"` + + Rating Rating `gorm:"foreigenKey:ObjectID" json:"rating"` }