-
Notifications
You must be signed in to change notification settings - Fork 1
secondary application form backend #64
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """ | ||
| Interface for volunteer data service operations. | ||
| Defines the contract for volunteer data CRUD operations. | ||
| """ | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import List | ||
|
|
||
| from app.schemas.volunteer_data import ( | ||
| VolunteerDataCreateRequest, | ||
| VolunteerDataResponse, | ||
| VolunteerDataUpdateRequest, | ||
| ) | ||
|
|
||
|
|
||
| class IVolunteerDataService(ABC): | ||
| """ | ||
| Interface for volunteer data service operations | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| async def create_volunteer_data(self, volunteer_data: VolunteerDataCreateRequest) -> VolunteerDataResponse: | ||
| """Create new volunteer data entry""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def get_volunteer_data_by_id(self, volunteer_data_id: str) -> VolunteerDataResponse: | ||
| """Get volunteer data by ID""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def get_volunteer_data_by_user_id(self, user_id: str) -> VolunteerDataResponse: | ||
| """Get volunteer data by user ID""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def get_all_volunteer_data(self) -> List[VolunteerDataResponse]: | ||
| """Get all volunteer data entries""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def update_volunteer_data_by_id( | ||
| self, volunteer_data_id: str, volunteer_data_update: VolunteerDataUpdateRequest | ||
| ) -> VolunteerDataResponse: | ||
| """Update volunteer data by ID""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def delete_volunteer_data_by_id(self, volunteer_data_id: str) -> None: | ||
| """Delete volunteer data by ID""" | ||
| pass |
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,21 @@ | ||
| import uuid | ||
| from datetime import datetime | ||
|
|
||
| from sqlalchemy import Column, DateTime, ForeignKey, Text | ||
| from sqlalchemy.dialects.postgresql import UUID | ||
| from sqlalchemy.orm import relationship | ||
|
|
||
| from .Base import Base | ||
|
|
||
|
|
||
| class VolunteerData(Base): | ||
| __tablename__ = "volunteer_data" | ||
|
|
||
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) | ||
| user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True) | ||
| experience = Column(Text, nullable=True) | ||
| references_json = Column(Text, nullable=True) | ||
| additional_comments = Column(Text, nullable=True) | ||
| submitted_at = Column(DateTime, default=datetime.utcnow, nullable=False) | ||
|
|
||
| user = relationship("User", back_populates="volunteer_data") |
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,131 @@ | ||
| from fastapi import APIRouter, Depends, HTTPException | ||
|
|
||
| from app.middleware.auth import has_roles | ||
| from app.schemas.user import UserRole | ||
| from app.schemas.volunteer_data import ( | ||
| VolunteerDataCreateRequest, | ||
| VolunteerDataListResponse, | ||
| VolunteerDataPublicSubmission, | ||
| VolunteerDataResponse, | ||
| VolunteerDataUpdateRequest, | ||
| ) | ||
| from app.services.implementations.volunteer_data_service import VolunteerDataService | ||
| from app.utilities.service_utils import get_volunteer_data_service | ||
|
|
||
| router = APIRouter( | ||
| prefix="/volunteer-data", | ||
| tags=["volunteer-data"], | ||
| ) | ||
|
|
||
|
|
||
| # Public endpoint - anyone can submit volunteer data | ||
| @router.post("/submit", response_model=VolunteerDataResponse) | ||
| async def submit_volunteer_data( | ||
| volunteer_data: VolunteerDataPublicSubmission, | ||
| volunteer_data_service: VolunteerDataService = Depends(get_volunteer_data_service), | ||
| ): | ||
| """Public endpoint for volunteers to submit their application data""" | ||
| try: | ||
| create_request = VolunteerDataCreateRequest( | ||
| user_id=None, | ||
| experience=volunteer_data.experience, | ||
| references_json=volunteer_data.references_json, | ||
| additional_comments=volunteer_data.additional_comments, | ||
| ) | ||
| return await volunteer_data_service.create_volunteer_data(create_request) | ||
| except HTTPException as http_ex: | ||
| raise http_ex | ||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
|
|
||
| # Admin only - create volunteer data | ||
| @router.post("/", response_model=VolunteerDataResponse) | ||
| async def create_volunteer_data( | ||
| volunteer_data: VolunteerDataCreateRequest, | ||
| volunteer_data_service: VolunteerDataService = Depends(get_volunteer_data_service), | ||
| authorized: bool = has_roles([UserRole.ADMIN]), | ||
| ): | ||
| try: | ||
| return await volunteer_data_service.create_volunteer_data(volunteer_data) | ||
| except HTTPException as http_ex: | ||
| raise http_ex | ||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
|
|
||
| # Admin only - get all volunteer data | ||
| @router.get("/", response_model=VolunteerDataListResponse) | ||
| async def get_all_volunteer_data( | ||
| volunteer_data_service: VolunteerDataService = Depends(get_volunteer_data_service), | ||
| authorized: bool = has_roles([UserRole.ADMIN]), | ||
| ): | ||
| try: | ||
| volunteer_data_list = await volunteer_data_service.get_all_volunteer_data() | ||
| return VolunteerDataListResponse(volunteer_data=volunteer_data_list, total=len(volunteer_data_list)) | ||
| except HTTPException as http_ex: | ||
| raise http_ex | ||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
|
|
||
| # Admin only - get volunteer data by ID | ||
| @router.get("/{volunteer_data_id}", response_model=VolunteerDataResponse) | ||
| async def get_volunteer_data( | ||
| volunteer_data_id: str, | ||
| volunteer_data_service: VolunteerDataService = Depends(get_volunteer_data_service), | ||
| authorized: bool = has_roles([UserRole.ADMIN]), | ||
| ): | ||
| try: | ||
| return await volunteer_data_service.get_volunteer_data_by_id(volunteer_data_id) | ||
| except HTTPException as http_ex: | ||
| raise http_ex | ||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
|
|
||
| # Admin only - get volunteer data by user ID | ||
| @router.get("/user/{user_id}", response_model=VolunteerDataResponse) | ||
| async def get_volunteer_data_by_user( | ||
| user_id: str, | ||
| volunteer_data_service: VolunteerDataService = Depends(get_volunteer_data_service), | ||
| authorized: bool = has_roles([UserRole.ADMIN]), | ||
| ): | ||
| try: | ||
| return await volunteer_data_service.get_volunteer_data_by_user_id(user_id) | ||
| except HTTPException as http_ex: | ||
| raise http_ex | ||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
|
|
||
| # Admin only - update volunteer data | ||
| @router.put("/{volunteer_data_id}", response_model=VolunteerDataResponse) | ||
| async def update_volunteer_data( | ||
| volunteer_data_id: str, | ||
| volunteer_data_update: VolunteerDataUpdateRequest, | ||
| volunteer_data_service: VolunteerDataService = Depends(get_volunteer_data_service), | ||
| authorized: bool = has_roles([UserRole.ADMIN]), | ||
| ): | ||
| try: | ||
| return await volunteer_data_service.update_volunteer_data_by_id(volunteer_data_id, volunteer_data_update) | ||
| except HTTPException as http_ex: | ||
| raise http_ex | ||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=str(e)) | ||
|
|
||
|
|
||
| # Admin only - delete volunteer data | ||
| @router.delete("/{volunteer_data_id}") | ||
| async def delete_volunteer_data( | ||
| volunteer_data_id: str, | ||
| volunteer_data_service: VolunteerDataService = Depends(get_volunteer_data_service), | ||
| authorized: bool = has_roles([UserRole.ADMIN]), | ||
| ): | ||
| try: | ||
| await volunteer_data_service.delete_volunteer_data_by_id(volunteer_data_id) | ||
| return {"message": "Volunteer data deleted successfully"} | ||
| except HTTPException as http_ex: | ||
| raise http_ex | ||
| except Exception as 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,72 @@ | ||
| """ | ||
| Pydantic schemas for volunteer data validation and serialization. | ||
| Handles volunteer data CRUD and response models for the API. | ||
| """ | ||
|
|
||
| from datetime import datetime | ||
| from typing import List, Optional | ||
| from uuid import UUID | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field | ||
|
|
||
|
|
||
| class VolunteerDataBase(BaseModel): | ||
| """ | ||
| Base schema for volunteer data model with common attributes. | ||
| """ | ||
|
|
||
| experience: Optional[str] = Field(None, description="Volunteer experience description") | ||
| references_json: Optional[str] = Field(None, description="JSON string containing references") | ||
| additional_comments: Optional[str] = Field(None, description="Additional comments about volunteering") | ||
|
|
||
|
|
||
| class VolunteerDataCreateRequest(VolunteerDataBase): | ||
| """ | ||
| Request schema for creating volunteer data | ||
| """ | ||
|
|
||
| user_id: Optional[UUID] = Field( | ||
| None, description="User ID this volunteer data belongs to (optional for public submissions)" | ||
| ) | ||
|
|
||
|
|
||
| class VolunteerDataPublicSubmission(VolunteerDataBase): | ||
| """ | ||
| Request schema for public volunteer data submissions (no user_id required) | ||
| """ | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class VolunteerDataUpdateRequest(BaseModel): | ||
| """ | ||
| Request schema for updating volunteer data, all fields optional | ||
| """ | ||
|
|
||
| experience: Optional[str] = Field(None, description="Volunteer experience description") | ||
| references_json: Optional[str] = Field(None, description="JSON string containing references") | ||
| additional_comments: Optional[str] = Field(None, description="Additional comments about volunteering") | ||
|
|
||
|
|
||
| class VolunteerDataResponse(BaseModel): | ||
| """ | ||
| Response schema for volunteer data | ||
| """ | ||
|
|
||
| id: UUID | ||
| user_id: Optional[UUID] | ||
| experience: Optional[str] | ||
| references_json: Optional[str] | ||
| additional_comments: Optional[str] | ||
| submitted_at: datetime | ||
|
|
||
| model_config = ConfigDict(from_attributes=True) | ||
|
|
||
|
|
||
| class VolunteerDataListResponse(BaseModel): | ||
| """ | ||
| Response schema for listing volunteer data | ||
| """ | ||
|
|
||
| volunteer_data: List[VolunteerDataResponse] | ||
| total: 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
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.