feat:(fb) Add FormService for form management - #66
Conversation
Introduces the FormService class to handle business logic and database operations for forms, including create, read, update, delete, and view count increment. Updates __init__.py to export FormService.
Removed an unnecessary trailing newline in __init__.py and improved logger.info formatting in form_service.py for better readability.
DogukanUrker
left a comment
There was a problem hiding this comment.
hey, i see there’s a plan in the pr body but that’s not really how this should work. the whole point of an implementation plan is to discuss and get approval before writing the code, not after the pr is already open. otherwise it’s just documentation, not a plan we can actually act on.
for future prs, please create the implementation plan separately, get approval from me or berat first, then start coding. i’ll review this one today, if it needs major changes we might be better off starting fresh with the proper flow.
btw i noticed you used claude for the plan which is cool. curious though, which model did you use and where? (cursor, claude code, claude desktop, etc.?)
|
I used Claude Sonnet 4.5 that Antigravity provides. About the workflow, initially my intention was to follow it (create a implementation plan, get approval and continue with coding) but when I asked help from Claude about the task it just did everything without a implementation plan, when I asked for one it said that it did not create one since the task seemed simple and an implementation plan was not required. So I examined the code myself and decided it was ok to send you the code and documentation. In any case I will folow the proper workflow for future prs |
|
ahh got it. so antigravity actually has a “plan mode” you can select from the chat (there’s fast mode and plan mode). for implementation plans, try using plan mode and start your prompt with something like “create an implementation plan for…” before diving into the task. ai models tend to be eager to complete everything from start to finish. that’s just how they’re built. we need to guide them with proper prompts to prevent that. but honestly, the fact that you reviewed the code yourself and made the judgment call to send it is really solid, that’s exactly the kind of critical thinking we need for software development. also heads up,antigravity gives you claude opus 4.5 for free, try using that next time. it’s currently the best model for coding tasks. i want to set up a more detailed meeting soon about ai usage. i’ll walk through how to get the results we want more easily and efficiently. haven’t reviewed the pr yet so can’t speak on the code itself, but appreciate the proactive approach |
DogukanUrker
left a comment
There was a problem hiding this comment.
lgtm! the code follows the existing patterns from submission_service well and the implementation is solid.
there are a couple of small things we can address later:
_to_object_idreturns unknown types unchanged instead of raising an error (same pattern exists in submission_service though)update_formusesexclude_none=Truewhich prevents intentionally clearing fields likestart_dateordeadline- might want to change to justexclude_unset=True
nothing blocking, we can revisit these in a follow-up if needed.
Raise TypeError if obj_id is not ObjectId or str in _to_object_id, and update form update logic to include fields with None values by removing exclude_none from model_dump.
Simplified the TypeError exception message in the _ensure_object_id method by moving it to a single line for improved readability.
I asked Claude for help and this is what it came up with.
Implementation Details
Summary
Created a comprehensive service layer for form CRUD operations in
form_service.py. The service follows the existing project patterns and conventions, mirroring the structure ofsubmission_service.py.Implemented Methods
FormServiceClassThe service layer includes the following methods:
Core CRUD Operations
create_form(form_data: FormCreate) -> FormInDBget_form_by_id(form_id: PyObjectId) -> FormInDB | Noneget_all_forms(skip: int = 0, limit: int = 10, active_only: bool = False) -> tuple[list[FormInDB], int]active_onlyfilter to show only active formsupdate_form(form_id: PyObjectId, form_data: FormUpdate) -> FormInDB | Noneupdated_attimestampdelete_form(form_id: PyObjectId) -> boolUtility Methods
increment_view_count(form_id: PyObjectId) -> boolHelper Methods
_to_object_id(obj_id: PyObjectId) -> ObjectId_document_to_form(doc: dict | None) -> FormInDB | NoneKey Features
submission_service.pyIntegration
The service integrates with:
app/models/form.pyapp/utils/loggerCode Quality
✅ Linting: Passed Ruff checks with no errors
✅ Conventions: Follows Python backend conventions (snake_case, type hints, async/await)
✅ Documentation: Comprehensive docstrings for all methods
✅ Error Handling: Proper exception handling and logging
Usage Example
Related Issue
Closes #49
Checklist