diff --git a/sigl/domain/service.py b/sigl/domain/service.py index 7e165fa..20907ae 100644 --- a/sigl/domain/service.py +++ b/sigl/domain/service.py @@ -89,6 +89,34 @@ def list_delete(session: Session, id: int): session.commit() +def list_deleteItem(session: Session, listId: int, entryId: int): + """Delete an Entry from a Shopping List.""" + entry = list_entry_by_id(session, listId, entryId) + + session.delete(entry) + session.commit() + + +def list_editItem( + session: Session, + listId: int, + entryId: int, + *, + quantity: Optional[str], + notes: Optional[str], +) -> ListEntry: + """Edit an Entry on a Shopping List.""" + entry = list_entry_by_id(session, listId, entryId) + entry.quantity = quantity + entry.notes = notes + entry.set_modified_at() + + session.add(entry) + session.commit() + + return entry + + def list_stores(session: Session, id: int) -> List[str]: """Get a list of all Stores for the List. @@ -132,18 +160,13 @@ def list_update( return sList -def list_entry_by_id(session: Session, id: int) -> Optional[ListEntry]: +def list_entry_by_id(session: Session, listId: int, entryId: int) -> Optional[ListEntry]: """Load a specific Shopping List Entry.""" - return session.query(ListEntry).filter(ListEntry.id == id).one_or_none() - - -def list_entry_set_crossedOff(session: Session, listId: int, entryId: int, crossedOff: bool) -> ListEntry: - """Set the Crossed-Off state of a List Entry.""" sList = list_by_id(session, listId) if not sList: raise NotFoundError(f'List {listId} not found') - entry = list_entry_by_id(session, entryId) + entry = session.query(ListEntry).filter(ListEntry.id == entryId).one_or_none() if not entry: raise NotFoundError(f'List Entry {entryId} not found') @@ -153,6 +176,13 @@ def list_entry_set_crossedOff(session: Session, listId: int, entryId: int, cross status_code=422, ) + return entry + + +def list_entry_set_crossedOff(session: Session, listId: int, entryId: int, crossedOff: bool) -> ListEntry: + """Set the Crossed-Off state of a List Entry.""" + entry = list_entry_by_id(session, listId, entryId) + entry.crossedOff = crossedOff session.add(entry) session.commit() diff --git a/sigl/templates/lists/detail.html.j2 b/sigl/templates/lists/detail.html.j2 index f35b30f..0f29b9e 100644 --- a/sigl/templates/lists/detail.html.j2 +++ b/sigl/templates/lists/detail.html.j2 @@ -1,31 +1,41 @@ {% extends 'base.html.j2' %} {% block title %}{{ list.name }} | Sigl{% endblock %} {% block header %} -