-
Notifications
You must be signed in to change notification settings - Fork 0
Furniture CRUD (DEV-45) #15
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
petersenmatthew
wants to merge
12
commits into
main
Choose a base branch
from
feature/DEV-45/furniture-crud
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 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3d5210f
Add CRUD operations for Furniture resource in API (DEV-45)
petersenmatthew 779bdff
Refactor Furniture API endpoints to use service layer for CRUD operat…
petersenmatthew 3df19ae
Merge remote-tracking branch 'origin/main' into feature/DEV-45/furnit…
petersenmatthew a54012c
Reduced characters in some lines to pass linting
petersenmatthew f54bf98
Refactor furniture service methods to accept schema objects instead o…
petersenmatthew d6edf86
Refactor update_furniture function for improved readability (DEV-45)
petersenmatthew 2feafaf
Rename dispatch_id to route_id for Furniture (DEV-45)
kenzysoror a70c8f2
Clean up furniture service helpers (DEV-45)
petersenmatthew 96e9569
Handle furniture write route errors consistently (DEV-45)
petersenmatthew 945a68f
Merge branch 'main' into feature/DEV-45/furniture-crud
petersenmatthew 017b99e
Consolidated imports and exports for both services (DEV-45)
petersenmatthew 1a4c186
Regenerate migration (DEV-45)
kenzysoror 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| """Services package. | ||
|
|
||
| Business logic layer; API routes depend on services, not the reverse. | ||
| """ | ||
|
|
||
| from . import furniture as furniture_service | ||
|
|
||
| __all__ = ["furniture_service"] |
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,58 @@ | ||
| """Furniture service. | ||
|
|
||
| CRUD and business logic for the Furniture resource. | ||
| """ | ||
|
|
||
| from sqlalchemy import select | ||
| from sqlalchemy.ext.asyncio import AsyncSession | ||
|
|
||
| from ..models import Furniture | ||
| from ..schemas import FurnitureCreate, FurnitureUpdate | ||
|
|
||
|
|
||
| async def list_furniture(db: AsyncSession) -> list[Furniture]: | ||
| """Return furniture items ordered by name.""" | ||
| result = await db.execute(select(Furniture).order_by(Furniture.name)) | ||
| return list(result.scalars().all()) | ||
petersenmatthew marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| async def get_furniture(furniture_id: str, db: AsyncSession) -> Furniture | None: | ||
| """Return a furniture item by id, or None if not found.""" | ||
| result = await db.execute(select(Furniture).where(Furniture.id == furniture_id)) | ||
| return result.scalar_one_or_none() | ||
|
|
||
|
|
||
| async def create_furniture(payload: FurnitureCreate, db: AsyncSession) -> Furniture: | ||
| """Create a furniture item. Caller must commit; IntegrityError may be raised.""" | ||
petersenmatthew marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| db_furniture = Furniture(**payload.model_dump()) | ||
| db.add(db_furniture) | ||
| await db.commit() | ||
| await db.refresh(db_furniture) | ||
| return db_furniture | ||
|
|
||
|
|
||
| async def update_furniture( | ||
| furniture_id: str, | ||
| payload: FurnitureUpdate, | ||
| db: AsyncSession, | ||
| ) -> Furniture | None: | ||
| """Update a furniture item by id. Returns None if not found.""" | ||
| furniture = await get_furniture(furniture_id, db) | ||
| if not furniture: | ||
| return None | ||
| update_data = payload.model_dump(exclude_unset=True) | ||
| for key, value in update_data.items(): | ||
| setattr(furniture, key, value) | ||
| await db.commit() | ||
| await db.refresh(furniture) | ||
| return furniture | ||
|
|
||
|
|
||
| async def delete_furniture(furniture_id: str, db: AsyncSession) -> bool: | ||
| """Delete a furniture item by id. Returns True if deleted, False if not found.""" | ||
| furniture = await get_furniture(furniture_id, db) | ||
| if not furniture: | ||
| return False | ||
| await db.delete(furniture) | ||
| await db.commit() | ||
| return True | ||
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.