Skip to content

Commit

Permalink
Resolving comments
Browse files Browse the repository at this point in the history
Resolving comments
  • Loading branch information
adescoteaux1 committed Sep 24, 2024
1 parent abe06f8 commit e6a8791
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions backend/internal/service/handler/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"fmt"
"platnm/internal/models"
"platnm/internal/storage"
"strconv"

Expand All @@ -18,15 +19,6 @@ func NewReviewHandler(reviewRepository storage.ReviewRepository) *ReviewHandler
}
}

func (h *ReviewHandler) GetReviews(c *fiber.Ctx) error {
review, err := h.reviewRepository.GetReviews(c.Context())
if err != nil {
return err
}

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

func (h *ReviewHandler) GetReviewById(c *fiber.Ctx, mediaType string) error {
var (
id = c.Params("id")
Expand Down Expand Up @@ -61,16 +53,15 @@ func (h *ReviewHandler) GetReviewById(c *fiber.Ctx, mediaType string) error {
}
}

var avgRating = getAve(scores)
var rating = getAve(scores)

var end = offset*limit - 1
var start = end - limit
var paginatedReview = review[start:end]

// Return the reviews and average rating
response := fiber.Map{
"avgRating": avgRating,
"reviews": paginatedReview,
response := Response{
AvgRating: rating,
Reviews: paginatedReview,
}

return c.Status(fiber.StatusOK).JSON(response)
Expand All @@ -87,3 +78,8 @@ func getAve(review []float64) float64 {
}
return avgRating
}

type Response struct {
AvgRating float64 `json:avgRating`

Check failure on line 83 in backend/internal/service/handler/review.go

View workflow job for this annotation

GitHub Actions / backend-lint

structtag: struct field tag `json:avgRating` not compatible with reflect.StructTag.Get: bad syntax for struct tag value (govet)
Reviews []*models.Review `json:reviews`

Check failure on line 84 in backend/internal/service/handler/review.go

View workflow job for this annotation

GitHub Actions / backend-lint

structtag: struct field tag `json:reviews` not compatible with reflect.StructTag.Get: bad syntax for struct tag value (govet)
}

0 comments on commit e6a8791

Please sign in to comment.