Skip to content

Commit

Permalink
I FIXED IT
Browse files Browse the repository at this point in the history
  • Loading branch information
luisa-li committed Sep 19, 2024
1 parent 88ecab3 commit 0aeb1bb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
16 changes: 8 additions & 8 deletions backend/internal/models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package models
import "time"

type Review struct {
ID string `json:"id"`
UserID int `json:"user_id"`
MediaID int `json:"media_id"`
MediaType string `json:"media_type"`
Rating int `json:"rating"`
Comment string `json:"comment"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID string `json:"id"`
UserID string `json:"user_id"`
MediaID string `json:"media_id"`
MediaType string `json:"media_type"`
Rating string `json:"rating"`
Comment string `json:"comment"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
9 changes: 2 additions & 7 deletions backend/internal/service/handler/review.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package handler

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

"github.com/gofiber/fiber/v2"
Expand All @@ -20,15 +18,12 @@ func NewReviewHandler(reviewRepository storage.ReviewRepository) *ReviewHandler

func (h *ReviewHandler) GetReviewsByUserID(c *fiber.Ctx) error {
id := c.Params("id")
if id == "" {
return errs.BadRequest(fmt.Errorf("received invalid ID. got %s", id))
}
user, err := h.reviewRepository.GetReviewsByUserID(c.Context(), id)
review, err := h.reviewRepository.GetReviewsByUserID(c.Context(), id)

if err != nil {
print(err.Error(), "from transactions err ")
return err
}

return c.Status(fiber.StatusOK).JSON(user)
return c.Status(fiber.StatusOK).JSON(review)
}
12 changes: 7 additions & 5 deletions backend/internal/storage/postgres/schema/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type ReviewRepository struct {
db *pgxpool.Pool
}

func (r *ReviewRepository) GetReviewsByUserID(id string, ctx context.Context) ([]*models.Review, error) {
func (r *ReviewRepository) GetReviewsByUserID(ctx context.Context, id string) ([]*models.Review, error) {

rows, err := r.db.Query(context.Background(), "SELECT * FROM review WHERE user_id = $1", id)
rows, err := r.db.Query(ctx, "SELECT * FROM review WHERE user_id = $1", id)
if err != nil {
print(err.Error(), "from transactions err ")
return []*models.Review{}, err
Expand All @@ -27,16 +27,16 @@ func (r *ReviewRepository) GetReviewsByUserID(id string, ctx context.Context) ([

var review models.Review

var ID, mediaType, comment *string
var userID, mediaID, rating *int
var mediaType, comment, userID, mediaID, rating *string
var createdAt, updatedAt *time.Time

if err := rows.Scan(&review.ID, &userID, &mediaID, &mediaType, &rating, &comment, &createdAt, &updatedAt); err != nil {
print(err.Error(), "from transactions err ")
return reviews, err
}

review.ID = *ID
print("are we here plsssss")

review.UserID = *userID
review.MediaID = *mediaID
review.MediaType = *mediaType
Expand All @@ -45,6 +45,8 @@ func (r *ReviewRepository) GetReviewsByUserID(id string, ctx context.Context) ([
review.CreatedAt = *createdAt
review.UpdatedAt = *updatedAt

print("chekc2 check2")

reviews = append(reviews, &review)
}

Expand Down
3 changes: 2 additions & 1 deletion backend/internal/storage/postgres/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func ConnectDatabase(host, user, password, dbname, port string) *pgxpool.Pool {

func NewRepository(db *pgxpool.Pool) *storage.Repository {
return &storage.Repository{
User: user.NewUserRepository(db),
User: user.NewUserRepository(db),
Review: user.NewReviewRepository(db),
}
}

0 comments on commit 0aeb1bb

Please sign in to comment.