fix: delete photo batch

pull/390/head
golangboy 1 year ago
parent 2b70e39629
commit b242d57b5a

@ -113,7 +113,6 @@ func (p *PhotoHandler) UpdatePhoto(ctx *gin.Context) (interface{}, error) {
}
photoParam := &param.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)
}

@ -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))

Loading…
Cancel
Save