We want a system that allows people to add each other as friends. This would allow people to see where friends are seated in the seatmap. In addition, it would also give us information that allows us to move people around without splitting up friend groups.
Design concept
The idea is a system where we use a single table to track the lifetime of friendships. A friendship is created when an user sends a friend request. Accepting the friend request sets an "accepted" column to a non-null value, meaning that the request is accepted. If the "deleted" column is set, the friend request should be invisible to users if they aren't using the views/friend_request/instance GET request
Requirements
Database models
Friendship
Represents a friend request, and when accepted, the actual friendship.
Fields:
UUID - Uuid, primary key
From - User
To - User
Created - Datetime
Accepted - Datetime, nullable
Deleted - Datetime, nullable
Remember to create a sqlalchemy migration!
API
User
views/user/instance
GET friendships - Lists all friendships where accepted is not null and deleted is null, and the user instance is either in the to or from column
GET friend_requests - Lists all friend requests where accepted is null, deleted is not null, and the user is either in the to or from column(show all incoming and outgoing friend requests)
views/friend_request/init:
POST (empty name) - Create new friendship. Should error if you already have a friendship that isn't deleted between the current user and the to user. Takes one argument, user_email - the email of the user we want to add as a friend. Returns the friendship object when created.
views/friend_request/instance:
GET (empty name) - View friendship. You must be ADMIN, HR_ADMIN, TICKET_ADMIN, or either the to or from user in order to access it.
DELETE (empty name) - Marks the friendship as Deleted.
POST accept - Accepts the friend request by setting accepted to datetime.now(). Should error if the friend request is already accepted. Should error if the current user isn't the one in the to field - you cannot accept friend requests you made yourself.
Tests
Ensure that you cannot accept your own friend request
Ensure you cannot create a friend request if a non-deleted one already exists(either pending or accepted state)
We want a system that allows people to add each other as friends. This would allow people to see where friends are seated in the seatmap. In addition, it would also give us information that allows us to move people around without splitting up friend groups.
Design concept
The idea is a system where we use a single table to track the lifetime of friendships. A friendship is created when an user sends a friend request. Accepting the friend request sets an "accepted" column to a non-null value, meaning that the request is accepted. If the "deleted" column is set, the friend request should be invisible to users if they aren't using the views/friend_request/instance GET request
Requirements
Database models
Friendship
Represents a friend request, and when accepted, the actual friendship.
Fields:
Remember to create a sqlalchemy migration!
API
User
accepted
is not null anddeleted
is null, and the user instance is either in theto
orfrom
columnaccepted
is null,deleted
is not null, and the user is either in theto
orfrom
column(show all incoming and outgoing friend requests)to
user. Takes one argument,user_email
- the email of the user we want to add as a friend. Returns the friendship object when created.to
orfrom
user in order to access it.accepted
to datetime.now(). Should error if the friend request is already accepted. Should error if the current user isn't the one in theto
field - you cannot accept friend requests you made yourself.Tests