Skip to content

Commit 0aeaf49

Browse files
committed
addressing comments
1 parent be5e4bf commit 0aeaf49

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

backend/app/schemas/volunteer_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class VolunteerDataResponse(BaseModel):
5555
"""
5656

5757
id: UUID
58-
user_id: UUID
58+
user_id: Optional[UUID]
5959
experience: Optional[str]
6060
references_json: Optional[str]
6161
additional_comments: Optional[str]

backend/app/services/implementations/volunteer_data_service.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ async def create_volunteer_data(
2424
self, volunteer_data: VolunteerDataCreateRequest
2525
) -> VolunteerDataResponse:
2626
try:
27-
# Check if volunteer data already exists for this user
28-
existing_data = (
29-
self.db.query(VolunteerData)
30-
.filter(VolunteerData.user_id == volunteer_data.user_id)
31-
.first()
32-
)
33-
if existing_data:
34-
raise HTTPException(
35-
status_code=409,
36-
detail="Volunteer data already exists for this user"
27+
if volunteer_data.user_id is not None:
28+
existing_data = (
29+
self.db.query(VolunteerData)
30+
.filter(VolunteerData.user_id == volunteer_data.user_id)
31+
.first()
3732
)
33+
if existing_data:
34+
raise HTTPException(
35+
status_code=409,
36+
detail="Volunteer data already exists for this user"
37+
)
3838

3939
# Create new volunteer data entry
4040
db_volunteer_data = VolunteerData(

backend/migrations/versions/e71f29bbfe31_make_user_id_nullable_in_volunteer_data.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
"""
88
from typing import Sequence, Union
9+
from alembic import op
910

1011
# revision identifiers, used by Alembic.
1112
revision: str = 'e71f29bbfe31'
@@ -15,8 +16,16 @@
1516

1617

1718
def upgrade() -> None:
18-
pass
19+
# Make user_id nullable to allow public submissions without user accounts
20+
op.alter_column('volunteer_data', 'user_id', nullable=True)
21+
22+
# Drop the unique constraint since we'll have multiple NULL values
23+
op.drop_constraint('uq_volunteer_data_user_id', 'volunteer_data', type_='unique')
1924

2025

2126
def downgrade() -> None:
22-
pass
27+
# Recreate the unique constraint
28+
op.create_unique_constraint('uq_volunteer_data_user_id', 'volunteer_data', ['user_id'])
29+
30+
# Make user_id non-nullable again
31+
op.alter_column('volunteer_data', 'user_id', nullable=False)

0 commit comments

Comments
 (0)