package model import ( "time" "gorm.io/gorm" ) type TradeType string const ( TradeTypeSell TradeType = "sell" TradeTypeBuy TradeType = "buy" ) type TradeCategory string const ( TradeCategoryDigital TradeCategory = "digital" TradeCategoryBook TradeCategory = "book" TradeCategoryClothing TradeCategory = "clothing" TradeCategoryDaily TradeCategory = "daily" TradeCategoryCosmetics TradeCategory = "cosmetics" TradeCategorySport TradeCategory = "sport" TradeCategoryTicket TradeCategory = "ticket" TradeCategoryOther TradeCategory = "other" ) type TradeItemStatus string const ( TradeItemActive TradeItemStatus = "active" TradeItemSold TradeItemStatus = "sold" TradeItemBought TradeItemStatus = "bought" TradeItemOffline TradeItemStatus = "offline" ) type TradeItem struct { ID string `json:"id" gorm:"type:varchar(36);primaryKey"` UserID string `json:"user_id" gorm:"type:varchar(36);index;not null"` TradeType TradeType `json:"trade_type" gorm:"type:varchar(10);not null;index"` Category TradeCategory `json:"category" gorm:"type:varchar(20);not null;index"` Title string `json:"title" gorm:"type:varchar(100);not null"` Content string `json:"content" gorm:"type:text"` Segments MessageSegments `json:"segments,omitempty" gorm:"type:text"` User *User `json:"user,omitempty" gorm:"foreignKey:UserID"` Images []TradeImage `json:"images" gorm:"foreignKey:TradeItemID"` Price *float64 `json:"price,omitempty" gorm:"type:decimal(10,2)"` Condition string `json:"condition,omitempty" gorm:"type:varchar(20)"` Status TradeItemStatus `json:"status" gorm:"type:varchar(10);not null;default:'active';index"` ViewsCount int `json:"views_count" gorm:"default:0"` FavoritesCount int `json:"favorites_count" gorm:"default:0"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index"` UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime:false"` } func (t *TradeItem) BeforeCreate(tx *gorm.DB) error { SetUUIDIfEmpty(&t.ID) return nil } func (TradeItem) TableName() string { return "trade_items" } type TradeImage struct { ID string `json:"id" gorm:"type:varchar(36);primaryKey"` TradeItemID string `json:"trade_item_id" gorm:"type:varchar(36);not null;index"` URL string `json:"url" gorm:"type:text;not null"` ThumbnailURL string `json:"thumbnail_url" gorm:"type:text"` PreviewURL string `json:"preview_url" gorm:"type:text"` PreviewURLLarge string `json:"preview_url_large" gorm:"type:text"` Width int `json:"width" gorm:"default:0"` Height int `json:"height" gorm:"default:0"` SortOrder int `json:"sort_order" gorm:"default:0"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` } func (ti *TradeImage) BeforeCreate(tx *gorm.DB) error { SetUUIDIfEmpty(&ti.ID) return nil } func (TradeImage) TableName() string { return "trade_images" } type TradeFavorite struct { ID string `json:"id" gorm:"type:varchar(36);primaryKey"` TradeItemID string `json:"trade_item_id" gorm:"type:varchar(36);not null;index;uniqueIndex:idx_trade_fav_item_user,priority:1"` UserID string `json:"user_id" gorm:"type:varchar(36);not null;index;uniqueIndex:idx_trade_fav_item_user,priority:2"` CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"` } func (f *TradeFavorite) BeforeCreate(tx *gorm.DB) error { SetUUIDIfEmpty(&f.ID) return nil } func (TradeFavorite) TableName() string { return "trade_favorites" }