diff --git a/handler/admin/photo.go b/handler/admin/photo.go index 263478db..4f629a70 100644 --- a/handler/admin/photo.go +++ b/handler/admin/photo.go @@ -113,7 +113,6 @@ func (p *PhotoHandler) UpdatePhoto(ctx *gin.Context) (interface{}, error) { } photoParam := ¶m.Photo{} err = ctx.ShouldBindJSON(photoParam) - if err != nil { e := validator.ValidationErrors{} if errors.As(err, &e) { @@ -136,6 +135,21 @@ func (p *PhotoHandler) DeletePhoto(ctx *gin.Context) (interface{}, error) { return nil, p.PhotoService.Delete(ctx, id) } +func (p *PhotoHandler) DeletePhotoBatch(ctx *gin.Context) (interface{}, error) { + photosParam := make([]int32, 0) + err := ctx.ShouldBindJSON(&photosParam) + if err != nil { + return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("parameter error") + } + for _, id := range photosParam { + err := p.PhotoService.Delete(ctx, id) + if err != nil { + return nil, err + } + } + return nil, nil +} + func (p *PhotoHandler) ListPhotoTeams(ctx *gin.Context) (interface{}, error) { return p.PhotoService.ListTeams(ctx) } diff --git a/handler/router.go b/handler/router.go index 5e92c14f..9f1684df 100644 --- a/handler/router.go +++ b/handler/router.go @@ -226,7 +226,7 @@ func (s *Server) RegisterRouters() { photoRouter.GET("/latest", s.wrapHandler(s.PhotoHandler.ListPhoto)) photoRouter.GET("", s.wrapHandler(s.PhotoHandler.PagePhotos)) photoRouter.GET("/:id", s.wrapHandler(s.PhotoHandler.GetPhotoByID)) - photoRouter.DELETE("/:id", s.wrapHandler(s.PhotoHandler.DeletePhoto)) + photoRouter.DELETE("/batch", s.wrapHandler(s.PhotoHandler.DeletePhotoBatch)) photoRouter.POST("", s.wrapHandler(s.PhotoHandler.CreatePhoto)) photoRouter.POST("/batch", s.wrapHandler(s.PhotoHandler.CreatePhotoBatch)) photoRouter.PUT("/:id", s.wrapHandler(s.PhotoHandler.UpdatePhoto))