Skip to content

Commit

Permalink
Rename all /remove/ routes to /delete/ to comply with CRUD format
Browse files Browse the repository at this point in the history
  • Loading branch information
Boomaa23 committed Sep 3, 2024
1 parent 0ed5cdf commit 8944968
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
18 changes: 9 additions & 9 deletions server/src/api_box_routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
The Box API can create, get, update, remove, and list boxes which store inventory items.
The Box API can create, get, update, delete, and list boxes which store inventory items.
Note that inventory "boxes" store item entries, each of which represents a real "container".
Containers are typically bags, but may be boxes (not inventory boxes though) in some cases.
Expand Down Expand Up @@ -113,17 +113,17 @@ def api_box_update():
)


@api_box_blueprint.route('/api/box/remove', methods=['POST'])
@auth.route_requires_auth(auth.Scope.BOX_REMOVE)
def api_box_remove():
@api_box_blueprint.route('/api/box/delete', methods=['POST'])
@auth.route_requires_auth(auth.Scope.BOX_DELETE)
def api_box_delete():
"""
Remove a single inventory box, identified by box ID. ::
Delete a single inventory box, identified by box ID. ::
POST /api/box/remove [<box_id>, <api_key>]
POST /api/box/delete [<box_id>, <api_key>]
Requires authentication scope :py:attr:`auth.Scope.BOX_REMOVE`
Requires authentication scope :py:attr:`auth.Scope.BOX_DELETE`
:return: ``200`` on success with the removed :py:class:`models.Box`,\n
:return: ``200`` on success with the deleted :py:class:`models.Box`,\n
``400`` if box ID was malformed,\n
``400`` if API key was malformed,\n
``401`` if API key was invalid,\n
Expand All @@ -132,7 +132,7 @@ def api_box_remove():
``500`` if more than one box was found,\n
``500`` if any other error while authenticating
"""
return db.remove(entity_type=models.Box)
return db.delete(entity_type=models.Box)


@api_box_blueprint.route('/api/boxes/list', methods=['GET', 'POST'])
Expand Down
20 changes: 10 additions & 10 deletions server/src/api_item_routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
The Item API can create, get, update, remove, and list inventory item(s).
The Item API can create, get, update, delete, and list inventory item(s).
All routes except item retrieval require authentication, which is handled by :py:mod:`auth`.
Idempotent routes use the ``GET`` method while non-idempotent routes use ``POST``.
Expand Down Expand Up @@ -125,7 +125,7 @@ def api_item_update():
* ``jlcpcb_part_number: str``
At least one attribute must be updated, though updating more than one is supported.
Item IDs and creation user/time cannot be updated. Items must be removed and re-created to change these attributes.
Item IDs and creation user/time cannot be updated. Items must be deleted and re-created to change these attributes.
Requires authentication scope :py:attr:`auth.Scope.ITEM_UPDATE`
Expand All @@ -149,17 +149,17 @@ def api_item_update():
)


@api_item_blueprint.route('/api/item/remove', methods=['POST'])
@auth.route_requires_auth(auth.Scope.ITEM_REMOVE)
def api_item_remove():
@api_item_blueprint.route('/api/item/delete', methods=['POST'])
@auth.route_requires_auth(auth.Scope.ITEM_DELETE)
def api_item_delete():
"""
Remove a single inventory item, identified by item ID. ::
Delete a single inventory item, identified by item ID. ::
POST /api/item/remove [<item_id>, <api_key>]
POST /api/item/delete [<item_id>, <api_key>]
Requires authentication scope :py:attr:`auth.Scope.ITEM_REMOVE`
Requires authentication scope :py:attr:`auth.Scope.ITEM_DELETE`
:return: ``200`` on success with the removed :py:class:`models.Item`,\n
:return: ``200`` on success with the deleted :py:class:`models.Item`,\n
``400`` if item ID was malformed,\n
``400`` if API key was malformed,\n
``401`` if API key was invalid,\n
Expand All @@ -168,7 +168,7 @@ def api_item_remove():
``500`` if more than one item was found,\n
``500`` if any other error while authenticating
"""
return db.remove(entity_type=models.Item)
return db.delete(entity_type=models.Item)


