Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
delete gallery handle
  • Loading branch information
sxc committed Jul 7, 2023
2 parents 3c9d205 + ce06bed commit 243deb3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions controllers/galleries.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ func (g Galleries) Show(w http.ResponseWriter, r *http.Request) {
g.Templates.Show.Execute(w, r, data)
}

func (g Galleries) Delete(w http.ResponseWriter, r *http.Request) {
gallery, err := g.galleryByID(w, r, userMustOwnGallery)
if err != nil {
return
}
err = g.GalleryService.Delete(gallery.ID)
if err != nil {
http.Error(w, "Something went wrong", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/galleries", http.StatusFound)
}

type galleryOpt func(http.ResponseWriter, *http.Request, *models.Gallery) error

func (g Galleries) galleryByID(w http.ResponseWriter, r *http.Request, opts ...galleryOpt) (*models.Gallery, error) {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func main() {
r.Post("/", galleriesC.Create)
r.Get("/{id}/edit", galleriesC.Edit)
r.Post("/{id}", galleriesC.Update)
r.Post("/{id}/delete", galleriesC.Delete)

})
})
Expand Down
2 changes: 1 addition & 1 deletion templates/galleries/index.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
text-xs
rounded"
>Edit</a>
<form action="galleries/{{.ID}}/delte" method="post"
<form action="galleries/{{.ID}}/delete" method="post"
onsubmit="return confirm('Are you sure to delete this gallery?')">
{{csrfField}}
<button type="submit"
Expand Down

0 comments on commit 243deb3

Please sign in to comment.