Skip to content

Commit 5a7573b

Browse files
committed
Update models dependency to v2.1.2 and implement soft delete functionality for items
- Updated the models dependency in requirements.txt to version 2.1.2. - Modified fetch functions in item.py to filter out deleted items. - Added a new soft delete endpoint to mark items as deleted without removing them from the database.
1 parent 2cb938a commit 5a7573b

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

app/api/item.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ def sort_categories(categories: SortItems, user: User = Depends(authenticate)):
222222

223223

224224
@route.get("s")
225-
def fetch(user: User = Depends(authenticate), limit: int = 100, offset: int = 0):
225+
def fetch(user: User = Depends(authenticate)):
226226
items = db.session.query(Item).filter_by(
227-
user_id=user.id).offset(offset).limit(limit).all()
227+
user_id=user.id, deleted=False).all()
228228
return items
229229

230230

231231
@route.get("s/grouped")
232232
def fetch_grouped(user: User = Depends(authenticate)):
233-
items = db.session.query(Item).filter_by(user_id=user.id).all()
233+
items = db.session.query(Item).filter_by(user_id=user.id, deleted=False).all()
234234

235235
groups = {}
236236
for item in items:
@@ -260,6 +260,18 @@ def remove(item_id: int, user: User = Depends(authenticate)):
260260
db.session.commit()
261261

262262

263+
@route.post("/{item_id}/delete", status_code=204)
264+
def soft_delete(item_id: int, user: User = Depends(authenticate)):
265+
item = db.session.query(Item).filter_by(
266+
id=item_id, user_id=user.id).first()
267+
268+
if not item:
269+
raise HTTPException(404, "Item not found.")
270+
271+
item.deleted = True
272+
db.session.commit()
273+
274+
263275
class BulkItemIds(BaseModel):
264276
__root__: List[int]
265277

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ uvicorn[standard]
1919
sentry-sdk
2020
celery[redis]
2121
anthropic
22-
git+https://github.com/Packstack-Tech/models.git@v2.1.1#egg=models
22+
git+https://github.com/Packstack-Tech/models.git@v2.1.2#egg=models

0 commit comments

Comments
 (0)