test Animal Create Object
This commit is contained in:
parent
8be36697a7
commit
5bd3e4d6e7
@ -56,3 +56,8 @@ func (a *Animals) Detail(context *gin.Context) {
|
||||
response.Fail(context, errcode.AnimalNoFind, errcode.ErrMsg[errcode.AnimalNoFind], "")
|
||||
}
|
||||
}
|
||||
func (a *Animals) Create(context *gin.Context) {
|
||||
poi := context.GetStringMap(consts.ValidatorPrefix + "poi")
|
||||
// TODO 感觉这里就是获取信息之后,然后解析后再存储,方便后续 Model 直接绑定到数据。
|
||||
_ = poi
|
||||
}
|
||||
|
6
app/http/validator/common/location/poi.go
Normal file
6
app/http/validator/common/location/poi.go
Normal file
@ -0,0 +1,6 @@
|
||||
package location
|
||||
|
||||
type Poi struct {
|
||||
Laitude float64 `form:"latitude" json:"latitude"`
|
||||
Longitude float64 `form:"longitude" json:"longitude"`
|
||||
}
|
@ -54,6 +54,8 @@ func WebRegisterValidator() {
|
||||
containers.Set(key, animal.List{})
|
||||
key = consts.ValidatorPrefix + "AnimalDetail"
|
||||
containers.Set(key, animal.Detail{})
|
||||
key = consts.ValidatorPrefix + "AnimalCreate"
|
||||
containers.Set(key, animal.Create{})
|
||||
|
||||
key = consts.ValidatorPrefix + "AnimalLikeCreate"
|
||||
containers.Set(key, animal_like.Create{})
|
||||
|
31
app/http/validator/web/animal/create.go
Normal file
31
app/http/validator/web/animal/create.go
Normal file
@ -0,0 +1,31 @@
|
||||
package animal
|
||||
|
||||
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 Create struct {
|
||||
Name string `form:"name" json:"name" binding:"required"`
|
||||
Poi location.Poi `form:"poi" json:"poi"`
|
||||
}
|
||||
|
||||
func (c Create) CheckParams(context *gin.Context) {
|
||||
if err := context.ShouldBind(&c); err != nil {
|
||||
response.ValidatorError(context, err)
|
||||
return
|
||||
}
|
||||
|
||||
extraAddBindDataContext := data_transfer.DataAddContext(c, consts.ValidatorPrefix, context)
|
||||
if extraAddBindDataContext == nil {
|
||||
response.ErrorSystem(context, "Animal Create 表单验证器json化失败", "")
|
||||
} else {
|
||||
// 验证完成,调用控制器,并将验证器成员(字段)递给控制器,保持上下文数据一致性
|
||||
(&web.Animals{}).Create(extraAddBindDataContext)
|
||||
}
|
||||
}
|
@ -121,6 +121,7 @@ func InitWebRouter() *gin.Engine {
|
||||
{
|
||||
animal.GET("", validatorFactory.Create(consts.ValidatorPrefix+"AnimalList"))
|
||||
animal.GET(":anm_id", validatorFactory.Create(consts.ValidatorPrefix+"AnimalDetail"))
|
||||
animal.POST("", validatorFactory.Create(consts.ValidatorPrefix+"AnimalCreate"))
|
||||
|
||||
animal.POST("like", validatorFactory.Create(consts.ValidatorPrefix+"AnimalLikeCreate"))
|
||||
animal.DELETE("like", validatorFactory.Create(consts.ValidatorPrefix+"AnimalLikeDelete"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user