modified: main_dc/yalarba/api_yal/internal/database/psql_db.go

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
This commit is contained in:
2026-02-12 04:17:42 +05:00
parent f20d42e026
commit 6cc9354cce
4 changed files with 64 additions and 0 deletions
@@ -44,6 +44,9 @@ func autoMigrate(db *gorm.DB) error {
&models.Account{}, &models.Account{},
&models.UpdateHistory{}, &models.UpdateHistory{},
&models.Object{}, &models.Object{},
&models.RatingVote{},
&models.VoteBreakdown{},
&models.Rating{},
} }
for _, model := range models { for _, model := range models {
@@ -30,4 +30,6 @@ type Account struct {
// Связь: один Account имеет много Objects // Связь: один Account имеет много Objects
Objects []Object `gorm:"foreignKey:OwnerID" json:"objects"` Objects []Object `gorm:"foreignKey:OwnerID" json:"objects"`
} }
@@ -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
}
@@ -19,4 +19,6 @@ type Object struct {
Site string `json:"site"` Site string `json:"site"`
Description string `json:"description"` Description string `json:"description"`
Address string `json:"address"` Address string `json:"address"`
Rating Rating `gorm:"foreigenKey:ObjectID" json:"rating"`
} }