-
Notifications
You must be signed in to change notification settings - Fork 1
LLSC-24: Scheduling API #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sunbagel
wants to merge
43
commits into
main
Choose a base branch
from
alex-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
5a0d435
Create schedules model
janealsh c8907d9
add dependencies
mmiqball 05ac366
add pdyantic user models
mmiqball cf4cff6
add Firebase authentication initialization
mmiqball 287d434
implement user creation endpoint
mmiqball 5f8fb34
add user creation unit test
mmiqball b44baf9
separate user service initialization in user routes
mmiqball a2bc89a
simplify firebase initialization
mmiqball 50c554e
load env before code executes
mmiqball a1abe9b
construct firebase service account key path from pwd
mmiqball 637db5c
Create schedules model
janealsh 7caddb5
Merge branch 'janealsh/LLSC-24-schedules-model' of https://github.com…
sunbagel 5ad9a78
create TimeBlock model
sunbagel 6a72e13
finalized schedule model
janealsh e52dad2
Finalize schedules model
janealsh c925fff
set up boilerplate code for schedules
sunbagel f2e74a0
create outline for schedules and schemas
sunbagel 55d8848
update schedule model
sunbagel 789ffc8
add create_schedule and update schemas
sunbagel 37091d0
update Schedule and TimeBlock models to include int id
sunbagel 4b4bd41
add alembic migration for new models
sunbagel 4bf5014
add schedule_states initialization in alembic
sunbagel a845a46
add create_schedule endpoint
sunbagel d353aea
testing schedule endpoint
sunbagel c43780d
update pdm lock
sunbagel 8c200f2
update Schedule schema
sunbagel c628efb
update ScheduleInDB pydantic schemas
sunbagel 488a556
Merge branch 'main' into merging-branch
sunbagel c6d711c
Fix scheduleservice paths
sunbagel e669131
update schedule_status
sunbagel 96a2e24
address comments
sunbagel b658eb9
remove schedule service interface
sunbagel 8ccb174
update revision name
sunbagel 76f8365
Fixing Nits (#24)
emilyniee dc656e2
Merge branch 'main' into alex-branch
emilyniee 8670ccd
remove create_time_block
sunbagel e0284c6
update ScheduleInDB to ScheduleEntity
sunbagel 9f27772
create new schemas
sunbagel 7933a6d
Refactoring scheduling schema
sunbagel 6995730
merge origin
sunbagel 9423e3a
add matches model (#27)
RohanNankani 551d6bd
update match schema
sunbagel 7499b20
fix migration
sunbagel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from sqlalchemy import Column, ForeignKey, Table | ||
|
|
||
| from .Base import Base | ||
|
|
||
| # AvailableTimes as a pure association table | ||
| # only exists to establish a relationship between Users and Time Blocks | ||
| # a User has an Availability which is composed of many time blocks | ||
| available_times = Table( | ||
| "available_times", | ||
| Base.metadata, | ||
| Column("time_block_id", ForeignKey("time_blocks.id"), primary_key=True), | ||
| Column("user_id", ForeignKey("users.id"), primary_key=True), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import enum | ||
|
|
||
| from sqlalchemy import Column, DateTime, ForeignKey, Integer | ||
| from sqlalchemy.dialects.postgresql import UUID | ||
| from sqlalchemy.orm import relationship | ||
| from sqlalchemy.sql import func | ||
|
|
||
| from .Base import Base | ||
|
|
||
|
|
||
| class Match(Base): | ||
| __tablename__ = "matches" | ||
|
|
||
| id = Column(Integer, primary_key=True) | ||
|
|
||
| participant_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) | ||
| volunteer_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) | ||
|
|
||
| # the chosen time block | ||
| chosen_time_block_id = Column(Integer, ForeignKey("time_blocks.id"), nullable=True) | ||
|
|
||
| match_status_id = Column( | ||
| Integer, ForeignKey("match_status.id"), nullable=False, default=1 | ||
| ) | ||
|
|
||
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | ||
| updated_at = Column( | ||
| DateTime(timezone=True), server_default=func.now(), onupdate=func.now() | ||
| ) | ||
|
|
||
| match_status = relationship("MatchStatus") | ||
|
|
||
| participant = relationship( | ||
| "User", foreign_keys=[participant_id], back_populates="matches" | ||
| ) | ||
| volunteer = relationship( | ||
| "User", foreign_keys=[volunteer_id], back_populates="matches" | ||
| ) | ||
|
|
||
| confirmed_time = relationship( | ||
| "TimeBlock", back_populates="confirmed_match", uselist=False | ||
| ) | ||
| suggested_time_blocks = relationship( | ||
| "TimeBlock", back_populates="suggested_matches" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from sqlalchemy import Column, Integer, String | ||
|
|
||
| from .Base import Base | ||
|
|
||
|
|
||
| class MatchStatus(Base): | ||
| __tablename__ = "match_status" | ||
| id = Column(Integer, primary_key=True) | ||
| name = Column(String(80), nullable=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from sqlalchemy import Column, ForeignKey, Table | ||
|
|
||
| from .Base import Base | ||
|
|
||
| # SuggestedTimes as a pure association table | ||
| # only exists to establish a relationship between Matches and Time Blocks (many to many) | ||
| suggested_times = Table( | ||
| "suggested_times", | ||
| Base.metadata, | ||
| # composite key of match and time block | ||
| Column("match_id", ForeignKey("matches.id"), primary_key=True), | ||
| Column("time_block_id", ForeignKey("time_blocks.id"), primary_key=True), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from sqlalchemy import Column, DateTime, Integer | ||
| from sqlalchemy.orm import relationship | ||
|
|
||
| from .Base import Base | ||
|
|
||
|
|
||
| class TimeBlock(Base): | ||
| __tablename__ = "time_blocks" | ||
| id = Column(Integer, primary_key=True) | ||
| start_time = Column(DateTime) | ||
|
|
||
| # if a match has been confirmed on this time block, this is non null | ||
| confirmed_match = relationship( | ||
| "Match", back_populates="confirmed_time", uselist=False | ||
| ) | ||
|
|
||
| # suggested matches | ||
| suggested_matches = relationship( | ||
| "Match", secondary="suggested_times", back_populates="suggested_time_blocks" | ||
| ) | ||
|
|
||
| # the availability that the timeblock is a part of for a given user | ||
| users = relationship( | ||
| "User", secondary="available_times", back_populates="availability" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from fastapi import APIRouter, Depends, HTTPException | ||
| from sqlalchemy.orm import Session | ||
|
|
||
| from app.schemas.schedule import ScheduleCreateRequest, ScheduleEntity | ||
| from app.services.implementations.schedule_service import ScheduleService | ||
| from app.utilities.db_utils import get_db | ||
|
|
||
| router = APIRouter( | ||
| prefix="/schedules", | ||
| tags=["schedules"], | ||
| ) | ||
|
|
||
|
|
||
| def get_schedule_service(db: Session = Depends(get_db)): | ||
| return ScheduleService(db) | ||
|
|
||
|
|
||
| @router.post("/", response_model=ScheduleEntity) | ||
| async def create_schedule( | ||
| schedule: ScheduleCreateRequest, | ||
| schedule_service: ScheduleService = Depends(get_schedule_service), | ||
| ): | ||
| try: | ||
| created_schedule = await schedule_service.create_schedule(schedule) | ||
| return created_schedule | ||
| except HTTPException as http_ex: | ||
| raise http_ex | ||
| except Exception as e: | ||
| print(e) | ||
| raise HTTPException(status_code=500, detail=str(e)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| from datetime import datetime, timedelta | ||
| from enum import Enum | ||
| from typing import List, Optional | ||
| from uuid import UUID | ||
|
|
||
| from pydantic import BaseModel, ConfigDict | ||
|
|
||
| from app.schemas.time_block import TimeBlockBase, TimeBlockFull, TimeBlockId | ||
|
|
||
|
|
||
| class ScheduleStatus(str, Enum): | ||
| PENDING_VOLUNTEER = "PENDING_VOLUNTEER_RESPONSE" | ||
| PENDING_PARTICIPANT = "PENDING_PARTICIPANT_RESPONSE" | ||
| SCHEDULED = "SCHEDULED" | ||
| COMPLETED = "COMPLETED" | ||
|
|
||
| @classmethod | ||
| def to_schedule_status_id(cls, state: "ScheduleStatus") -> int: | ||
| status_map = { | ||
| cls.PENDING_VOLUNTEER: 1, | ||
| cls.PENDING_PARTICIPANT: 2, | ||
| cls.SCHEDULED: 3, | ||
| cls.COMPLETED: 4, | ||
| } | ||
|
|
||
| return status_map[state] | ||
|
|
||
|
|
||
| class ScheduleBase(BaseModel): | ||
| scheduled_time: Optional[datetime] | ||
| duration: Optional[timedelta] | ||
| status_id: int | ||
|
|
||
|
|
||
| class ScheduleEntity(ScheduleBase): | ||
| id: int | ||
|
|
||
| model_config = ConfigDict(from_attributes=True) | ||
|
|
||
|
|
||
| # Provides both Schedule data and full TimeBlock data | ||
| class ScheduleGetResponse(ScheduleEntity): | ||
| time_blocks: List[TimeBlockFull] | ||
|
|
||
|
|
||
| # List of Start and End times to Create a Schedule with | ||
| class ScheduleCreateRequest(BaseModel): | ||
| time_blocks: List[TimeBlockBase] | ||
|
|
||
|
|
||
| class ScheduleUpdateRequest(BaseModel): | ||
| schedule_id: UUID | ||
| time_blocks: List[TimeBlockBase] | ||
|
|
||
|
|
||
| class ScheduleDeleteRequest(BaseModel): | ||
| schedule_id: UUID | ||
| time_blocks: List[TimeBlockId] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from datetime import datetime | ||
| from uuid import UUID | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class TimeBlockBase(BaseModel): | ||
| start_time: datetime | ||
| end_time: datetime | ||
|
|
||
|
|
||
| class TimeBlockId(BaseModel): | ||
| id: UUID | ||
|
|
||
|
|
||
| class TimeBlockFull(TimeBlockBase, TimeBlockId): | ||
| """ | ||
| Combines TimeBlockBase and TimeBlockId. | ||
| Represents a full time block with an ID and time range. | ||
| """ | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class TimeBlockEntity(BaseModel): | ||
| id: UUID | ||
| schedule_id: int | ||
| start_time: datetime | ||
| end_time: datetime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: keep these in the same order as in the DB, just in case someone uses this as a reference for the ordering.