Skip to content

API

Dependencies

Views

me(request)

The function me returns a user.

Endpoint
  • Path: /api/me
  • Method: GET

Parameters:

Name Type Description Default
request
required

Returns:

Type Description
UserSchema

Returns a user.

Source code in backend/backend/api.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
@api.get("/me", response=UserSchema)
def me(request):
    """
    The function `me` returns a user.

    Endpoint:
        - **Path**: `/api/me`
        - **Method**: `GET`

    Args:
        request ():

    Returns:
        (UserSchema): Returns a user.
    """
    return request.user

Schemas

UserSchema

Schema to validate a User

Attributes:

Name Type Description
username str

The user's username.

is_authenticated bool

Wether or not the use is authenticated.

email str

The user's email address.

first_name str

The user's first name.

last_name str

The user's last name.

Source code in backend/backend/api.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class UserSchema(Schema):
    """
    Schema to validate a User

    Attributes:
        username (str): The user's username.
        is_authenticated (bool): Wether or not the use is authenticated.
        email (str): The user's email address.
        first_name (str): The user's first name.
        last_name (str): The user's last name.
    """

    username: str
    is_authenticated: bool
    email: str = None
    first_name: str = None
    last_name: str = None

Version

Views

list_version(request)

The function list_version retrieves the app version number from the backend.

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
VersionOut

a version object

Source code in backend/backend/api.py
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
@api.get("/version/list", response=VersionOut)
def list_version(request):
    """
    The function `list_version` retrieves the app version number
    from the backend.

    Args:
        request (HttpRequest): The HTTP request object.

    Returns:
        (VersionOut): a version object
    """

    try:
        qs = get_object_or_404(Version, id=1)
        return qs
    except Exception as e:
        raise HttpError(500, f"Record retrieval error: {str(e)}")

Schemas

VersionOut

Schema to represent a Version.

Attributes:

Name Type Description
id int

ID integer. Unique.

version_number str

The version of the app.

Source code in backend/backend/api.py
16
17
18
19
20
21
22
23
24
25
26
class VersionOut(Schema):
    """
    Schema to represent a Version.

    Attributes:
        id (int): ID integer. Unique.
        version_number (str): The version of the app.
    """

    id: int
    version_number: str

Aisle

Views

create_aisle(request, payload)

The function create_aisle creates an Aisle.

Endpoint
  • Path: /api/aisles
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload AisleIn

An object using schema of AisleIn.

required

Returns:

Name Type Description
id int

returns the id of the created Aisle.

Source code in backend/backend/api.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
@api.post("/aisles")
def create_aisle(request, payload: AisleIn):
    """
    The function `create_aisle` creates an Aisle.

    Endpoint:
        - **Path**: `/api/aisles`
        - **Method**: `POST`

    Args:
        request ():
        payload (AisleIn): An object using schema of AisleIn.

    Returns:
        id (int): returns the id of the created Aisle.
    """
    aisle = Aisle.objects.create(**payload.dict())
    return {"id": aisle.id}

get_aisle(request, aisle_id)

The function get_aisle returns an Aisle.

Endpoint
  • Path: /api/aisles/{aisle_id}
  • Method: GET

Parameters:

Name Type Description Default
request
required
aisle_id int

An ID of an Aisle.

required

Returns:

Type Description
AisleOut

returns the Aisle object.

Source code in backend/backend/api.py
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
@api.get("/aisles/{aisle_id}", response=AisleOut)
def get_aisle(request, aisle_id: int):
    """
    The function `get_aisle` returns an Aisle.

    Endpoint:
        - **Path**: `/api/aisles/{aisle_id}`
        - **Method**: `GET`

    Args:
        request ():
        aisle_id (int): An ID of an Aisle.

    Returns:
        (AisleOut): returns the Aisle object.
    """
    aisle = get_object_or_404(Aisle, id=aisle_id)
    return aisle

list_aisles(request)

The function list_aisles returns a list of Aisles.

Endpoint
  • Path: /api/aisles
  • Method: GET

Parameters:

Name Type Description Default
request
required

Returns:

Type Description
List[AisleOut]

returns a list of Aisle objects.

Source code in backend/backend/api.py
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
@api.get("/aisles", response=List[AisleOut])
def list_aisles(request):
    """
    The function `list_aisles` returns a list of Aisles.

    Endpoint:
        - **Path**: `/api/aisles`
        - **Method**: `GET`

    Args:
        request ():

    Returns:
        (List[AisleOut]): returns a list of Aisle objects.
    """
    qs = Aisle.objects.all()
    return qs

list_aislesbystore(request, store_id)

The function list_aislesbystore returns a list of Aisles for a matching store ID.

Endpoint
  • Path: /api/aislesbystore/{store_id}
  • Method: GET

Parameters:

Name Type Description Default
request
required
store_id int

An ID of a Store.

required

Returns:

Type Description
List[AisleOut]

Returns a list of Aisles.

Source code in backend/backend/api.py
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
@api.get("/aislesbystore/{store_id}", response=List[AisleOut])
def list_aislesbystore(request, store_id: int):
    """
    The function `list_aislesbystore` returns a list of Aisles for a matching
    store ID.

    Endpoint:
        - **Path**: `/api/aislesbystore/{store_id}`
        - **Method**: `GET`

    Args:
        request ():
        store_id (int): An ID of a Store.

    Returns:
        (List[AisleOut]): Returns a list of Aisles.
    """
    qs = Aisle.objects.all().filter(store__id=store_id).order_by("order")
    return qs

