-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get reviews for user #20
Merged
Merged
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c49311f
some draft code
luisa-li 2ac1bda
me when i fix
luisa-li 210f9b9
stuff
luisa-li 88ecab3
done.........?
luisa-li 0aeb1bb
I FIXED IT
luisa-li 0c9d32c
merge main into this branch
luisa-li 7afcfc0
moved review
luisa-li 28e34fc
mmm
luisa-li f7fbe4a
fix: changed error logging to conform to centralized logging
zcroft27 a7011c0
fix: changed error logging to conform to centralized logging
zcroft27 02b38d4
Merge branch 'get_reviews_for_user' of https://github.com/GenerateNU/…
zcroft27 b09f170
fix: GetReviewsByUserID implemented and ReviewHandler has a userRepos…
zcroft27 e732144
fixed nonexistent user 404 and existing but no review user 404
luisa-li 5671230
Merge branch 'main' into get_reviews_for_user
luisa-li fad9be5
merge main into branch
luisa-li 5fbc2a8
moving review handlers into own folder and separating out handler
luisa-li 6f97d14
moving stuff
luisa-li 8ef7145
dessy comment on moving UserExists
luisa-li 4dc2293
many more comments addressed
luisa-li 0200ecc
merge main
luisa-li 231159c
is this the end...?
luisa-li File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package models | ||
|
||
import "time" | ||
|
||
type Review struct { | ||
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package users | ||
|
||
import ( | ||
"platnm/internal/storage" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type ReviewHandler struct { | ||
reviewRepository storage.ReviewRepository | ||
} | ||
|
||
func NewReviewHandler(reviewRepository storage.ReviewRepository) *ReviewHandler { | ||
return &ReviewHandler{ | ||
reviewRepository, | ||
} | ||
} | ||
|
||
func (h *ReviewHandler) GetReviewsByUserID(c *fiber.Ctx) error { | ||
id := c.Params("id") | ||
review,err := h.reviewRepository.GetReviewsByUserID(c.Context(), id) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.Status(fiber.StatusOK).JSON(review) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package user | ||
|
||
import ( | ||
"context" | ||
"platnm/internal/models" | ||
|
||
"time" | ||
|
||
"github.com/jackc/pgx/v5/pgxpool" | ||
|
||
"fmt" | ||
) | ||
|
||
type ReviewRepository struct { | ||
db *pgxpool.Pool | ||
} | ||
|
||
func (r *ReviewRepository) GetReviewsByUserID(ctx context.Context, id string) ([]*models.Review, error) { | ||
|
||
rows, err := r.db.Query(ctx, "SELECT * FROM review WHERE user_id = $1", id) | ||
|
||
if !rows.Next() { | ||
fmt.Println("No rows found, likely an invalid user_id.") | ||
} | ||
|
||
if err != nil { | ||
print(err.Error(), "from transactions err ") | ||
ddusichka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print("id %s is not a valid id ", id) | ||
return []*models.Review{}, err | ||
} | ||
|
||
defer rows.Close() | ||
|
||
var reviews []*models.Review | ||
for rows.Next() { | ||
|
||
var review models.Review | ||
|
||
var mediaType, comment, userID, mediaID, rating *string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont think u need these temp vars. u can bind directly to fields of review struct that u define on line 28 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see this from the docs |
||
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 ") | ||
ddusichka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return reviews, err | ||
} | ||
|
||
review.UserID = *userID | ||
review.MediaID = *mediaID | ||
review.MediaType = *mediaType | ||
review.Comment = *comment | ||
review.Rating = *rating | ||
review.CreatedAt = *createdAt | ||
review.UpdatedAt = *updatedAt | ||
|
||
reviews = append(reviews, &review) | ||
} | ||
|
||
if err := rows.Err(); err != nil { | ||
print(err.Error(), "from transactions err ") | ||
ddusichka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return []*models.Review{}, err | ||
} | ||
|
||
return reviews, nil | ||
|
||
} | ||
|
||
func NewReviewRepository(db *pgxpool.Pool) *ReviewRepository { | ||
return &ReviewRepository{ | ||
db: db, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure this lives in
package reviews
and a corresponding reviews folder!also, following a more modular handler structure where each handler method gets its own file is a good way for us to avoid having massive files - see this PR's create_review file as an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!