diff --git a/backend/internal/constants/platnm.go b/backend/internal/constants/platnm.go new file mode 100644 index 00000000..f2fec3f7 --- /dev/null +++ b/backend/internal/constants/platnm.go @@ -0,0 +1,7 @@ +package constants + +const ( + PostReaction = 1 + Rating = 5 + RecommendationLike = 1 +) diff --git a/backend/internal/storage/postgres/schema/playlist.go b/backend/internal/storage/postgres/schema/playlist.go index 7663c8eb..50e42dd6 100644 --- a/backend/internal/storage/postgres/schema/playlist.go +++ b/backend/internal/storage/postgres/schema/playlist.go @@ -30,7 +30,6 @@ func (r *PlaylistRepository) CreatePlaylist(ctx context.Context, playlist models return err } return nil - } func (r *PlaylistRepository) AddToUserOnQueue(ctx context.Context, id string, track models.Track) error { diff --git a/backend/internal/storage/postgres/schema/recommendation.go b/backend/internal/storage/postgres/schema/recommendation.go index a6e00a5f..66a3e134 100644 --- a/backend/internal/storage/postgres/schema/recommendation.go +++ b/backend/internal/storage/postgres/schema/recommendation.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "errors" + "platnm/internal/constants" "platnm/internal/errs" "platnm/internal/models" "strconv" @@ -175,6 +176,11 @@ func (r *RecommendationRepository) UpdateRecommendation(ctx context.Context, rec return err } + _, err = r.Exec(ctx, `UPDATE "user" SET platnm = platnm + $1 WHERE id = $2`, constants.RecommendationLike, recommendation.RecommenderId) + if err != nil { + return err + } + return nil } diff --git a/backend/internal/storage/postgres/schema/review.go b/backend/internal/storage/postgres/schema/review.go index 617ee96b..a2841878 100644 --- a/backend/internal/storage/postgres/schema/review.go +++ b/backend/internal/storage/postgres/schema/review.go @@ -5,6 +5,7 @@ import ( "database/sql" "errors" "fmt" + "platnm/internal/constants" "platnm/internal/errs" "platnm/internal/models" "strconv" @@ -100,6 +101,11 @@ func (r *ReviewRepository) CreateReview(ctx context.Context, review *models.Revi } } + _, err := r.Exec(ctx, `UPDATE "user" SET platnm = platnm + $1 WHERE id = $2`, constants.Rating, review.UserID) + if err != nil { + return nil, err + } + return review, nil } @@ -1082,6 +1088,11 @@ func (r *ReviewRepository) UserVote(ctx context.Context, userID string, postID s // check if the review has more than 10 upvotes and if so notify the person that made the review review, _ := r.GetReviewByID(ctx, postID) + _, err = r.Exec(ctx, `UPDATE "user" SET platnm = platnm + $1 WHERE id = $2`, constants.RecommendationLike, review.UserID) + if err != nil { + return err + } + if review.ReviewStat.Upvotes >= 10 { // if we have more 10 upvotes on the review now _, err = r.Exec(ctx, ` @@ -1092,13 +1103,17 @@ func (r *ReviewRepository) UserVote(ctx context.Context, userID string, postID s if err != nil { return err } - } } else if postType == "comment" { comment, _ := r.GetCommentByCommentID(ctx, postID) + _, err = r.Exec(ctx, `UPDATE "user" SET platnm = platnm + $1 WHERE id = $2`, constants.PostReaction, comment.UserID) + if err != nil { + return err + } + if comment.Upvotes >= 10 { // if we have more 10 upvotes on the comment now _, err = r.Exec(ctx, ` diff --git a/backend/internal/storage/postgres/schema/user.go b/backend/internal/storage/postgres/schema/user.go index bf4c0a75..8ef62d3a 100644 --- a/backend/internal/storage/postgres/schema/user.go +++ b/backend/internal/storage/postgres/schema/user.go @@ -217,25 +217,19 @@ func (r *UserRepository) UpdateUserOnboard(ctx context.Context, email string, en func (r *UserRepository) GetUserProfile(ctx context.Context, id uuid.UUID) (*models.Profile, error) { profile := &models.Profile{} - query := `SELECT u.id, u.username, u.display_name, COUNT(DISTINCT followers.follower_id) AS follower_count, COUNT(DISTINCT followed.followee_id) AS followed_count, u.bio, u.profile_picture + query := `SELECT u.id, u.username, u.display_name, COUNT(DISTINCT followers.follower_id) AS follower_count, COUNT(DISTINCT followed.followee_id) AS followed_count, u.bio, u.profile_picture, u.platnm FROM "user" u LEFT JOIN follower followers ON followers.followee_id = u.id LEFT JOIN follower followed ON followed.follower_id = u.id WHERE u.id = $1 GROUP BY u.id, u.username, u.display_name, u.bio, u.profile_picture;` - err := r.db.QueryRow(ctx, query, id).Scan(&profile.UserID, &profile.Username, &profile.DisplayName, &profile.Followers, &profile.Followed, &profile.Bio, &profile.ProfilePicture) + err := r.db.QueryRow(ctx, query, id).Scan(&profile.UserID, &profile.Username, &profile.DisplayName, &profile.Followers, &profile.Followed, &profile.Bio, &profile.ProfilePicture, &profile.Score) if err != nil { print(err.Error(), "unable to find profile") return nil, err } - score, err := r.CalculateScore(ctx, id) - if err != nil { - return nil, err - } - profile.Score = score - return profile, nil } diff --git a/frontend/hooks/useProfile.ts b/frontend/hooks/useProfile.ts index dbbd8dff..5cf2ad1d 100644 --- a/frontend/hooks/useProfile.ts +++ b/frontend/hooks/useProfile.ts @@ -28,6 +28,7 @@ export function useProfile(userId: string) { const response = await axios.get( `${BASE_URL}/users/profile/id/${userId}`, ); + console.log("Profile:", response.data); const profile = { user_id: response.data.user_id, username: response.data.username, @@ -38,6 +39,7 @@ export function useProfile(userId: string) { followed: response.data.followed, score: response.data.score, }; + setUserProfile(profile); setBio(response.data.bio.String); } catch (error) {