Skip to content

Commit 488e7d0

Browse files
sunbagelemilyniee
andcommitted
Refactoring scheduling schema
Co-authored-by: emilyniee <[email protected]>
1 parent e0284c6 commit 488e7d0

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

backend/app/models/AvailableTime.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from sqlalchemy import Column, Integer, String
2+
3+
from .Base import Base
4+
5+
# AvailableTimes as a pure association table
6+
# only exists to establish a relationship between Users and Time Blocks
7+
# a User has an Availability which is composed of many time blocks
8+
available_times = Table(
9+
"available_times",
10+
Base.metadata,
11+
Column("time_block_id", ForeignKey("time_blocks.id"), primary_key=True),
12+
Column("user_id", ForeignKey("users.id"), primary_key=True),
13+
)

backend/app/models/SuggestedTime.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from .Base import Base
2+
from sqlalchemy import Column, DateTime, ForeignKey
3+
4+
# SuggestedTimes as a pure association table
5+
# only exists to establish a relationship between Matches and Time Blocks (many to many relationship)
6+
suggested_times = Table(
7+
"suggested_times",
8+
Base.metadata,
9+
# composite key of match and time block
10+
Column("match_id", ForeignKey("matches.id"), primary_key=True),
11+
Column("time_block_id", ForeignKey("time_blocks.id"), primary_key=True),
12+
)

backend/app/models/TimeBlock.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
class TimeBlock(Base):
1111
__tablename__ = "time_blocks"
1212
id = Column(Integer, primary_key=True)
13-
schedule_id = Column(Integer, ForeignKey("schedules.id"), nullable = False)
1413
start_time = Column(DateTime)
15-
end_time = Column(DateTime)
1614

17-
schedule = relationship("Schedule", back_populates="time_blocks")
15+
# if a match has been confirmed on this time block, this is non null
16+
confirmed_match = relationship("Match", back_populates="confirmed_time", uselist=False)
1817

18+
# suggested matches
19+
suggested_matches = relationship("Match", secondary="suggested_times", back_populates="suggested_time_blocks")
20+
21+
# the availability that the timeblock is a part of for a given user
22+
users = relationship("User", secondary="available_times", back_populates="availability")
23+

backend/app/models/User.py

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ class User(Base):
1717
auth_id = Column(String, nullable=False)
1818

1919
role = relationship("Role")
20+
21+
# time blocks in an availability for a user
22+
availability = relationship("TimeBlock", secondary="available_times", back_populates="users")

0 commit comments

Comments
 (0)