change Create to store
This commit is contained in:
parent
818894ca92
commit
32cbe38436
@ -7,7 +7,6 @@ import (
|
||||
"catface/app/utils/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
)
|
||||
|
||||
type Animals struct { // INFO 起到一个标记的作用,这样 web.xxx 的时候不同模块就不会命名冲突了。
|
||||
@ -23,7 +22,7 @@ func (a *Animals) List(context *gin.Context) {
|
||||
num := context.GetFloat64(consts.ValidatorPrefix + "num")
|
||||
skip := context.GetFloat64(consts.ValidatorPrefix + "skip")
|
||||
|
||||
animals := curd.CreateUserCurdFactory().List(attrs, gender, breed, sterilzation, status, int(num), int(skip))
|
||||
animals := curd.CreateAnimalsCurdFactory().List(attrs, gender, breed, sterilzation, status, int(num), int(skip))
|
||||
if animals != nil {
|
||||
response.Success(context, consts.CurdStatusOkMsg, animals)
|
||||
} else {
|
||||
|
29
app/http/controller/web/encounter_controller.go
Normal file
29
app/http/controller/web/encounter_controller.go
Normal file
@ -0,0 +1,29 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"catface/app/global/consts"
|
||||
"catface/app/service/encounter/curd"
|
||||
"catface/app/utils/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Encounters struct {
|
||||
}
|
||||
|
||||
func (e *Encounters) Store(context *gin.Context) {
|
||||
userId := context.GetFloat64(consts.ValidatorPrefix + "user_id")
|
||||
animalsID := context.GetString(consts.ValidatorPrefix + "animals_id")
|
||||
title := context.GetString(consts.ValidatorPrefix + "title")
|
||||
context := context.GetString(consts.ValidatorPrefix + "content")
|
||||
photos := context.GetString(consts.ValidatorPrefix + "photos")
|
||||
laitude := context.GetFloat64(consts.ValidatorPrefix + "latitude")
|
||||
longitude := context.GetFloat64(consts.ValidatorPrefix + "longitude")
|
||||
|
||||
encounters := curd.CreateEncounterCurdFactory().Create()
|
||||
if encounters == nil {
|
||||
response.Success(context, consts.CurdStatusOkMsg, encounters)
|
||||
} else {
|
||||
response.Fail(context, consts.CurdCreatFailCode, consts.CurdCreatFailMsg, "")
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import (
|
||||
"catface/app/http/validator/common/upload_files"
|
||||
"catface/app/http/validator/common/websocket"
|
||||
"catface/app/http/validator/web/animal"
|
||||
"catface/app/http/validator/web/encounter"
|
||||
"catface/app/http/validator/web/users"
|
||||
)
|
||||
|
||||
@ -51,4 +52,9 @@ func WebRegisterValidator() {
|
||||
containers.Set(key, animal.List{})
|
||||
key = consts.ValidatorPrefix + "AnimalDetail"
|
||||
containers.Set(key, animal.Detail{})
|
||||
|
||||
// TAG Encounter
|
||||
key = consts.ValidatorPrefix + "EncounterStore"
|
||||
containers.Set(key, encounter.Store{})
|
||||
|
||||
}
|
||||
|
37
app/http/validator/web/encounter/store.go
Normal file
37
app/http/validator/web/encounter/store.go
Normal file
@ -0,0 +1,37 @@
|
||||
package encounter
|
||||
|
||||
import (
|
||||
"catface/app/global/consts"
|
||||
"catface/app/http/controller/web"
|
||||
"catface/app/http/validator/core/data_transfer"
|
||||
"catface/app/utils/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
UserId int `form:"user_id" json:"user_id" binding:"required,numeric"`
|
||||
AnimalsId string `form:"animals_id" json:"animals_id" binding:"required"`
|
||||
Title string `form:"title" json:"title" binding:"required"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func (e Store) CheckParams(context *gin.Context) {
|
||||
if err := context.ShouldBind(&e); err != nil {
|
||||
response.ValidatorError(context, err)
|
||||
return
|
||||
}
|
||||
|
||||
extraAddBindDataContext := data_transfer.DataAddContext(e, consts.ValidatorPrefix, context)
|
||||
if extraAddBindDataContext == nil {
|
||||
response.ErrorSystem(context, "EncounterStore表单验证器json化失败", "")
|
||||
} else {
|
||||
// 验证完成,调用控制器,并将验证器成员(字段)递给控制器,保持上下文数据一致性
|
||||
(&web.Encounters{}).Store(extraAddBindDataContext)
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package model
|
||||
|
||||
func CreateEncounterFactory(sqlType string) *Encounter {
|
||||
return &Encounter{BaseModel: BaseModel{DB: UseDbConn(sqlType)}}
|
||||
}
|
||||
|
||||
type Encounter struct { // Encounter 或者称为 post,指的就是 Human 单次的记录。
|
||||
BaseModel
|
||||
// TAG 外键关联
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func CreateUserCurdFactory() *AnimalsCurd {
|
||||
func CreateAnimalsCurdFactory() *AnimalsCurd {
|
||||
return &AnimalsCurd{model.CreateAnimalFactory("")}
|
||||
}
|
||||
|
||||
|
16
app/service/encounter/curd/encounter_curd.go
Normal file
16
app/service/encounter/curd/encounter_curd.go
Normal file
@ -0,0 +1,16 @@
|
||||
package curd
|
||||
|
||||
import "catface/app/model"
|
||||
|
||||
func CreateEncounterCurdFactory() *EncounterCurd {
|
||||
return &EncounterCurd{model.CreateEncounterFactory("")}
|
||||
}
|
||||
|
||||
type EncounterCurd struct {
|
||||
encounter *model.Encounter
|
||||
}
|
||||
|
||||
func (e *EncounterCurd) Store(encounter *model.Encounter) bool {
|
||||
|
||||
return model.CreateEncounterFactory()
|
||||
}
|
@ -19,7 +19,6 @@ func (u *UsersCurd) Register(userName, pass, userIp string) bool {
|
||||
}
|
||||
|
||||
func (u *UsersCurd) Store(name string, pass string, realName string, phone string, remark string) bool {
|
||||
|
||||
pass = md5_encrypt.Base64Md5(pass) // 预先处理密码加密,然后存储在数据库
|
||||
return u.userModel.Store(name, pass, realName, phone, remark)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
// "catface/app/http/controller/captcha" // 验证码组件
|
||||
// "catface/app/http/middleware/authorization"
|
||||
|
||||
"catface/app/http/middleware/cors"
|
||||
validatorFactory "catface/app/http/validator/core/factory"
|
||||
|
||||
@ -123,6 +124,16 @@ func InitWebRouter() *gin.Engine {
|
||||
animal.GET("", validatorFactory.Create(consts.ValidatorPrefix+"AnimalList"))
|
||||
animal.GET(":anm_id", validatorFactory.Create(consts.ValidatorPrefix+"AnimalDetail"))
|
||||
}
|
||||
|
||||
// backend.Use(authorization.CheckTokenAuth()) // INFO token 检查
|
||||
// {
|
||||
encounter := backend.Group("encounter")
|
||||
{
|
||||
// GET 获取列表; POST 上传
|
||||
// encounter.GET("", validatorFactory.Create(consts.ValidatorPrefix+"EncounterList"))
|
||||
encounter.POST("", validatorFactory.Create(consts.ValidatorPrefix+"EnconterStore"))
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
// //处理静态资源(不建议gin框架处理静态资源,参见 public/readme.md 说明 ) // INFO 已经交给 Nginx 了
|
||||
|
Loading…
x
Reference in New Issue
Block a user