Add endpoint for deleting link
This commit is contained in:
parent
2cfd175414
commit
99be0824cd
1 changed files with 17 additions and 0 deletions
|
|
@ -53,11 +53,28 @@ func redirectHandler(c echo.Context, pool *pgxpool.Pool) error {
|
|||
return c.Redirect(http.StatusSeeOther, link.RedirectURL.String())
|
||||
}
|
||||
|
||||
func removalHandler(c echo.Context, pool *pgxpool.Pool) error {
|
||||
linkId := c.Param("id")
|
||||
|
||||
rep := PgRepository{pool: pool}
|
||||
|
||||
if err := rep.DeleteById(linkId); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func AddHandlers(s *echo.Echo, pool *pgxpool.Pool) {
|
||||
s.POST("", func(ctx echo.Context) error {
|
||||
return creationHandler(ctx, pool)
|
||||
})
|
||||
|
||||
s.GET("/:id", func(ctx echo.Context) error {
|
||||
return redirectHandler(ctx, pool)
|
||||
})
|
||||
|
||||
s.DELETE("/:id", func(ctx echo.Context) error {
|
||||
return removalHandler(ctx, pool)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue