From 210f9b916f03cf6e19f1279bb1ad43cf658028ae Mon Sep 17 00:00:00 2001 From: Luisa <103768169+luisa-li@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:12:14 -0400 Subject: [PATCH] stuff --- backend/internal/service/handler/review.go | 10 +++++++--- backend/internal/service/server.go | 4 ++-- backend/internal/storage/storage.go | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/internal/service/handler/review.go b/backend/internal/service/handler/review.go index 657706d9..45565a44 100644 --- a/backend/internal/service/handler/review.go +++ b/backend/internal/service/handler/review.go @@ -1,6 +1,8 @@ package handler import ( + "fmt" + "platnm/internal/errs" "platnm/internal/storage" "github.com/gofiber/fiber/v2" @@ -16,9 +18,12 @@ func NewReviewHandler(reviewRepository storage.ReviewRepository) *ReviewHandler } } -func (h*ReviewHandler) GetReviewsByUserID(c *fiber.Ctx) error { +func (h *ReviewHandler) GetReviewsByUserID(c *fiber.Ctx) error { id := c.Params("id") - user, err := h.reviewRepository.GetReviewsByUserID(id, c.Context()) + if id == "" { + return errs.BadRequest(fmt.Errorf("received invalid ID. got %s", id)) + } + user, err := h.reviewRepository.GetReviewsByUserID(c.Context(), id) if err != nil { print(err.Error(), "from transactions err ") @@ -27,4 +32,3 @@ func (h*ReviewHandler) GetReviewsByUserID(c *fiber.Ctx) error { return c.Status(fiber.StatusOK).JSON(user) } - diff --git a/backend/internal/service/server.go b/backend/internal/service/server.go index 7c8a0632..4f3e0da2 100644 --- a/backend/internal/service/server.go +++ b/backend/internal/service/server.go @@ -37,9 +37,9 @@ func setupRoutes(app *fiber.App, conn *pgxpool.Pool) { r.Get("/", userHandler.GetUsers) r.Get("/:id", userHandler.GetUserById) }) + reviewHandler := handler.NewReviewHandler(repository.Review) app.Route("/reviews", func(r fiber.Router) { - reviewHandler := handler.NewReviewHandler(repository.Review) - r.Get("/", reviewHandler.GetReviewsByUserID) + r.Get("/:id", reviewHandler.GetReviewsByUserID) }) } diff --git a/backend/internal/storage/storage.go b/backend/internal/storage/storage.go index ab0426dd..bed700a3 100644 --- a/backend/internal/storage/storage.go +++ b/backend/internal/storage/storage.go @@ -11,7 +11,7 @@ type UserRepository interface { } type ReviewRepository interface { - GetReviewsByUserID(id string, ctx context.Context) ([]*models.Review, error) + GetReviewsByUserID(ctx context.Context, id string) ([]*models.Review, error) } // Repository storage of all repositories.