Skip to content

Commit

Permalink
Merge branch 'main' into styling_ally
Browse files Browse the repository at this point in the history
  • Loading branch information
adescoteaux1 committed Dec 4, 2024
2 parents 1a98fcc + c1bd7f5 commit 0d67fd4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
7 changes: 7 additions & 0 deletions backend/internal/constants/platnm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package constants

const (
PostReaction = 1
Rating = 5
RecommendationLike = 1
)
1 change: 0 additions & 1 deletion backend/internal/storage/postgres/schema/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions backend/internal/storage/postgres/schema/recommendation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"errors"
"platnm/internal/constants"
"platnm/internal/errs"
"platnm/internal/models"
"strconv"
Expand Down Expand Up @@ -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

}
Expand Down
17 changes: 16 additions & 1 deletion backend/internal/storage/postgres/schema/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"platnm/internal/constants"
"platnm/internal/errs"
"platnm/internal/models"
"strconv"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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, `
Expand All @@ -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, `
Expand Down
10 changes: 2 additions & 8 deletions backend/internal/storage/postgres/schema/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/hooks/useProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 0d67fd4

Please sign in to comment.