feat:完善项目信息
This commit is contained in:
22
app/api/website/api/user.go
Normal file
22
app/api/website/api/user.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/website/controller/user"
|
||||||
|
"SciencesServer/app/basic/api"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type User struct{}
|
||||||
|
|
||||||
|
func (*User) Collect(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||||
|
ObjectID uint64 `json:"object_id" form:"object_id" binding:"required"`
|
||||||
|
}{}
|
||||||
|
if err := api.Bind(form)(c); err != nil {
|
||||||
|
api.APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := user.NewCollect()(nil).Launch(form.Kind, form.ObjectID)
|
||||||
|
api.APIResponse(err)(c)
|
||||||
|
}
|
42
app/api/website/controller/user/collect.go
Normal file
42
app/api/website/controller/user/collect.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"SciencesServer/app/api/website/model"
|
||||||
|
model2 "SciencesServer/app/common/model"
|
||||||
|
"SciencesServer/app/session"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Collect struct {
|
||||||
|
*session.Enterprise
|
||||||
|
}
|
||||||
|
|
||||||
|
type CollectHandle func(session *session.Enterprise) *Collect
|
||||||
|
|
||||||
|
// Launch 收藏发起
|
||||||
|
func (c *Collect) Launch(kind int, objectID uint64) error {
|
||||||
|
mUserCollect := model.NewUserCollect()
|
||||||
|
|
||||||
|
where := []*model2.ModelWhere{
|
||||||
|
model2.NewWhere("uid", c.UID),
|
||||||
|
model2.NewWhere("kind", kind),
|
||||||
|
model2.NewWhere("object_id", objectID),
|
||||||
|
}
|
||||||
|
isExist, err := model2.FirstField(mUserCollect.UserCollect, []string{"id"}, where...)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if isExist {
|
||||||
|
return model2.Delete(mUserCollect.UserCollect)
|
||||||
|
}
|
||||||
|
mUserCollect.UID = c.UID
|
||||||
|
mUserCollect.Kind = model2.UserCollectKind(kind)
|
||||||
|
mUserCollect.ObjectID = objectID
|
||||||
|
return model2.Create(mUserCollect.UserCollect)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCollect() CollectHandle {
|
||||||
|
return func(session *session.Enterprise) *Collect {
|
||||||
|
return &Collect{session}
|
||||||
|
}
|
||||||
|
}
|
3
app/api/website/controller/user/instance.go
Normal file
3
app/api/website/controller/user/instance.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
type User func()
|
@ -28,6 +28,12 @@ func registerAPI(app *gin.Engine) {
|
|||||||
_api := new(api2.Index)
|
_api := new(api2.Index)
|
||||||
indexV1.GET("", _api.Instance)
|
indexV1.GET("", _api.Instance)
|
||||||
}
|
}
|
||||||
|
// User 用户信息管理
|
||||||
|
userV1 := v1.Group("/user")
|
||||||
|
{
|
||||||
|
_api := new(api2.User)
|
||||||
|
userV1.POST("/collect/launch", _api.Collect)
|
||||||
|
}
|
||||||
// Activity 活动信息管理
|
// Activity 活动信息管理
|
||||||
activityV1 := v1.Group("/activity")
|
activityV1 := v1.Group("/activity")
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user