From 4649b697f1877d3ac1360f1cb52630d9f3ec843d Mon Sep 17 00:00:00 2001 From: Havoc412 <2993167370@qq.com> Date: Wed, 23 Oct 2024 01:33:34 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8change=20Photos=20string=20->=20[]s?= =?UTF-8?q?tring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/encounter.go | 9 +++++---- app/model/encounter_result.go | 2 +- app/service/encounter/curd/encounter_curd.go | 8 ++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/model/encounter.go b/app/model/encounter.go index 9299374..891fc5a 100644 --- a/app/model/encounter.go +++ b/app/model/encounter.go @@ -26,10 +26,11 @@ type Encounter struct { // Encounter 或者称为 post,指的就是 Human 单 // Time 从 CreatedAt 中解析 // TAG Avatar 最好是压缩后的备份图像 - Avatar string `gorm:"type:varchar(50)" json:"avatar,omitempty"` // 缩略图 url,为 Go 获取 Photo 之后压缩处理后的图像,单独存储。 - AvatarHeight uint16 `json:"avatar_height,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。 - AvatarWidth uint16 `json:"avatar_width,omitempty"` - Photos string `gorm:"type:varchar(100)" json:"photos,omitempty"` // 图片数组 + Avatar string `gorm:"type:varchar(50)" json:"avatar,omitempty"` // 缩略图 url,为 Go 获取 Photo 之后压缩处理后的图像,单独存储。 + AvatarHeight uint16 `json:"avatar_height,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。 + AvatarWidth uint16 `json:"avatar_width,omitempty"` + Photos string `gorm:"type:varchar(100)" json:"photos,omitempty"` // 图片数组 + PhotosSlice []string `gorm:"-" json:"photos_list,omitempty"` // TIP GORM 忽略 // POI Latitude float64 `json:"latitude,omitempty"` // POI 位置相关 Longitude float64 `json:"longitude,omitempty"` diff --git a/app/model/encounter_result.go b/app/model/encounter_result.go index 2e87665..7fde547 100644 --- a/app/model/encounter_result.go +++ b/app/model/encounter_result.go @@ -18,7 +18,7 @@ type EncounterList struct { } type EncounterDetail struct { - Encounter Encounter + Encounter Encounter `json:"encounter"` UsersModel UsersModel `json:"user"` Animals []Animal `json:"animals"` } diff --git a/app/service/encounter/curd/encounter_curd.go b/app/service/encounter/curd/encounter_curd.go index 9acb056..ad5b468 100644 --- a/app/service/encounter/curd/encounter_curd.go +++ b/app/service/encounter/curd/encounter_curd.go @@ -34,8 +34,12 @@ func (e *EncounterCurd) Detail(id string) *model.EncounterDetail { return nil } + // 1.1 处理 Photos 为 []string,同时忽略原本的 Photos 字段。 + encounter.PhotosSlice = query_handler.StringToStringArray(encounter.Photos) + encounter.Photos = "" + // 2. user data - user, err := model.CreateUserFactory("").ShowByID(encounter.UsersModelId, "user_avatar", "user_name") + user, err := model.CreateUserFactory("").ShowByID(encounter.UsersModelId, "user_avatar", "user_name", "id") if err != nil { return nil } @@ -43,7 +47,7 @@ func (e *EncounterCurd) Detail(id string) *model.EncounterDetail { // 3. animals data animals_id := query_handler.StringToint64Array(encounter.AnimalsId) - animals := model.CreateAnimalFactory("").ShowByIDs(animals_id, "avatar", "name") + animals := model.CreateAnimalFactory("").ShowByIDs(animals_id, "avatar", "name", "id") _ = animals // 4. 合并