feat(encounter): 优化遇猫创建逻辑
- 添加 poi 和 extra 信息的处理 - 新增标签处理逻辑 - 优化动物模型默认值设置 - 调整动物模型字段,增加默认值
This commit is contained in:
parent
75f2b9e59b
commit
8186f41347
@ -13,7 +13,6 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
)
|
||||
|
||||
type Encounters struct {
|
||||
@ -37,14 +36,35 @@ func (e *Encounters) Create(context *gin.Context) {
|
||||
context.Set(consts.ValidatorPrefix+"avatar_height", float64(avatarHeight))
|
||||
context.Set(consts.ValidatorPrefix+"avatar_width", float64(avatarWidth))
|
||||
}
|
||||
// 将 Array 转化为 string 类型
|
||||
poi := context.GetStringMap(consts.ValidatorPrefix + "poi")
|
||||
if poi != nil {
|
||||
// 感觉这里就是获取信息之后,然后解析后再存储,方便后续 Model 直接绑定到数据。
|
||||
latitude := poi["latitude"].(float64)
|
||||
longitude := poi["longitude"].(float64)
|
||||
context.Set(consts.ValidatorPrefix+"latitude", latitude)
|
||||
context.Set(consts.ValidatorPrefix+"longitude", longitude)
|
||||
}
|
||||
extra := context.GetStringMap(consts.ValidatorPrefix + "extra")
|
||||
var tags []string
|
||||
if extra != nil {
|
||||
context.Set(consts.ValidatorPrefix+"topics", extra["topics"])
|
||||
tags = data_transfer.GetStringSlice(context, "topics")
|
||||
context.Set(consts.ValidatorPrefix+"tags", tags) // INFO 这里字段没有直接匹配上。
|
||||
}
|
||||
// STAGE - 2
|
||||
if res, err := data_transfer.ConvertSliceToString(photos); err == nil {
|
||||
context.Set(consts.ValidatorPrefix+"photos", res)
|
||||
} else {
|
||||
response.Fail(context, consts.ValidatorParamsCheckFailCode, consts.ValidatorParamsCheckFailMsg, "")
|
||||
return
|
||||
}
|
||||
// Real Insert - 1: ENC
|
||||
if res, err := data_transfer.ConvertSliceToString(tags); err == nil {
|
||||
context.Set(consts.ValidatorPrefix+"tags", res)
|
||||
} else {
|
||||
response.Fail(context, consts.ValidatorParamsCheckFailCode, consts.ValidatorParamsCheckFailMsg, "")
|
||||
return
|
||||
}
|
||||
// STAGE -3: Real Insert - 1: ENC
|
||||
animals_id := data_transfer.GetFloat64Slice(context, "animals_id") // 由于是 Slice 就交给 EAlink 内部遍历时处理。
|
||||
// Real Insert - 2: EA LINK
|
||||
if encounter_id, ok := model.CreateEncounterFactory("").InsertDate(context); ok && encounter_id > 0 {
|
||||
@ -53,7 +73,9 @@ func (e *Encounters) Create(context *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(context, consts.CurdStatusOkMsg, "")
|
||||
response.Success(context, consts.CurdStatusOkMsg, gin.H{
|
||||
"encounter_id": encounter_id,
|
||||
})
|
||||
} else {
|
||||
response.Fail(context, consts.CurdCreatFailCode, consts.CurdCreatFailMsg+", 新增错误", "")
|
||||
}
|
||||
|
@ -3,12 +3,17 @@ package encounter
|
||||
import (
|
||||
"catface/app/global/consts"
|
||||
"catface/app/http/controller/web"
|
||||
"catface/app/http/validator/common/location"
|
||||
"catface/app/http/validator/core/data_transfer"
|
||||
"catface/app/utils/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Extra struct {
|
||||
Topics []string `form:"topics" json:"topics"`
|
||||
}
|
||||
|
||||
type Create struct {
|
||||
UserId int `form:"user_id" json:"user_id" binding:"required,numeric"`
|
||||
AnimalsId []int `form:"animals_id" json:"animals_id" binding:"required"`
|
||||
@ -16,9 +21,10 @@ type Create struct {
|
||||
Content string `form:"content" json:"content"`
|
||||
|
||||
// Avatar string `form:"avatar" json:"avatar"`
|
||||
Photos []string `form:"photos" json:"photos"` // INFO 如果 Photo 为空,那就选取 Animals 的 Avatar
|
||||
Laitude float64 `form:"latitude" json:"latitude"`
|
||||
Longitude float64 `form:"longitude" json:"longitude"`
|
||||
Photos []string `form:"photos" json:"photos"` // INFO 如果 Photo 为空,那就选取 Animals 的 Avatar
|
||||
|
||||
Poi location.Poi `form:"poi" json:"poi"`
|
||||
Extra Extra `form:"extra" json:"extra"`
|
||||
}
|
||||
|
||||
func (c Create) CheckParams(context *gin.Context) {
|
||||
|
@ -18,13 +18,13 @@ type Animal struct {
|
||||
BaseModel // 假设 BaseModel 中不需要添加 omitempty 标签
|
||||
Name string `gorm:"type:varchar(20)" json:"name,omitempty"` // 名称
|
||||
Birthday string `gorm:"size:10" json:"birthday,omitempty"` // 生日;就简单存string就好
|
||||
Gender uint8 `json:"gender,omitempty"` // 性别
|
||||
Breed uint8 `json:"breed,omitempty"` // 品种
|
||||
Sterilization uint8 `json:"sterilization,omitempty"` // 1 不明 2 未绝育 3 已绝育
|
||||
Vaccination uint8 `json:"vaccination,omitempty"` // 免疫状态
|
||||
Deworming uint8 `json:"deworming,omitempty"` // 驱虫状态
|
||||
Gender uint8 `gorm:"default:1" json:"gender,omitempty"` // 性别
|
||||
Breed uint8 `gorm:"default:1" json:"breed,omitempty"` // 品种
|
||||
Sterilization uint8 `gorm:"default:1" json:"sterilization,omitempty"` // 1 不明 2 未绝育 3 已绝育
|
||||
Vaccination uint8 `gorm:"default:1" json:"vaccination,omitempty"` // 免疫状态
|
||||
Deworming uint8 `gorm:"default:1" json:"deworming,omitempty"` // 驱虫状态
|
||||
NickNames string `gorm:"type:varchar(31)" json:"nick_names,omitempty"` // 别称,辅助查询;存储上采取 , 间隔符的方式; VARCHAR 会比较合适
|
||||
Status uint8 `json:"status,omitempty"` // 状态
|
||||
Status uint8 `gorm:"default:1" json:"status,omitempty"` // 状态
|
||||
Description string `gorm:"column:description;type:varchar(255)" json:"description,omitempty"` // 简明介绍
|
||||
Tags string `json:"tags,omitempty"`
|
||||
// TAG imaegs
|
||||
@ -34,7 +34,7 @@ type Animal struct {
|
||||
HeadImg string `gorm:"type:varchar(50)" json:"head_img,omitempty"` // Head 默认处理为正方形。
|
||||
Photos string `gorm:"type:varchar(255)" json:"photos,omitempty"` // 图片数组
|
||||
// TAG POI
|
||||
Department uint8 `gorm:"column:department" json:"department,omitempty"`
|
||||
Department uint8 `gorm:"column:department;default:1" json:"department,omitempty"`
|
||||
Latitude float64 `json:"latitude,omitempty"` // POI 位置相关
|
||||
Longitude float64 `json:"longitude,omitempty"` // POI 位置相关
|
||||
ActivityRadius uint64 `json:"activity_radius,omitempty"` // 活动半径
|
||||
|
Loading…
x
Reference in New Issue
Block a user