-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Yiran li/feature/create shift api v2 (#301)
## Describe your changes In this PR, we mainly implemented the functionality for creating new shift requests. I also enhanced the `update_status` function by introducing a conflict check when the status is changed to accepted, ensuring that any conflicting shifts are detected before the status is updated. Additionally, an unavailability time record is created when a shift is accepted. Furthermore, we made modifications to the database schema by adding the `shift_position` table and establishing relationships between the `shift_request`, `shift_request_volunteer`, and `shift_position` tables. ### Functional changes #### Create new shift We added functionality to allow users to create new shift requests. These requests include details such as title, start time, end time, and vehicle type. Based on the vehicle type, the system determines the number and types of volunteer roles (such as 'Crew Leader', 'Driver', 'Advanced', and 'Basic') required for the shift. These roles are then stored in the `shift_position` table, ensuring that each shift has the correct set of roles assigned to it. #### Update Status The `update_status` function was enhanced to incorporate conflict detection when a shift status is changed to accepted. When the status is updated to accepted, the system performs a conflict check by querying the database for any other confirmed shifts assigned to the same volunteer that overlap in time. If a conflict is detected, the status change is rejected, and a `ConflictError` is raised. If no conflict is found, the status is updated, and an `unavailability_time` record is created, marking the volunteer's time as unavailable during the shift period. This ensures accurate scheduling and prevents volunteers from being double-booked. Additionally, the function handles updating shifts to other statuses, such as rejected. When a shift is rejected, the status is simply updated without further checks. ### Database Changes ### Add `shift_position` table The `shift_position` table was introduced to store information about the roles required for each shift based on the type of vehicle involved. The `create_positions` function dynamically generates positions for each shift according to the vehicle_type. Depending on the vehicle type, a predefined set of roles (e.g., crewLeader, driver, advanced, basic) is assigned to the shift. For example: **Heavy Tanker**: Six roles are assigned—crewLeader, driver, two advanced, and two basic roles. **Medium Tanker**: Four roles are assigned—crewLeader, driver, advanced, and basic. **Light Unit**: Two roles are assigned—driver and basic. Each role is saved as a record in the `shift_position` table, with the associated `shift_id` and `role_code`. This flexible design allows different vehicle types to require varying numbers and types of volunteers for each shift. #### Modify `unavailability_time` table The `unavailability_time` table was updated with a new column called `is_shift`. This column is a boolean field that indicates whether the unavailability time corresponds to a scheduled shift. When a volunteer accepts a shift, a corresponding unavailability time record is created with the `is_shift` flag set to True. This allows the system to distinguish between general unavailability times and those specifically associated with accepted shifts. #### Status Enum Updates The status enums were updated for both `ShiftStatus` and `ShiftVolunteerStatus` to reflect clearer stages in the shift lifecycle. For ShiftRequest, statuses such as "pending," "submitted," "confirmed," and "completed" were introduced. For ShiftRequestVolunteer, "accepted" replaced the former "confirmed" status to better align with the system's workflow. ### I have already done some basic test for these updates in Postman. ## Issue ticket number and link https://fireapp-emergiq-2024.atlassian.net/browse/FIR-112?atlOrigin=eyJpIjoiNmMyYmJiODlhZWI5NGUwY2JjYmIwNzkwMGY5N2M3ZTMiLCJwIjoiaiJ9 --------- Co-authored-by: anannnchim <[email protected]> Co-authored-by: Steven (Quoc) <[email protected]>
- Loading branch information
1 parent
58313c3
commit 91fbcb9
Showing
15 changed files
with
233 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,21 +1,16 @@ | ||
from datetime import datetime | ||
|
||
from sqlalchemy import Column, String, DateTime, ForeignKey, Integer, Enum | ||
from sqlalchemy import Column, String, ForeignKey, Integer | ||
from sqlalchemy.orm import relationship | ||
|
||
from domain.base import Base | ||
|
||
|
||
class ShiftPosition(Base): | ||
__tablename__ = 'shift_position' | ||
|
||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
shift_id = Column(Integer, ForeignKey('shift_request.id'), nullable=False) | ||
role_code = Column(String(256), ForeignKey('role.code'), nullable=False) | ||
shift_id = Column(Integer, ForeignKey('shift_request.id'), name='shift_id', nullable=False) | ||
role_code = Column(String(256), ForeignKey('role.code'), name='role_code', nullable=False) | ||
|
||
# Many-to-one relationship with Role | ||
role = relationship("Role") | ||
|
||
# One-to-one relationship with ShiftRequestVolunteer using backref | ||
volunteer = relationship("ShiftRequestVolunteer", uselist=False, backref="shift_position", | ||
primaryjoin="ShiftPosition.id == ShiftRequestVolunteer.position_id") |
This file contains 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 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 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 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 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 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 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.