-
Notifications
You must be signed in to change notification settings - Fork 0
Incidents Backend Refactor #164
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
aLEGEND21
wants to merge
2
commits into
main
Choose a base branch
from
arnav/incidents-backend-refactor
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,24 @@ | ||
| from enum import Enum | ||
|
|
||
| from pydantic import AwareDatetime, BaseModel | ||
|
|
||
|
|
||
| class IncidentSeverity(Enum): | ||
| COMPLAINT = "complaint" | ||
| WARNING = "warning" | ||
| CITATION = "citation" | ||
|
|
||
|
|
||
| class IncidentData(BaseModel): | ||
| """Data DTO for an incident without id.""" | ||
|
|
||
| location_id: int | ||
| incident_datetime: AwareDatetime | ||
| description: str = "" | ||
| severity: IncidentSeverity | ||
|
|
||
|
|
||
| class IncidentDto(IncidentData): | ||
| """Output DTO for an incident.""" | ||
|
|
||
| id: int |
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,76 @@ | ||
| from fastapi import APIRouter, Depends, status | ||
| from src.core.authentication import authenticate_admin, authenticate_staff_or_admin | ||
| from src.modules.account.account_model import AccountDto | ||
|
|
||
| from .incident_model import IncidentData, IncidentDto | ||
| from .incident_service import IncidentService | ||
|
|
||
| incident_router = APIRouter(prefix="/api/locations", tags=["incidents"]) | ||
|
|
||
|
|
||
| @incident_router.get( | ||
| "/{location_id}/incidents", | ||
| response_model=list[IncidentDto], | ||
| status_code=status.HTTP_200_OK, | ||
| summary="Get all incidents for a location", | ||
| description="Returns all incidents associated with a given location. Staff or admin only.", | ||
| ) | ||
| async def get_incidents_by_location( | ||
| location_id: int, | ||
| incident_service: IncidentService = Depends(), | ||
| _: AccountDto = Depends(authenticate_staff_or_admin), | ||
| ) -> list[IncidentDto]: | ||
| """Get all incidents for a location.""" | ||
| return await incident_service.get_incidents_by_location(location_id) | ||
|
|
||
|
|
||
| @incident_router.post( | ||
| "/{location_id}/incidents", | ||
| response_model=IncidentDto, | ||
| status_code=status.HTTP_201_CREATED, | ||
| summary="Create an incident for a location", | ||
| description="Creates a new incident associated with a location. Admin only.", | ||
| ) | ||
| async def create_incident( | ||
| location_id: int, | ||
| incident_data: IncidentData, | ||
| incident_service: IncidentService = Depends(), | ||
| _: AccountDto = Depends(authenticate_admin), | ||
| ) -> IncidentDto: | ||
| """Create an incident for a location.""" | ||
| return await incident_service.create_incident(location_id, incident_data) | ||
|
|
||
|
|
||
| @incident_router.put( | ||
| "/{location_id}/incidents/{incident_id}", | ||
| response_model=IncidentDto, | ||
| status_code=status.HTTP_200_OK, | ||
| summary="Update an incident", | ||
| description="Updates an existing incident. Admin only.", | ||
| ) | ||
| async def update_incident( | ||
| location_id: int, | ||
| incident_id: int, | ||
| incident_data: IncidentData, | ||
| incident_service: IncidentService = Depends(), | ||
| _: AccountDto = Depends(authenticate_admin), | ||
| ) -> IncidentDto: | ||
| """Update an incident.""" | ||
| return await incident_service.update_incident(incident_id, location_id, incident_data) | ||
aLEGEND21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @incident_router.delete( | ||
| "/{location_id}/incidents/{incident_id}", | ||
| response_model=IncidentDto, | ||
| status_code=status.HTTP_200_OK, | ||
| summary="Delete an incident", | ||
| description="Deletes an incident. Admin only.", | ||
| ) | ||
| async def delete_incident( | ||
| location_id: int, | ||
| incident_id: int, | ||
| incident_service: IncidentService = Depends(), | ||
| _: AccountDto = Depends(authenticate_admin), | ||
| ) -> IncidentDto: | ||
| """Delete an incident.""" | ||
| return await incident_service.delete_incident(incident_id) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.