diff --git a/link/handlers.go b/link/handlers.go index a54e644..da24868 100644 --- a/link/handlers.go +++ b/link/handlers.go @@ -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) + }) }