@api_item_blueprint.route('/api/items/list', methods=['GET', 'POST'])
Expand Down
8 changes: 4 additions & 4 deletions server/src/api_reservation_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def api_reservation_update():
)


@api_reservation_blueprint.route('/api/reservation/remove', methods=['POST'])
@auth.route_requires_auth(auth.Scope.RESERVATION_REMOVE)
def api_reservation_remove():
@api_reservation_blueprint.route('/api/reservation/delete', methods=['POST'])
@auth.route_requires_auth(auth.Scope.RESERVATION_DELETE)
def api_reservation_delete():
# TODO documentation
return db.remove(entity_type=models.Reservation)
return db.delete(entity_type=models.Reservation)


@api_reservation_blueprint.route('/api/reservations/list', methods=['GET', 'POST'])
Expand Down
8 changes: 4 additions & 4 deletions server/src/api_user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def api_user_update():
)


@api_user_blueprint.route('/api/user/remove', methods=['POST'])
@auth.route_requires_auth(auth.Scope.USER_REMOVE)
def api_user_remove():
@api_user_blueprint.route('/api/user/delete', methods=['POST'])
@auth.route_requires_auth(auth.Scope.USER_DELETE)
def api_user_delete():
# TODO documentation
return db.remove(entity_type=models.User)
return db.delete(entity_type=models.User)
8 changes: 4 additions & 4 deletions server/src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ class Scope(enum.IntFlag):
ITEM_GET = enum.auto()
ITEM_CREATE = enum.auto()
ITEM_UPDATE = enum.auto()
ITEM_REMOVE = enum.auto()
ITEM_DELETE = enum.auto()
ITEMS_LIST = enum.auto()
RESERVATION_GET = enum.auto()
RESERVATION_CREATE = enum.auto()
RESERVATION_UPDATE = enum.auto()
RESERVATION_REMOVE = enum.auto()
RESERVATION_DELETE = enum.auto()
RESERVATIONS_LIST = enum.auto()
USER_GET = enum.auto()
USER_CREATE = enum.auto()
USER_UPDATE = enum.auto()
USER_REMOVE = enum.auto()
USER_DELETE = enum.auto()
BOX_GET = enum.auto()
BOX_CREATE = enum.auto()
BOX_UPDATE = enum.auto()
BOX_REMOVE = enum.auto()
BOX_DELETE = enum.auto()
BOXES_LIST = enum.auto()


Expand Down
2 changes: 1 addition & 1 deletion server/src/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def update(entity_type: Type[models.Model], immutable_props: List[str]) -> Respo
return updated_entity.to_response()


def remove(entity_type: Type[models.Model]) -> Response:
def delete(entity_type: Type[models.Model]) -> Response:
# TODO documentation
form = common.FlaskPOSTForm(flask.request.form)
conn, cursor = common.get_db_connection()
Expand Down
6 changes: 3 additions & 3 deletions server/tst/test_api_box_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def call_route(self, attrs: Dict[str, str]):
return self.client.post('/api/box/update', data=attrs)


class TestBoxRemove(tstutil.TestBase, tstutil.AuthorizedTests, tstutil.IdTests):
scope = auth.Scope.BOX_REMOVE
class TestBoxDelete(tstutil.TestBase, tstutil.AuthorizedTests, tstutil.IdTests):
scope = auth.Scope.BOX_DELETE
entity_type = models.Box

def test_200(self):
Expand All @@ -115,7 +115,7 @@ def test_500_duplicate_id(self):
pass

def call_route(self, attrs: Dict[str, str]):
return self.client.post('/api/box/remove', data=attrs)
return self.client.post('/api/box/delete', data=attrs)


class TestBoxesList(tstutil.TestBase):
Expand Down

0 comments on commit 8944968

Please sign in to comment.