From ac066be7022bef39f1d51f4d7f5f27804e003545 Mon Sep 17 00:00:00 2001 From: Andrey Chervyakov Date: Mon, 15 Mar 2021 23:32:51 +0600 Subject: [PATCH] Add blueprint for link update endpoint --- link/handlers.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/link/handlers.go b/link/handlers.go index 804230d..da5fc13 100644 --- a/link/handlers.go +++ b/link/handlers.go @@ -82,6 +82,22 @@ func allRetrievalHandler(c echo.Context, serv *PgService) error { return c.JSON(http.StatusOK, models) } +/*func updateHandler(c echo.Context, serv *PgService) error { + linkId := c.Param("id") + + var model UpdateModel + if err := json.NewDecoder(c.Request().Body).Decode(&model); err != nil { + return echo.NewHTTPError(http.StatusBadRequest, "Invalid data format.") + } + + l, err := serv.GetById(linkId) + if err != nil { + return err + } + + return c.NoContent(http.StatusOK) +}*/ + func removalHandler(c echo.Context, serv *PgService) error { linkId := c.Param("id") @@ -95,21 +111,26 @@ func removalHandler(c echo.Context, serv *PgService) error { func AddHandlers(s *echo.Echo, pool *pgxpool.Pool) { serv := NewPgService(PgRepository{pool: pool}) - gr := s.Group("/links") + linksGroup := s.Group("/links") + exactLinkGroup := linksGroup.Group("/:id") - gr.POST("", func(ctx echo.Context) error { + linksGroup.POST("", func(ctx echo.Context) error { return creationHandler(ctx, &serv) }) - gr.GET("", func(ctx echo.Context) error { + linksGroup.GET("", func(ctx echo.Context) error { return allRetrievalHandler(ctx, &serv) }) - gr.GET("/:id", func(ctx echo.Context) error { + exactLinkGroup.GET("", func(ctx echo.Context) error { return retrievalByIdHandler(ctx, &serv) }) - gr.DELETE("/:id", func(ctx echo.Context) error { + /*exactLinkGroup.PATCH("", func(ctx echo.Context) error { + return updateHandler(ctx, &serv) + })*/ + + exactLinkGroup.DELETE("", func(ctx echo.Context) error { return removalHandler(ctx, &serv) })