Skip to content

Commit

Permalink
fix: delete photo batch
Browse files Browse the repository at this point in the history
  • Loading branch information
golangboy authored and jakezhu9 committed Feb 23, 2024
1 parent 2b70e39 commit 6ff6deb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion handler/admin/photo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion handler/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 6ff6deb

Please sign in to comment.