Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
luisa-li committed Sep 19, 2024
1 parent 2ac1bda commit 210f9b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions backend/internal/service/handler/review.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package handler

import (
"fmt"
"platnm/internal/errs"
"platnm/internal/storage"

"github.com/gofiber/fiber/v2"
Expand All @@ -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 ")
Expand All @@ -27,4 +32,3 @@ func (h*ReviewHandler) GetReviewsByUserID(c *fiber.Ctx) error {

return c.Status(fiber.StatusOK).JSON(user)
}

4 changes: 2 additions & 2 deletions backend/internal/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
2 changes: 1 addition & 1 deletion backend/internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 210f9b9

Please sign in to comment.