like
This commit is contained in:
@@ -291,3 +291,19 @@ func ModelItemDelete(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Write(utils.ToJSON(model))
|
||||
}
|
||||
|
||||
// 添加一条喜欢
|
||||
func ModelsItemLike(w http.ResponseWriter, r *http.Request) {
|
||||
models.AccountRead(w, r, func(account *models.Account) {
|
||||
// 先检查模型是否存在
|
||||
var model = models.Model{ID: utils.ParamInt(mux.Vars(r)["id"], 0)}
|
||||
if err := configs.ORMDB().Take(&model, utils.ParamInt(mux.Vars(r)["id"], 0)).Error; err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
// 添加喜欢
|
||||
models.LikeModel.Add(strconv.Itoa(account.ID), strconv.Itoa(model.ID))
|
||||
w.Write([]byte("ok"))
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user