update_aisle(request, aisle_id, payload)

The function update_aisle updates an Aisle

Endpoint
  • Path: /api/aisles/{aisle_id}
  • Method: PUT

Parameters:

Name Type Description Default
request
required
aisle_id int

The ID of an aisle object.

required
payload AisleIn

An Aisle object.

required

Returns:

Name Type Description
success bool

True if successfully updated.

Source code in backend/backend/api.py
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
@api.put("/aisles/{aisle_id}")
def update_aisle(request, aisle_id: int, payload: AisleIn):
    """
    The function `update_aisle` updates an Aisle

    Endpoint:
        - **Path**: `/api/aisles/{aisle_id}`
        - **Method**: `PUT`

    Args:
        request ():
        aisle_id (int): The ID of an aisle object.
        payload (AisleIn): An Aisle object.

    Returns:
        success (bool): True if successfully updated.
    """
    aisle = get_object_or_404(Aisle, id=aisle_id)
    aisle.name = payload.name
    aisle.order = payload.order
    aisle.store_id = payload.store_id
    aisle.save()
    return {"success": True}

delete_aisle(request, aisle_id)

The function delete_aisle deletes a given Aisle.

Endpoint
  • Path: /api/aisles/{aisle_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request
required
aisle_id int

ID of an Aisle to delete.

required

Returns:

Name Type Description
success bool

True if successfully deleted.

Source code in backend/backend/api.py
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
@api.delete("/aisles/{aisle_id}")
def delete_aisle(request, aisle_id: int):
    """
    The function `delete_aisle` deletes a given Aisle.

    Endpoint:
        - **Path**: `/api/aisles/{aisle_id}`
        - **Method**: `DELETE`

    Args:
        request ():
        aisle_id (int): ID of an Aisle to delete.

    Returns:
        success (bool): True if successfully deleted.
    """
    aisle = get_object_or_404(Aisle, id=aisle_id)
    aisle.delete()
    return {"success": True}

Schemas

AisleIn

Schema to validate an Aisle.

Attributes:

Name Type Description
name str

The name of the aisle.

order int

The order of the aisle. Default = 1.

store_id int

The ID of a Store object.

Source code in backend/backend/api.py
72
73
74
75
76
77
78
79
80
81
82
83
84
class AisleIn(Schema):
    """
    Schema to validate an Aisle.

    Attributes:
        name (str): The name of the aisle.
        order (int): The order of the aisle. Default = 1.
        store_id (int): The ID of a Store object.
    """

    name: str
    order: int = 1
    store_id: int

AisleOut

Schema to represent an Aisle.

Attributes:

Name Type Description
id int

ID integer. Unique.

name str

The name of the Aisle.

order int

The order of the Aisle. Default = 1.

store_id int

The ID of the store.

store StoreOut

The Store object.

Source code in backend/backend/api.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class AisleOut(Schema):
    """
    Schema to represent an Aisle.

    Attributes:
        id (int): ID integer. Unique.
        name (str): The name of the Aisle.
        order (int): The order of the Aisle. Default = 1.
        store_id (int): The ID of the store.
        store (StoreOut): The Store object.
    """

    id: int
    name: str
    order: int = 1
    store_id: int
    store: StoreOut

AislesWithItems

Schema to represent an Aisle with ListItems assigned to it.

Attributes:

Name Type Description
id int

ID of the aisle.

name str

The name of the aisle.

order int

The order of the aisle.

store_id int

The id of the store this aisle is in.

listitems List[ListItemOut]

A list of list items in this aisle.

Source code in backend/backend/api.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
class AislesWithItems(Schema):
    """
    Schema to represent an Aisle with ListItems assigned to it.

    Attributes:
        id (int): ID of the aisle.
        name (str): The name of the aisle.
        order (int): The order of the aisle.
        store_id (int): The id of the store this aisle is in.
        listitems (List[ListItemOut]): A list of list items in this aisle.
    """

    id: int
    name: str
    order: int = 1
    store_id: int
    listitems: List[ListItemOut]

Store

Views

create_store(request, payload)

The function create_store creates a Store.

Endpoint
  • Path: /api/stores
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload StoreIn

A Store object to add.

required

Returns:

Name Type Description
id int

The ID of the added Store.

Source code in backend/backend/api.py
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
@api.post("/stores")
def create_store(request, payload: StoreIn):
    """
    The function `create_store` creates a Store.

    Endpoint:
        - **Path**: `/api/stores`
        - **Method**: `POST`

    Args:
        request ():
        payload (StoreIn): A Store object to add.

    Returns:
        id (int): The ID of the added Store.
    """
    store = Store.objects.create(**payload.dict())
    return {"id": store.id}

get_store(request, store_id)

The function get_store returns a Store object for a given ID.

Endpoint
  • Path: /api/stores/{store_id}
  • Method: GET

Parameters:

Name Type Description Default
request
required
store_id int

ID of a Store to retreive.

required

Returns:

Type Description
StoreOut

A Store object.

Source code in backend/backend/api.py
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
@api.get("/stores/{store_id}", response=StoreOut)
def get_store(request, store_id: int):
    """
    The function `get_store` returns a Store object for a given ID.

    Endpoint:
        - **Path**: `/api/stores/{store_id}`
        - **Method**: `GET`

    Args:
        request ():
        store_id (int): ID of a Store to retreive.

    Returns:
        (StoreOut): A Store object.
    """
    store = get_object_or_404(Store, id=store_id)
    return store

list_stores(request)

The function list_stores returns a list of Stores.

Endpoint
  • Path: /api/stores
  • Method: GET

Parameters:

Name Type Description Default
request
required

Returns:

Type Description
List[StoreOut]

A list of Store objects.

Source code in backend/backend/api.py
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
@api.get("/stores", response=List[StoreOut])
def list_stores(request):
    """
    The function `list_stores` returns a list of Stores.

    Endpoint:
        - **Path**: `/api/stores`
        - **Method**: `GET`

    Args:
        request ():

    Returns:
        (List[StoreOut]): A list of Store objects.
    """
    qs = Store.objects.all()
    return qs

update_store(request, store_id, payload)

The function update_store updates a give Store.

Endpoint
  • Path: /api/stores/{store_id}
  • Method: PUT

Parameters:

Name Type Description Default
request
required
store_id int

ID of a Store to update.

required
payload StoreIn

A Store object with updates.

required

Returns:

Name Type Description
success bool

True if successfully updated.

Source code in backend/backend/api.py
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
@api.put("/stores/{store_id}")
def update_store(request, store_id: int, payload: StoreIn):
    """
    The function `update_store` updates a give Store.

    Endpoint:
        - **Path**: `/api/stores/{store_id}`
        - **Method**: `PUT`

    Args:
        request ():
        store_id (int): ID of a Store to update.
        payload (StoreIn): A Store object with updates.

    Returns:
        success (bool): True if successfully updated.
    """
    store = get_object_or_404(Store, id=store_id)
    store.name = payload.name
    store.save()
    return {"success": True}

delete_store(request, store_id)

The function delete_store deletes a given Store.

Endpoint
  • Path: /api/stores/{store_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request
required
store_id int

ID of a Store to delete.

required

Returns:

Name Type Description
success bool

True if successfully deleted.

Source code in backend/backend/api.py
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
@api.delete("/stores/{store_id}")
def delete_store(request, store_id: int):
    """
    The function `delete_store` deletes a given Store.

    Endpoint:
        - **Path**: `/api/stores/{store_id}`
        - **Method**: `DELETE`

    Args:
        request ():
        store_id (int): ID of a Store to delete.

    Returns:
        success (bool): True if successfully deleted.
    """
    store = get_object_or_404(Store, id=store_id)
    store.delete()
    return {"success": True}

Schemas

StoreIn

Schema to validate a Store.

Attributes:

Name Type Description
name str

The name of the store.

Source code in backend/backend/api.py
48
49
50
51
52
53
54
55
56
class StoreIn(Schema):
    """
    Schema to validate a Store.

    Attributes:
        name (str): The name of the store.
    """

    name: str

StoreOut

Schema to represent a Store.

Attributes:

Name Type Description
id int

ID integer. Unique.

name str

The name of the store.

Source code in backend/backend/api.py
59
60
61
62
63
64
65
66
67
68
69
class StoreOut(Schema):
    """
    Schema to represent a Store.

    Attributes:
        id (int): ID integer. Unique.
        name (str): The name of the store.
    """

    id: int
    name: str

Item

Views

create_item(request, payload)

The function create_item creates an Item.

Endpoint
  • Path: /api/items
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload ItemIn

An object using schema of ItemIn.

required

Returns:

Name Type Description
id int

returns the id of the created Item.

Source code in backend/backend/api.py
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
@api.post("/items", response=ItemOut)
def create_item(request, payload: ItemIn):
    """
    The function `create_item` creates an Item.

    Endpoint:
        - **Path**: `/api/items`
        - **Method**: `POST`

    Args:
        request ():
        payload (ItemIn): An object using schema of ItemIn.

    Returns:
        id (int): returns the id of the created Item.
    """
    item = Item.objects.create(**payload.dict())
    return item

get_item(request, item_id)

The function get_item returns an Item.

Endpoint
  • Path: /api/items/{item_id}
  • Method: GET

Parameters:

Name Type Description Default
request
required
item_id int

The ID of an Item.

required

Returns:

Type Description
ItemOut

returns an Item object.

Source code in backend/backend/api.py
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
@api.get("/items/{item_id}", response=ItemOut)
def get_item(request, item_id: int):
    """
    The function `get_item` returns an Item.

    Endpoint:
        - **Path**: `/api/items/{item_id}`
        - **Method**: `GET`

    Args:
        request ():
        item_id (int): The ID of an Item.

    Returns:
        (ItemOut): returns an Item object.
    """
    item = get_object_or_404(Item, id=item_id)
    return item

list_items(request, page=Query(1), page_size=Query(15), full=Query(False))

The function list_items returns a paginated list of Items.

Endpoint
  • Path: /api/items
  • Method: GET

Parameters:

Name Type Description Default
request
required
page int

The page number to return. Optional. Default = 1.

Query(1)
page_size int

Hoe many items per page. Optional. Default = 15.

Query(15)
full bool

Wehter this is a full request or not. Optional. Default = False.

Query(False)

Returns:

Type Description
PaginatedItems

returns a PaginatedItems object.

Source code in backend/backend/api.py
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
@api.get("/items", response=PaginatedItems)
def list_items(
    request,
    page: Optional[int] = Query(1),
    page_size: Optional[int] = Query(15),
    full: Optional[bool] = Query(False),
):
    """
    The function `list_items` returns a paginated list of Items.

    Endpoint:
        - **Path**: `/api/items`
        - **Method**: `GET`

    Args:
        request ():
        page (int): The page number to return. Optional. Default = 1.
        page_size (int): Hoe many items per page. Optional. Default = 15.
        full (bool): Wehter this is a full request or not. Optional. Default = False.

    Returns:
        (PaginatedItems): returns a PaginatedItems object.
    """
    qs = Item.objects.all().order_by("name")
    total_pages = 0
    item_list = []
    if not full:
        if len(qs) > 0:
            paginator = Paginator(qs, page_size)
            page_obj = paginator.page(page)
            item_list = list(page_obj.object_list)
            total_pages = paginator.num_pages
    else:
        item_list = list(qs)
    total_records = len(qs)
    paginated_items = PaginatedItems(
        items=item_list,
        current_page=page,
        total_pages=total_pages,
        total_records=total_records,
    )
    return paginated_items

update_item(request, item_id, payload)

The function update_item updates an Item.

Endpoint
  • Path: /api/items/{item_id}
  • Method: PUT

Parameters:

Name Type Description Default
request
required
item_id int

ID of the item to update.

required
payload ItemIn

An Item object with updates.

required

Returns:

Name Type Description
success bool

True if successfully updated.

Source code in backend/backend/api.py
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
@api.put("/items/{item_id}")
def update_item(request, item_id: int, payload: ItemIn):
    """
    The function `update_item` updates an Item.

    Endpoint:
        - **Path**: `/api/items/{item_id}`
        - **Method**: `PUT`

    Args:
        request ():
        item_id (int): ID of the item to update.
        payload (ItemIn): An Item object with updates.

    Returns:
        success (bool): True if successfully updated.
    """
    item = get_object_or_404(Item, id=item_id)
    item.name = payload.name
    item.matches = payload.matches
    item.save()
    return {"success": True}

delete_item(request, item_id)

The function delete_item deletes a given Item.

Endpoint
  • Path: /api/items/{item_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request
required
item_id int

ID of an Item to delete.

required

Returns:

Name Type Description
success bool

True if successfully deleted.

Source code in backend/backend/api.py
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
@api.delete("/items/{item_id}")
def delete_item(request, item_id: int):
    """
    The function `delete_item` deletes a given Item.

    Endpoint:
        - **Path**: `/api/items/{item_id}`
        - **Method**: `DELETE`

    Args:
        request ():
        item_id (int): ID of an Item to delete.

    Returns:
        success (bool): True if successfully deleted.
    """
    item = get_object_or_404(Item, id=item_id)
    item.delete()
    return {"success": True}

Schemas

ItemIn

Schema to validate an Item.

Attributes:

Name Type Description
name str

The name of the item.

matches str

Names that match this item.

aisle AisleOut

Last aisle used for this item.

Source code in backend/backend/api.py
106
107
108
109
110
111
112
113
114
115
116
117
118
class ItemIn(Schema):
    """
    Schema to validate an Item.

    Attributes:
        name (str): The name of the item.
        matches (str): Names that match this item.
        aisle (AisleOut): Last aisle used for this item.
    """

    name: str
    matches: str = None
    aisle: Optional[AisleOut]

ItemOut

Schema to represent an Item.

Attributes:

Name Type Description
id int

ID integer. Unique.

name str

The name of the item.

matches str

Names that macth this item.

aisle AisleOut

Last aisle used for this item. Optional.

Source code in backend/backend/api.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class ItemOut(Schema):
    """
    Schema to represent an Item.

    Attributes:
        id (int): ID integer. Unique.
        name (str): The name of the item.
        matches (str): Names that macth this item.
        aisle (AisleOut): Last aisle used for this item. Optional.
    """

    id: int
    name: str
    matches: str = None
    aisle: Optional[AisleOut]

PaginatedItems

Schema to represent a paginated list of Items.

Attributes:

Name Type Description
items List[ItemOut]

A paginated list of items.

current_page int

The current page of the list.

total_pages int

The total number of pages of items.

total_records int

The total count of items.

Source code in backend/backend/api.py
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class PaginatedItems(Schema):
    """
    Schema to represent a paginated list of Items.

    Attributes:
        items (List[ItemOut]): A paginated list of items.
        current_page (int): The current page of the list.
        total_pages (int): The total number of pages of items.
        total_records (int): The total count of items.
    """

    items: List[ItemOut]
    current_page: int
    total_pages: int
    total_records: int

ListItem

Views

create_listitem(request, payload)

The function create_listitem creates a ListItem.

Endpoint
  • Path: /api/listitems
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload ListItemIn

An object using schema of ListItemIn.

required

Returns:

Name Type Description
id int

returns the id of the created ListItem.

Source code in backend/backend/api.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
@api.post("/listitems")
def create_listitem(request, payload: ListItemIn):
    """
    The function `create_listitem` creates a ListItem.

    Endpoint:
        - **Path**: `/api/listitems`
        - **Method**: `POST`

    Args:
        request ():
        payload (ListItemIn): An object using schema of ListItemIn.

    Returns:
        id (int): returns the id of the created ListItem.
    """
    existing_item = ListItem.objects.filter(
        shopping_list_id=payload.shopping_list_id, item_id=payload.item_id
    ).first()
    if existing_item is None:
        listitem = ListItem.objects.create(**payload.dict())
        item = Item.objects.get(id=payload.item_id)
        item.aisle_id = payload.aisle_id
        item.save()
        return {"id": listitem.id}
    else:
        existing_item.qty += payload.qty
        existing_item.purchased = False
        existing_item.save()
        return {"id": existing_item.id}

get_listitem(request, listitem_id)

The function get_listitem returns a ListItem

Endpoint
  • Path: /api/listitems/{listitem_id}
  • Method: GET

Parameters:

Name Type Description Default
request
required
listitem_id int

The ID of a ListItem.

required

Returns:

Type Description
ListItemOut

returns a ListItem object.

Source code in backend/backend/api.py
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
@api.get("/listitems/{listitem_id}", response=ListItemOut)
def get_listitem(request, listitem_id: int):
    """
    The function `get_listitem` returns a ListItem

    Endpoint:
        - **Path**: `/api/listitems/{listitem_id}`
        - **Method**: `GET`

    Args:
        request ():
        listitem_id (int): The ID of a ListItem.

    Returns:
        (ListItemOut): returns a ListItem object.
    """
    listitem = get_object_or_404(ListItem, id=listitem_id)
    return listitem

list_listitems(request)

The function list_listitems returns a list of ListItems.

Endpoint
  • Path: /api/listitems
  • Method: GET

Parameters:

Name Type Description Default
request
required

Returns:

Type Description
List[ListItemOut]

Returns a list of ListItem objects.

Source code in backend/backend/api.py
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
@api.get("/listitems", response=List[ListItemOut])
def list_listitems(request):
    """
    The function `list_listitems` returns a list of ListItems.

    Endpoint:
        - **Path**: `/api/listitems`
        - **Method**: `GET`

    Args:
        request ():

    Returns:
        (List[ListItemOut]): Returns a list of ListItem objects.
    """
    qs = ListItem.objects.all()
    return qs

update_listitem(request, listitem_id, payload)

The function update_listitem updates a ListItem.

Endpoint
  • Path: /api/listitems/{listitem_id}
  • Method: PUT

Parameters:

Name Type Description Default
request
required
listitem_id int

The ID of a ListItem to update.

required
payload ListItemIn

A ListItem object with updates.

required

Returns:

Name Type Description
success bool

True if successfully updated.

Source code in backend/backend/api.py
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
@api.put("/listitems/{listitem_id}")
def update_listitem(request, listitem_id: int, payload: ListItemIn):
    """
    The function `update_listitem` updates a ListItem.

    Endpoint:
        - **Path**: `/api/listitems/{listitem_id}`
        - **Method**: `PUT`

    Args:
        request ():
        listitem_id (int): The ID of a ListItem to update.
        payload (ListItemIn): A ListItem object with updates.

    Returns:
        success (bool): True if successfully updated.
    """
    listitem = get_object_or_404(ListItem, id=listitem_id)
    listitem.qty = payload.qty
    listitem.purchased = payload.purchased
    listitem.notes = payload.notes
    listitem.purch_date = payload.purch_date
    listitem.item_id = payload.item_id
    listitem.aisle_id = payload.aisle_id
    listitem.shopping_list_id = payload.shopping_list_id
    listitem.save()
    return {"success": True}

delete_listitem(request, listitem_id)

The function delete_listitem deletes a given ListItem.

Endpoint
  • Path: /api/listitems/{listitem_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request
required
listitem_id int

ID of an ListItem to delete.

required

Returns:

Name Type Description
success bool

True if successfully deleted.

Source code in backend/backend/api.py
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
@api.delete("/listitems/{listitem_id}")
def delete_listitem(request, listitem_id: int):
    """
    The function `delete_listitem` deletes a given ListItem.

    Endpoint:
        - **Path**: `/api/listitems/{listitem_id}`
        - **Method**: `DELETE`

    Args:
        request ():
        listitem_id (int): ID of an ListItem to delete.

    Returns:
        success (bool): True if successfully deleted.
    """
    listitem = get_object_or_404(ListItem, id=listitem_id)
    listitem.delete()
    return {"success": True}

delete_listitems_by_shoppinglist(request, shoppinglist_id)

The function delete_listitems_by_shoppinglist deletes all ListItems for a given ShoppingList ID.

Endpoint
  • Path: /api/listitems/deleteall/{shoppinglist_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request
required
shoppinglist_id int

ID of a ShoppingList.

required

Returns:

Name Type Description
success bool

True if successfully deleted.

Source code in backend/backend/api.py
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
@api.delete("/listitems/deleteall/{shoppinglist_id}")
def delete_listitems_by_shoppinglist(request, shoppinglist_id: int):
    """
    The function `delete_listitems_by_shoppinglist` deletes all ListItems for
    a given ShoppingList ID.

    Endpoint:
        - **Path**: `/api/listitems/deleteall/{shoppinglist_id}`
        - **Method**: `DELETE`

    Args:
        request ():
        shoppinglist_id (int): ID of a ShoppingList.

    Returns:
        success (bool): True if successfully deleted.
    """
    listitems = ListItem.objects.filter(shopping_list_id=shoppinglist_id)
    listitems.delete()
    return {"success": True}

delete_purchased_listitems_by_shoppinglist(request, shoppinglist_id)

The function delete_purchased_listitems_by_shoppinglist deletes all ListItems markded as purchased on a given ShoppingList.

Endpoint
  • Path: /api/listitems/deletepurchased/{shoppinglist_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request
required
shoppinglist_id int

ID of a ShoppingList.

required

Returns:

Name Type Description
success bool

True if successfully deleted.

Source code in backend/backend/api.py
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
@api.delete("/listitems/deletepurchased/{shoppinglist_id}")
def delete_purchased_listitems_by_shoppinglist(request, shoppinglist_id: int):
    """
    The function `delete_purchased_listitems_by_shoppinglist` deletes all ListItems
    markded as purchased on a given ShoppingList.

    Endpoint:
        - **Path**: `/api/listitems/deletepurchased/{shoppinglist_id}`
        - **Method**: `DELETE`

    Args:
        request ():
        shoppinglist_id (int): ID of a ShoppingList.

    Returns:
        success (bool): True if successfully deleted.
    """
    listitems = ListItem.objects.filter(
        shopping_list_id=shoppinglist_id, purchased=True
    )
    listitems.delete()
    return {"success": True}

Schemas

ListItemIn

Schema to validate a ListItem.

Attributes:

Name Type Description
qty int

The quantity of list items. Default = 1.

purchased bool

Wether the list item has been purchsaed. Default = False.

notes str

Notes for the list item. Default = None.

purch_date date

Last aisle used for this item. Default = None.

item_id int

ID of the item.

aisle_id int

ID of the aisle.

shopping_list_id int

ID of the shopping list.

Source code in backend/backend/api.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
class ListItemIn(Schema):
    """
    Schema to validate a ListItem.

    Attributes:
        qty (int): The quantity of list items. Default = 1.
        purchased (bool): Wether the list item has been purchsaed. Default = False.
        notes (str): Notes for the list item. Default = None.
        purch_date (date): Last aisle used for this item. Default = None.
        item_id (int): ID of the item.
        aisle_id (int): ID of the aisle.
        shopping_list_id (int): ID of the shopping list.
    """

    qty: int = 1
    purchased: bool = False
    notes: str = None
    purch_date: date = None
    item_id: int
    aisle_id: int
    shopping_list_id: int

ListItemOut

Schema to represent a ListItem.

Attributes:

Name Type Description
id int

The ID of the list item.

qty int

The quantity of list items. Default = 1.

purchased bool

Wether the list item has been purchsaed. Default = False.

notes str

Notes for the list item. Default = None.

purch_date date

Last aisle used for this item. Default = None.

item_id int

ID of the item.

aisle_id int

ID of the aisle.

shopping_list_id int

ID of the shopping list.

item ItemOut

Object representing the item for the list item.

Source code in backend/backend/api.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
class ListItemOut(Schema):
    """
    Schema to represent a ListItem.

    Attributes:
        id (int): The ID of the list item.
        qty (int): The quantity of list items. Default = 1.
        purchased (bool): Wether the list item has been purchsaed. Default = False.
        notes (str): Notes for the list item. Default = None.
        purch_date (date): Last aisle used for this item. Default = None.
        item_id (int): ID of the item.
        aisle_id (int): ID of the aisle.
        shopping_list_id (int): ID of the shopping list.
        item (ItemOut): Object representing the item for the list item.
    """

    id: int
    qty: int = 1
    purchased: bool = False
    notes: str = None
    purch_date: date = None
    item_id: int
    aisle_id: int
    shopping_list_id: int
    item: ItemOut

Shopping List

Views

create_shoppinglist(request, payload)

The function create_shoppinglist creates a ShoppingList.

Endpoint
  • Path: /api/shoppinglists
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload ShoppingListIn

An object using schema of ShoppingListIn.

required

Returns:

Name Type Description
id int

returns the id of the created ShoppingList.

Source code in backend/backend/api.py
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
@api.post("/shoppinglists")
def create_shoppinglist(request, payload: ShoppingListIn):
    """
    The function `create_shoppinglist` creates a ShoppingList.

    Endpoint:
        - **Path**: `/api/shoppinglists`
        - **Method**: `POST`

    Args:
        request ():
        payload (ShoppingListIn): An object using schema of ShoppingListIn.

    Returns:
        id (int): returns the id of the created ShoppingList.
    """
    shoppinglist = ShoppingList.objects.create(**payload.dict())
    return {"id": shoppinglist.id}

get_shoppinglist(request, shoppinglist_id)

The function get_shoppinglist returns a ShoppingList.

Endpoint
  • Path: /api/shoppinglists/{shoppinglist_id}
  • Method: GET

Parameters:

Name Type Description Default
request
required
shoppinglist_id int

An ID of a ShoppingList.

required

Returns:

Type Description
ShoppingListOut

returns a ShoppingList object.

Source code in backend/backend/api.py
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
@api.get("/shoppinglists/{shoppinglist_id}", response=ShoppingListOut)
def get_shoppinglist(request, shoppinglist_id: int):
    """
    The function `get_shoppinglist` returns a ShoppingList.

    Endpoint:
        - **Path**: `/api/shoppinglists/{shoppinglist_id}`
        - **Method**: `GET`

    Args:
        request ():
        shoppinglist_id (int): An ID of a ShoppingList.

    Returns:
        (ShoppingListOut): returns a ShoppingList object.
    """
    shoppinglist = get_object_or_404(ShoppingList, id=shoppinglist_id)
    return shoppinglist

get_shoppinglistfull(request, shoppinglist_id)

The function get_shoppinglistfull returns a ShoppingList with aisles and items.

Endpoint
  • Path: /api/shoppinglistfull/{shoppinglist_id}
  • Method: GET

Parameters:

Name Type Description Default
request
required
shoppinglist_id int

The ID of a ShoppingList.

required

Returns:

Type Description
ShoppingListFull

returns a ShoppingListFull object.

Source code in backend/backend/api.py
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@api.get("/shoppinglistfull/{shoppinglist_id}", response=ShoppingListFull)
def get_shoppinglistfull(request, shoppinglist_id: int):
    """
    The function `get_shoppinglistfull` returns a ShoppingList with aisles and items.

    Endpoint:
        - **Path**: `/api/shoppinglistfull/{shoppinglist_id}`
        - **Method**: `GET`

    Args:
        request ():
        shoppinglist_id (int): The ID of a ShoppingList.

    Returns:
        (ShoppingListFull): returns a ShoppingListFull object.
    """
    shoppinglist = get_object_or_404(ShoppingList, id=shoppinglist_id)
    store = shoppinglist.store
    aisles = Aisle.objects.filter(
        store=store,
        listitem__shopping_list=shoppinglist,
        listitem__purchased=False,
    ).order_by("order", "name")
    purchasedaisles = Aisle.objects.filter(
        store=store,
        listitem__shopping_list=shoppinglist,
        listitem__purchased=True,
    ).order_by("order", "name")
    aisles_dict = {
        aisle.id: AislesWithItems(
            id=aisle.id,
            name=aisle.name,
            order=aisle.order,
            store_id=store.id,
            listitems=[],
        )
        for aisle in aisles
    }
    purchased_aisles_dict = {
        aisle.id: AislesWithItems(
            id=aisle.id,
            name=aisle.name,
            order=aisle.order,
            store_id=store.id,
            listitems=[],
        )
        for aisle in purchasedaisles
    }
    listitems = ListItem.objects.filter(
        shopping_list=shoppinglist, purchased=False
    ).order_by("purchased", "item__name")
    purchasedlistitems = ListItem.objects.filter(
        shopping_list=shoppinglist, purchased=True
    ).order_by("purchased", "item__name")
    total_purchased_count = ListItem.objects.filter(
        shopping_list=shoppinglist, purchased=True
    ).count()
    total_items_count = (
        ListItem.objects.filter(shopping_list=shoppinglist)
        .order_by("purchased", "item__name")
        .count()
    )

    for listitem in listitems:
        aisles_dict[listitem.aisle.id].listitems.append(
            ListItemOut(
                id=listitem.id,
                qty=listitem.qty,
                purchased=listitem.purchased,
                notes=listitem.notes,
                purch_date=listitem.purch_date,
                item_id=listitem.item.id,
                aisle_id=listitem.aisle_id,
                shopping_list_id=listitem.shopping_list.id,
                item=ItemOut(
                    id=listitem.item.id,
                    name=listitem.item.name,
                    matches=listitem.item.matches,
                ),
            )
        )

    for listitem in purchasedlistitems:
        purchased_aisles_dict[listitem.aisle.id].listitems.append(
            ListItemOut(
                id=listitem.id,
                qty=listitem.qty,
                purchased=listitem.purchased,
                notes=listitem.notes,
                purch_date=listitem.purch_date,
                item_id=listitem.item.id,
                aisle_id=listitem.aisle_id,
                shopping_list_id=listitem.shopping_list.id,
                item=ItemOut(
                    id=listitem.item.id,
                    name=listitem.item.name,
                    matches=listitem.item.matches,
                ),
            )
        )

    response_data = ShoppingListFull(
        id=shoppinglist.id,
        name=shoppinglist.name,
        store_id=store.id,
        store=StoreOut(id=store.id, name=store.name),
        aisles=list(aisles_dict.values()),
        purchased_aisles=list(purchased_aisles_dict.values()),
        totalitems=total_items_count,
        totalpurchased=total_purchased_count,
    )
    return response_data

list_shoppinglists(request)

The function list_shoppinglists returns a list of ShoppingLists.

Endpoint
  • Path: /api/shoppinglists
  • Method: GET

Parameters:

Name Type Description Default
request
required

Returns:

Type Description
List[ShoppingListOut]

Returns a list of ShoppingList objects.

Source code in backend/backend/api.py
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
@api.get("/shoppinglists", response=List[ShoppingListOut])
def list_shoppinglists(request):
    """
    The function `list_shoppinglists` returns a list of ShoppingLists.

    Endpoint:
        - **Path**: `/api/shoppinglists`
        - **Method**: `GET`

    Args:
        request ():

    Returns:
        (List[ShoppingListOut]): Returns a list of ShoppingList objects.
    """
    qs = ShoppingList.objects.all()
    return qs

list_listsbystore(request, store_id)

The function list_listsbystore returns a list of ShoppingLists for a given Store ID.

Endpoint
  • Path: /api/listsbystore/{store_id}
  • Method: GET

Parameters:

Name Type Description Default
request
required
store_id int

The ID of a Store.

required

Returns:

Type Description
List[ShoppingListOut]

Returns a list of ShoppingList objects.

Source code in backend/backend/api.py
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
@api.get("/listsbystore/{store_id}", response=List[ShoppingListOut])
def list_listsbystore(request, store_id: int):
    """
    The function `list_listsbystore` returns a list of ShoppingLists for a given
    Store ID.

    Endpoint:
        - **Path**: `/api/listsbystore/{store_id}`
        - **Method**: `GET`

    Args:
        request ():
        store_id (int): The ID of a Store.

    Returns:
        (List[ShoppingListOut]): Returns a list of ShoppingList objects.
    """
    qs = ShoppingList.objects.all().filter(store__id=store_id)
    return qs

update_shoppinglist(request, shoppinglist_id, payload)

The function update_shoppinglist updates a given ShoppingList.

Endpoint
  • Path: /api/shoppinglists/{shoppinglist_id}
  • Method: PUT

Parameters:

Name Type Description Default
request
required
shoppinglist_id int

ID of the Shoppinglist to update.

required
payload ShoppingListIn

A ShoppingList object with updates.

required

Returns:

Name Type Description
success bpp;

True if successfully updated.

Source code in backend/backend/api.py
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
@api.put("/shoppinglists/{shoppinglist_id}")
def update_shoppinglist(request, shoppinglist_id: int, payload: ShoppingListIn):
    """
    The function `update_shoppinglist` updates a given ShoppingList.

    Endpoint:
        - **Path**: `/api/shoppinglists/{shoppinglist_id}`
        - **Method**: `PUT`

    Args:
        request ():
        shoppinglist_id (int): ID of the Shoppinglist to update.
        payload (ShoppingListIn): A ShoppingList object with updates.

    Returns:
        success (bpp;): True if successfully updated.
    """
    shoppinglist = get_object_or_404(ShoppingList, id=shoppinglist_id)
    shoppinglist.name = payload.name
    shoppinglist.store_id = payload.store_id
    shoppinglist.save()
    return {"success": True}

delete_shoppinglist(request, shoppinglist_id)

The function delete_shoppinglist deletes a given ShoppingList.

Endpoint
  • Path: /api/shoppinglists/{shoppinglist_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request
required
shoppinglist_id int

ID of a ShoppingList to delete.

required

Returns:

Name Type Description
success bool

True if successfully deleted.

Source code in backend/backend/api.py
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
@api.delete("/shoppinglists/{shoppinglist_id}")
def delete_shoppinglist(request, shoppinglist_id: int):
    """
    The function `delete_shoppinglist` deletes a given ShoppingList.

    Endpoint:
        - **Path**: `/api/shoppinglists/{shoppinglist_id}`
        - **Method**: `DELETE`

    Args:
        request ():
        shoppinglist_id (int): ID of a ShoppingList to delete.

    Returns:
        success (bool): True if successfully deleted.
    """
    shoppinglist = get_object_or_404(ShoppingList, id=shoppinglist_id)
    shoppinglist.delete()
    return {"success": True}

Schemas

ShoppingListIn

Schema to validate a ShoppingList.

Attributes:

Name Type Description
name str

The name of the shopping list.

store_id int

The ID of the store for the shopping list.

Source code in backend/backend/api.py
205
206
207
208
209
210
211
212
213
214
215
class ShoppingListIn(Schema):
    """
    Schema to validate a ShoppingList.

    Attributes:
        name (str): The name of the shopping list.
        store_id (int): The ID of the store for the shopping list.
    """

    name: str
    store_id: int

ShoppingListOut

Schema to represent a ShoppingList.

Attributes:

Name Type Description
id int

ID of the shopping list.

name str

The name of the shopping list.

store_id int

The ID of the store for the shopping list.

store StoreOut

The Store object.

Source code in backend/backend/api.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
class ShoppingListOut(Schema):
    """
    Schema to represent a ShoppingList.

    Attributes:
        id (int): ID of the shopping list.
        name (str): The name of the shopping list.
        store_id (int): The ID of the store for the shopping list.
        store (StoreOut): The Store object.
    """

    id: int
    name: str
    store_id: int
    store: StoreOut

ShoppingListFull

Schema to represent a ShoppingList with ListItems assigned to it.

Attributes:

Name Type Description
id int

ID of the shopping list.

name str

The name of the shopping list.

store_id int

The ID of the store for this shopping list.

store StoreOut

The Store object.

aisles List[AislesWithItems]

A list of aisles with listitems assigned.

purchased_aisles List[AislesWithItems]

A list of aisles with listitems marked as purchased.

totalitems int

The total number of items on the shopping list.

totalpurchased int

The total number of items marked purchased on the shopping list.

Source code in backend/backend/api.py
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
class ShoppingListFull(Schema):
    """
    Schema to represent a ShoppingList with ListItems assigned to it.

    Attributes:
        id (int): ID of the shopping list.
        name (str): The name of the shopping list.
        store_id (int): The ID of the store for this shopping list.
        store (StoreOut): The Store object.
        aisles (List[AislesWithItems]): A list of aisles with listitems assigned.
        purchased_aisles (List[AislesWithItems]): A list of aisles with listitems marked as
            purchased.
        totalitems (int): The total number of items on the shopping list.
        totalpurchased (int): The total number of items marked purchased on the shopping list.
    """

    id: int
    name: str
    store_id: int
    store: StoreOut
    aisles: List[AislesWithItems]
    purchased_aisles: List[AislesWithItems]
    totalitems: int
    totalpurchased: int