+ DeleteRecipes
This commit is contained in:
@@ -312,3 +312,27 @@ func VoteFoodRecipe(ctx *jxcontext.Context, recipeID, voteType int) (err error)
|
||||
dao.Commit(db)
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteRecipes(ctx *jxcontext.Context, recipeIDs []int) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
for _, recipeID := range recipeIDs {
|
||||
recipe := &model.FoodRecipe{}
|
||||
recipe.ID = recipeID
|
||||
num2, err2 := dao.DeleteEntityLogically(db, recipe, nil, ctx.GetUserName(), nil)
|
||||
if err = err2; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
num += num2
|
||||
}
|
||||
dao.Commit(db)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -130,3 +130,20 @@ func (c *FoodRecipeController) VoteFoodRecipe() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 删除菜谱
|
||||
// @Description 删除菜谱
|
||||
// @Param token header string true "认证token"
|
||||
// @Param recipeIDs query string true "菜谱ID列表"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /DeleteRecipes [delete]
|
||||
func (c *FoodRecipeController) DeleteRecipes() {
|
||||
c.callDeleteRecipes(func(params *tFoodrecipeDeleteRecipesParams) (retVal interface{}, errCode string, err error) {
|
||||
var recipeIDs []int
|
||||
if err = jxutils.Strings2Objs(params.RecipeIDs, &recipeIDs); err == nil {
|
||||
retVal, err = userstore.DeleteRecipes(params.Ctx, recipeIDs)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -493,6 +493,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:FoodRecipeController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:FoodRecipeController"],
|
||||
beego.ControllerComments{
|
||||
Method: "DeleteRecipes",
|
||||
Router: `/DeleteRecipes`,
|
||||
AllowHTTPMethods: []string{"delete"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:FoodRecipeController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:FoodRecipeController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetRecipeDetail",
|
||||
|
||||
Reference in New Issue
Block a user