Skip to content

Commit

Permalink
fixed schema to show friends usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonghua committed Oct 21, 2024
1 parent 2b982d3 commit d1ce0b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apis/profiles_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ def get_user_friends(username):

query_friends = """
SELECT
friends.friend_id
users2.username
FROM
friends
LEFT JOIN users ON friends.user_id = users.user_id
users users1
JOIN
friends f ON users1.user_id = f.user_id
JOIN
users users2 ON f.friend_id = users2.user_id
WHERE
users.username=%s
users1.username=%s
"""

with get_db().cursor(cursor=DictCursor) as cursor:
Expand Down
6 changes: 6 additions & 0 deletions frontend/static/js/pages/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ var app = new Vue({
this.profileName = serverData["profile_name"];
}
},

methods: {
addFriend(){
console.log("ADD FRIEND");
}
}
});
1 change: 1 addition & 0 deletions scripts/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ CREATE TABLE IF NOT EXISTS `cmty_pending_prompts_marathon` (
CREATE TABLE IF NOT EXISTS `friends` (
`user_id` INT NOT NULL,
`friend_id` INT NOT NULL,
PRIMARY KEY (`user_id`, `friend_id`),
FOREIGN KEY (`user_id`) REFERENCES `users`(`user_id`),
FOREIGN KEY (`friend_id`) REFERENCES `users`(`user_id`)
);

0 comments on commit d1ce0b1

Please sign in to comment.