Skip to content

Feature/event issue #108 ready for review#146

Open
arunPdl02 wants to merge 15 commits into
CSSS:mainfrom
arunPdl02:feature/event
Open

Feature/event issue #108 ready for review#146
arunPdl02 wants to merge 15 commits into
CSSS:mainfrom
arunPdl02:feature/event

Conversation

@arunPdl02
Copy link
Copy Markdown

This PR implements the event feature that allows CRUD operations.

Created database schema using sqlalchemy with proper constraints.

Implement the following APIs:
GET( /event)
GET( /event/)
GET(/event//)
POST (/event)
PATCH (/event/)
DELETE (/event/)

Closes #108

@arunPdl02 arunPdl02 changed the title Feature/event issue #108 draft Feature/event issue #108 ready for review May 17, 2026
Copy link
Copy Markdown
Contributor

@jbriones1 jbriones1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, very clean and understandable code.

For future reference, you can just assume anything that creates, updates, or deletes things from the database requires site admin access. Reads might be harder to understand, so you can ask for those.

Comment on lines +30 to +31
sa.Column('start_date', sa.Date(), nullable=True),
sa.Column('end_date', sa.Date(), nullable=True),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change these to repeat_start/end_date so its more clear what is being stored. Sorry, it wasn't clear in the spec.

Comment thread src/event/models.py
Comment on lines +12 to +13
start_date: datetime.date | None = None
end_date: datetime.date | None = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update these to say repeat_start/end_date.

Comment thread src/event/models.py
Comment on lines +22 to +23
start_date: datetime.date | None = None
end_date: datetime.date | None = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update these to say repeat_start/end_date.

Comment thread src/event/models.py
Copy link
Copy Markdown
Contributor

@jbriones1 jbriones1 May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce the amount of duplicated fields you can use inheritance. Makes it less error-prone to update the exact same field across multiple models.

class EventPublic(BaseModel):
    name: str
    start_time:
   ...

class Event(EventPublic):
    eid: int
   # has all of the fields from EventPublic

Also, I think it's fine to return the eid, so you can remove EventPublic and just return Event.

Comment thread src/event/models.py
Comment on lines +31 to +32
start_date: datetime.date | None = None
end_date: datetime.date | None = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update these to say repeat_start/end_date.

Comment thread src/event/tables.py
"start_date": self.start_date,
"end_date": self.end_date,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer using Pydantic's model_dump() if this isn't used anywhere. If it isn't used just remove it so others don't make their own serialization objects.

Comment thread src/event/urls.py
responses={
404:{"description": "Event doesn't exist."}
},
operation_id="update_event"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a site admin dependency.

Comment thread src/event/urls.py
Comment on lines +120 to +150
final_start_time = body.start_time if body.start_time is not None else db_event.start_time
final_end_time = body.end_time if body.end_time is not None else db_event.end_time

if final_start_time > final_end_time:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="The event start time must be before the end time"
)

if not body.start_date and body.end_date:
if not db_event.start_date:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="The event start date and event end date must be initilized at the same time"
)
if db_event.start_date > body.end_date:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="The event start date must be before the event end date"
)
if body.start_date and not body.end_date:
if not db_event.end_date:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="The event start date and event end date must be initilized at the same time"
)
if body.start_date > db_event.end_date:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="The event start date must be before the event end date"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation should be handled by the model validators you wrote. You can merge the data into a single Pydantic Event object, which should automatically trigger the validator. For example:

db_event = await event.crud.get_event_by_eid(db_session, eid)
...
db_data = Event.model_validate(db_event).model_dump()
patch_data = body.model_dump(exclude_unset=True)
merged_data = {**db_data, **patch_data}
try:
    updated_data = Event(**merged_data) # validators would run here
except ValidationError as e:
    raise HTTPException(...)

Comment thread src/event/models.py
if self.start_time and self.end_time:
if self.start_time > self.end_time:
raise ValueError("The event start time must be before end time")
return self
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You don't have to do this, but maybe you could add a separate validator in case this has a repeat_start_date and repeat_end_date on the object.

Comment thread src/event/urls.py
404:{"description": "Event doesn't exist."}
},
operation_id="delete_event",
# dependecies=[Depends()],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a site admin dependency.

Comment thread src/event/models.py
start_date: datetime.date | None = None
end_date: datetime.date | None = None

class EventPublic(BaseModel):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning the eid is fine here, so you can remove this model and just use Event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Events endpoint

2 participants