Skip to content

API

CustomUser

Views

list_users(request)

The function list_users retrieves a list of CustomUser objects.

Endpoint
  • Path: /api/v2/users
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
List[CustomUserSchema]

List of CustomUser objects.

Source code in backend/backend/api.py
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
@api.get("/users", response=List[CustomUserSchema])
def list_users(request):
    """
    The function `list_users` retrieves a list of CustomUser objects.

    Endpoint:
        - **Path**: `/api/v2/users`
        - **Method**: `GET`

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

    Returns:
        (List[CustomUserSchema]): List of CustomUser objects.
    """
    qs = CustomUser.objects.all()
    return qs

me(request)

The function me retrieves the CustomUser object of the logged in user.

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

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
CustomUserSchema

The CustomUser object of the logged in user.

Source code in backend/backend/api.py
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
@api.get("/me", response=CustomUserSchema)
def me(request):
    """
    The function `me` retrieves the CustomUser object of the logged in user.

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

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

    Returns:
        (CustomUserSchema): The CustomUser object of the logged in user.
    """
    return request.user

TokenAuth

Source code in backend/backend/api.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class TokenAuth(HttpBearer):
    def authenticate(self, request, token):
        """
        The function `authenticate` authenticates a user.

        Args:
            self ():
            request ():
            token ():

        Returns:
            user (token): Returns a user token.
        """
        try:
            user = default_token_generator.get_user(token)
        except Exception as e:
            raise HttpError(401, f"Invalid token: {str(e)}")
        return user
authenticate(request, token)

The function authenticate authenticates a user.

Parameters:

Name Type Description Default
self
required
request
required
token
required

Returns:

Name Type Description
user token

Returns a user token.

Source code in backend/backend/api.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def authenticate(self, request, token):
    """
    The function `authenticate` authenticates a user.

    Args:
        self ():
        request ():
        token ():

    Returns:
        user (token): Returns a user token.
    """
    try:
        user = default_token_generator.get_user(token)
    except Exception as e:
        raise HttpError(401, f"Invalid token: {str(e)}")
    return user

login_user(request, payload)

The function login_user logs in a user.

Endpoint
  • Path: /api/v2/login
  • Method: POST

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
payload LoginSchema

A username and password.

required

Returns:

Type Description
object

Returns a user object with token.

Source code in backend/backend/api.py
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
@router.post("/login")
def login_user(request, payload: LoginSchema):
    """
    The function `login_user` logs in a user.

    Endpoint:
        - **Path**: `/api/v2/login`
        - **Method**: `POST`

    Args:
        request (HttpRequest): The HTTP request object.
        payload (LoginSchema): A username and password.

    Returns:
        (object): Returns a user object with token.
    """
    username = payload.username
    password = payload.password

    user = authenticate(request, username=username, password=password)
    if user:
        login(request, user)

        # Retrieve or create a token for the authenticated user
        token = default_token_generator.make_token(user)

        return {
            "token": token,
            "firstname": user.first_name,
            "lastname": user.last_name,
            "email": user.email,
            "isAdmin": user.is_superuser,
            "male": user.male,
            "id": user.id,
            "user_color": user.user_color,
            "groups": [group.id for group in user.groups.all()],
        }
    else:
        raise HttpError(401, "Invalid credentials")

logout_user(request)

The function logout_user logs out.

Endpoint
  • Path: /api/v2/logout
  • Method: POST

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
str

Returns detail: Logout successful if successful.

Source code in backend/backend/api.py
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
@router.post("/logout")
def logout_user(request):
    """
    The function `logout_user` logs out.

    Endpoint:
        - **Path**: `/api/v2/logout`
        - **Method**: `POST`

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

    Returns:
        (str): Returns `detail: Logout successful` if successful.
    """
    # Log the user out
    logout(request)
    return {"detail": "Logout successful"}

Schemas

LoginSchema

Schema to represent a LoginSchema.

Attributes:

Name Type Description
username str

Username string.

password str

Password string.

Source code in backend/backend/api.py
65
66
67
68
69
70
71
72
73
74
75
class LoginSchema(Schema):
    """
    Schema to represent a LoginSchema.

    Attributes:
        username (str): Username string.
        password (str): Password string.
    """

    username: str
    password: str

LoginUserSchema

Schema to represent a LoginUserSchema.

Attributes:

Name Type Description
email str

User email.

profile_picture str

Path to user picutre. Default=None.

male bool

Toggle if male or not.

user_color str

Hex value of a user color.

first_name str

User first name.

last_name str

User last name.

fullname str

Full name of user.

is_superuser bool

Toggle if user is superuser.

is_staff bool

Toggle if user is staff.

is_active bool

Toggle if user is active.

groups List[int]

List of group ids user belongs to.

Source code in backend/backend/api.py
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
class LoginUserSchema(Schema):
    """
    Schema to represent a LoginUserSchema.

    Attributes:
        email (str): User email.
        profile_picture (str): Path to user picutre. Default=None.
        male (bool): Toggle if male or not.
        user_color (str): Hex value of a user color.
        first_name (str): User first name.
        last_name (str): User last name.
        fullname (str): Full name of user.
        is_superuser (bool): Toggle if user is superuser.
        is_staff (bool): Toggle if user is staff.
        is_active (bool): Toggle if user is active.
        groups (List[int]): List of group ids user belongs to.
    """

    email: str
    profile_picture: str = None
    male: bool
    user_color: str
    first_name: str
    last_name: str
    fullname: str
    is_superuser: bool
    is_staff: bool
    is_active: bool
    groups: List[int]

CustomUserSchema

Schema to represent a CustomUserSchema.

Attributes:

Name Type Description
id int

ID of the user.

email str

Email of the user.

profile_picture str

Path to the user profile picture. Default=None.

male bool

Toggle if user is male.

user_color str

Hex value of a user color.

first_name str

User first name.

last_name str

User last name.

fullname str

Full name of user.

is_superuser bool

Toggle if user is superuser.

is_staff bool

Toggle if user is staff.

is_active bool

Toggle if user is active.

Source code in backend/backend/api.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class CustomUserSchema(Schema):
    """
    Schema to represent a CustomUserSchema.

    Attributes:
        id (int): ID of the user.
        email (str): Email of the user.
        profile_picture (str): Path to the user profile picture. Default=None.
        male (bool): Toggle if user is male.
        user_color (str): Hex value of a user color.
        first_name (str): User first name.
        last_name (str): User last name.
        fullname (str): Full name of user.
        is_superuser (bool): Toggle if user is superuser.
        is_staff (bool): Toggle if user is staff.
        is_active (bool): Toggle if user is active.
    """

    id: int
    email: str
    profile_picture: str = None
    male: bool
    user_color: str
    first_name: str
    last_name: str
    fullname: str
    is_superuser: bool
    is_staff: bool
    is_active: bool

AreaGroup

Views

create_areagroup(request, payload)

The function create_areagroup creates an AreaGroup object.

Endpoint
  • Path: /api/v2/areagroups
  • Method: POST

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
payload AreaGroupIn

An AreaGroup object to create.

required

Returns:

Type Description
int

The ID of the newly created AreaGroup object.

Source code in backend/backend/api.py
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
@api.post("/areagroups")
def create_areagroup(request, payload: AreaGroupIn):
    """
    The function `create_areagroup` creates an AreaGroup object.

    Endpoint:
        - **Path**: `/api/v2/areagroups`
        - **Method**: `POST`

    Args:
        request (HttpRequest): The HTTP request object.
        payload (AreaGroupIn): An AreaGroup object to create.

    Returns:
        (int): The ID of the newly created AreaGroup object.
    """
    areagroup = AreaGroup.objects.create(**payload.dict())
    return {"id": areagroup.id}

get_areagroup(request, areagroup_id)

The function get_areagroup retrieves an AreaGroup object.

Endpoint
  • Path: /api/v2/areagroups/{areagroup_id}
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
areagroup_id int

ID of the AreaGroup object to retreive.

required

Returns:

Type Description
AreaGroupOut

The AreaGroup object.

Source code in backend/backend/api.py
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
@api.get("/areagroups/{areagroup_id}", response=AreaGroupOut)
def get_areagroup(request, areagroup_id: int):
    """
    The function `get_areagroup` retrieves an AreaGroup object.

    Endpoint:
        - **Path**: `/api/v2/areagroups/{areagroup_id}`
        - **Method**: `GET`

    Args:
        request (HttpRequest): The HTTP request object.
        areagroup_id (int): ID of the AreaGroup object to retreive.

    Returns:
        (AreaGroupOut): The AreaGroup object.
    """
    areagroup = get_object_or_404(AreaGroup, id=areagroup_id)
    return areagroup

list_areagroups(request)

The function list_areagroups retrieves a list of AreaGroup objects.

Endpoint
  • Path: /api/v2/areagroups
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
List[AreaGroupOut]

List of AreaGroup objects.

Source code in backend/backend/api.py
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
@api.get("/areagroups", response=List[AreaGroupOut])
def list_areagroups(request):
    """
    The function `list_areagroups` retrieves a list of AreaGroup objects.

    Endpoint:
        - **Path**: `/api/v2/areagroups`
        - **Method**: `GET`

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

    Returns:
        (List[AreaGroupOut]): List of AreaGroup objects.
    """
    qs = AreaGroup.objects.all()
    return qs

update_areagroup(request, areagroup_id, payload)

The function update_areagroup updates a given AreaGroup object.

Endpoint
  • Path: /api/v2/areagroups/{areagroup_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
areagroup_id int

ID of the AreaGroup object to update.

required
payload AreaGroupIn

AreaGroup object with updates to apply.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
@api.put("/areagroups/{areagroup_id}")
def update_areagroup(request, areagroup_id: int, payload: AreaGroupIn):
    """
    The function `update_areagroup` updates a given AreaGroup object.

    Endpoint:
        - **Path**: `/api/v2/areagroups/{areagroup_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        areagroup_id (int): ID of the AreaGroup object to update.
        payload (AreaGroupIn): AreaGroup object with updates to apply.

    Returns:
        (str): Returns `success` if successful.
    """
    areagroup = get_object_or_404(AreaGroup, id=areagroup_id)
    areagroup.group_name = payload.group_name
    areagroup.group_order = payload.group_order
    areagroup.group_color = payload.group_color
    areagroup.save()
    return {"success": True}

delete_areagroup(request, areagroup_id)

The function delete_areagroup deletes a given AreaGroup object.

Endpoint
  • Path: /api/v2/areagroups/{areagroup_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
areagroup_id int

ID of the AreaGroup object to delete.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
@api.delete("/areagroups/{areagroup_id}")
def delete_areagroup(request, areagroup_id: int):
    """
    The function `delete_areagroup` deletes a given AreaGroup object.

    Endpoint:
        - **Path**: `/api/v2/areagroups/{areagroup_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        areagroup_id (int): ID of the AreaGroup object to delete.

    Returns:
        (str): Returns `success` if successful.
    """
    areagroup = get_object_or_404(AreaGroup, id=areagroup_id)
    areagroup.delete()
    return {"success": True}

Schemas

AreaGroupIn

Schema to represent an AreaGroupIn.

Attributes:

Name Type Description
group_name str

Area group name.

group_order int

Area group order index.

group_color str

Hex value of area group color.

Source code in backend/backend/api.py
140
141
142
143
144
145
146
147
148
149
150
151
152
class AreaGroupIn(Schema):
    """
    Schema to represent an AreaGroupIn.

    Attributes:
        group_name (str): Area group name.
        group_order (int): Area group order index.
        group_color (str): Hex value of area group color.
    """

    group_name: str
    group_order: int
    group_color: str

AreaGroupOut

Schema to represent an AreaGroupOut.

Attributes:

Name Type Description
id int

ID of area group.

group_name str

Area group name.

group_order int

Area group order index.

group_color str

Hex value of area group color.

Source code in backend/backend/api.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
class AreaGroupOut(Schema):
    """
    Schema to represent an AreaGroupOut.

    Attributes:
        id (int): ID of area group.
        group_name (str): Area group name.
        group_order (int): Area group order index.
        group_color (str): Hex value of area group color.
    """

    id: int
    group_name: str
    group_order: int
    group_color: str

Area

Views

create_area(request, payload)

The function create_area creates an Area object.

Endpoint
  • Path: /api/v2/areas
  • Method: POST

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
payload AreaIn

Area Object to create.

required

Returns:

Type Description
int

ID of the newly created Area object.

Source code in backend/backend/api.py
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
@api.post("/areas")
def create_area(request, payload: AreaIn):
    """
    The function `create_area` creates an Area object.

    Endpoint:
        - **Path**: `/api/v2/areas`
        - **Method**: `POST`

    Args:
        request (HttpRequest): The HTTP request object.
        payload (AreaIn): Area Object to create.

    Returns:
        (int): ID of the newly created Area object.
    """
    area = Area.objects.create(**payload.dict())
    return {"id": area.id}

get_area(request, area_id)

The function get_area retrieves an Area object.

Endpoint
  • Path: /api/v2/areas/{area_id}
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
area_id int

ID of the Area object to retreive.

required

Returns:

Type Description
AreaOut

The Area object.

Source code in backend/backend/api.py
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
@api.get("/areas/{area_id}", response=AreaOut)
def get_area(request, area_id: int):
    """
    The function `get_area` retrieves an Area object.

    Endpoint:
        - **Path**: `/api/v2/areas/{area_id}`
        - **Method**: `GET`

    Args:
        request (HttpRequest): The HTTP request object.
        area_id (int): ID of the Area object to retreive.

    Returns:
        (AreaOut): The Area object.
    """
    area = get_object_or_404(Area, id=area_id)
    return area

list_areas(request)

The function list_areas retrieves a list of Area objects.

Endpoint
  • Path: /api/v2/areas
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
List[AreaOut]

List of Area objects.

Source code in backend/backend/api.py
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
@api.get("/areas", response=List[AreaOut])
def list_areas(request):
    """
    The function `list_areas` retrieves a list of Area objects.

    Endpoint:
        - **Path**: `/api/v2/areas`
        - **Method**: `GET`

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

    Returns:
        (List[AreaOut]): List of Area objects.
    """
    qs = Area.objects.all().order_by("group__group_order", "area_name")
    return qs

update_area(request, area_id, payload)

The function update_area updates a given Area object.

Endpoint
  • Path: /api/v2/areas/{area_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
area_id int

ID of the Area object to update.

required
payload AreaIn

Area object with updates to apply.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
@api.put("/areas/{area_id}")
def update_area(request, area_id: int, payload: AreaIn):
    """
    The function `update_area` updates a given Area object.

    Endpoint:
        - **Path**: `/api/v2/areas/{area_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        area_id (int): ID of the Area object to update.
        payload (AreaIn): Area object with updates to apply.

    Returns:
        (str): Returns `success` if successful.
    """
    area = get_object_or_404(Area, id=area_id)
    area.area_name = payload.area_name
    area.area_icon = payload.area_icon
    area.group_id = payload.group_id
    area.save()
    return {"success": True}

delete_area(request, area_id)

The function delete_area deletes a given Area object.

Endpoint
  • Path: /api/v2/areas/{area_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
area_id int

ID of the Area object to delete.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
@api.delete("/areas/{area_id}")
def delete_area(request, area_id: int):
    """
    The function `delete_area` deletes a given Area object.

    Endpoint:
        - **Path**: `/api/v2/areas/{area_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        area_id (int): ID of the Area object to delete.

    Returns:
        (str): Returns `success` if successful.
    """
    area = get_object_or_404(Area, id=area_id)
    area.delete()
    return {"success": True}

Schemas

AreaIn

Schema to represent an AreaIn.

Attributes:

Name Type Description
area_name str

Area name.

area_icon str

Name of area icon.

group_id int

ID of group object area belongs to.

Source code in backend/backend/api.py
172
173
174
175
176
177
178
179
180
181
182
183
184
class AreaIn(Schema):
    """
    Schema to represent an AreaIn.

    Attributes:
        area_name (str): Area name.
        area_icon (str): Name of area icon.
        group_id (int): ID of group object area belongs to.
    """

    area_name: str
    area_icon: str
    group_id: int

AreaOut

Schema to represent an AreaOut.

Attributes:

Name Type Description
id int

ID of an area.

area_name str

Area name.

area_icon str

Name of area icon.

group_id int

ID of group object area belongs to.

group AreaGroupOut

Group object area belongs to.

dirtiness int

Percentage of dirtiness for the area.

dueCount int

Number of chores due for the area.

totalCount int

Total number of chores for the area.

total_dirtiness int

Total dirtiness of the area.

Source code in backend/backend/api.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
class AreaOut(Schema):
    """
    Schema to represent an AreaOut.

    Attributes:
        id (int): ID of an area.
        area_name (str): Area name.
        area_icon (str): Name of area icon.
        group_id (int): ID of group object area belongs to.
        group (AreaGroupOut): Group object area belongs to.
        dirtiness (int): Percentage of dirtiness for the area.
        dueCount (int): Number of chores due for the area.
        totalCount (int): Total number of chores for the area.
        total_dirtiness (int): Total dirtiness of the area.
    """

    id: int
    area_name: str
    area_icon: str
    group_id: int
    group: AreaGroupOut
    dirtiness: int
    dueCount: int
    totalCount: int
    total_dirtiness: int

Month

Views

Schemas

MonthOut

Schema to represent a Month.

Attributes:

Name Type Description
id int

ID of the month.

name str

Name of the month.

Source code in backend/backend/api.py
214
215
216
217
218
219
220
221
222
223
224
class MonthOut(Schema):
    """
    Schema to represent a Month.

    Attributes:
        id (int): ID of the month.
        name (str): Name of the month.
    """

    id: int
    name: str

Chore

Views

create_chore(request, payload)

The function create_chore creates a new Chore object.

Endpoint
  • Path: /api/v2/chores
  • Method: POST

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
payload ChoreIn

Chore object to create.

required

Returns:

Type Description
int

ID of the newly created Chore object.

Source code in backend/backend/api.py
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
@api.post("/chores")
def create_chore(request, payload: ChoreIn):
    """
    The function `create_chore` creates a new Chore object.

    Endpoint:
        - **Path**: `/api/v2/chores`
        - **Method**: `POST`

    Args:
        request (HttpRequest): The HTTP request object.
        payload (ChoreIn): Chore object to create.

    Returns:
        (int): ID of the newly created Chore object.
    """
    # Convert active_months IDs into Month instances
    active_months = Month.objects.filter(id__in=payload.active_months)

    # Create the Chore object
    chore = Chore.objects.create(
        chore_name=payload.chore_name,
        area_id=payload.area_id,
        intervalNumber=payload.intervalNumber,
        unit=payload.unit,
        effort=payload.effort,
    )

    # Set the active_months field
    chore.active_months.set(active_months)

    return {"id": chore.id}

get_chore(request, chore_id)

The function get_chore retrieves an Chore object.

Endpoint
  • Path: /api/v2/chores/{chore_id}
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
chore_id int

ID of the Chore object to retreive.

required

Returns:

Type Description
ChoreOut

The Chore object.

Source code in backend/backend/api.py
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
@api.get("/chores/{chore_id}", response=ChoreOut)
def get_chore(request, chore_id: int):
    """
    The function `get_chore` retrieves an Chore object.

    Endpoint:
        - **Path**: `/api/v2/chores/{chore_id}`
        - **Method**: `GET`

    Args:
        request (HttpRequest): The HTTP request object.
        chore_id (int): ID of the Chore object to retreive.

    Returns:
        (ChoreOut): The Chore object.
    """
    chore = get_object_or_404(Chore, id=chore_id)
    return chore

list_chores(request, inactive=False, timeframe=None, assignee_id=None, area_id=None)

The function list_chores retrieves a list of Chore objects.

Endpoint
  • Path: /api/v2/chores
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
inactive bool

Toggle retreiving inactive chores. Default=False.

False
timeframe int

Days from today to retrieve. Retreives all if None. Default=None.

None
assignee_id int

Filter chores by assigned CustomUser ID. Retreives all if None. Default=None.

None
area_id int

Filter chores by Area ID. Retreives all if None. Default=None.

None

Returns:

Type Description
List[ChoreOut]

List of Chore objects.

Source code in backend/backend/api.py
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
@api.get("/chores", response=List[ChoreOut])
def list_chores(
    request,
    inactive: bool = False,
    timeframe: int = None,
    assignee_id: int = None,
    area_id: int = None,
):
    """
    The function `list_chores` retrieves a list of Chore objects.

    Endpoint:
        - **Path**: `/api/v2/chores`
        - **Method**: `GET`

    Args:
        request (HttpRequest): The HTTP request object.
        inactive (bool): Toggle retreiving inactive chores. Default=False.
        timeframe (int): Days from today to retrieve. Retreives all if None. Default=None.
        assignee_id (int): Filter chores by assigned CustomUser ID. Retreives all if None. Default=None.
        area_id (int): Filter chores by Area ID. Retreives all if None. Default=None.

    Returns:
        (List[ChoreOut]): List of Chore objects.
    """
    qs = Chore.objects.all().order_by(
        "status", "nextDue", "lastCompleted", "effort", "chore_name", "id"
    )
    if not inactive:
        qs = qs.filter(status=0)
    if timeframe is not None:
        today = timezone.now().date()
        target_date = today
        if timeframe > 0:
            target_date = today + timedelta(days=timeframe)
        qs = qs.filter(nextDue__lte=target_date)
    if assignee_id is not None:
        qs = qs.filter(assignee_id=assignee_id)
    if area_id is not None:
        qs = qs.filter(area_id=area_id)
    chore_list = []

    for chore in qs:
        active_months = list(chore.active_months.all())
        active_month_ids = [month.id for month in active_months]
        last_three_query = HistoryItem.objects.filter(chore=chore).order_by(
            "-completed_date"
        )[:3]
        last_three = []
        for item in last_three_query:
            display_name = ""
            if item.completed_by.fullname == " ":
                display_name = item.completed_by.email
            else:
                display_name = item.completed_by.fullname
            last_three_object = LastHistoryItem(
                completed_date=item.completed_date,
                completed_by=display_name,
            )
            last_three.append(last_three_object)
        chore_data = ChoreOut(
            id=chore.id,
            chore_name=chore.chore_name,
            area_id=chore.area_id,
            area=chore.area,  # Assuming AreaOut is a valid representation
            nextDue=chore.nextDue,
            lastCompleted=chore.lastCompleted,
            intervalNumber=chore.intervalNumber,
            unit=chore.unit,
            active_months=active_month_ids,  # Set active_months to the list of IDs
            assignee_id=chore.assignee_id,
            assignee=chore.assignee,
            effort=chore.effort,
            vacationPause=chore.vacationPause,
            expand=chore.expand,
            dirtiness=chore.dirtiness,
            duedays=chore.duedays,
            last_three_history_items=last_three,
            status=chore.status,
        )
        chore_list.append(chore_data)

    return chore_list

update_chore(request, chore_id, payload)

The function update_chore updates a given Chore object.

Endpoint
  • Path: /api/v2/chores/{chore_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
chore_id int

ID of the Chore object to update.

required
payload ChoreIn

Chore object with updates to apply.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
@api.put("/chores/{chore_id}")
def update_chore(request, chore_id: int, payload: ChoreIn):
    """
    The function `update_chore` updates a given Chore object.

    Endpoint:
        - **Path**: `/api/v2/chores/{chore_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        chore_id (int): ID of the Chore object to update.
        payload (ChoreIn): Chore object with updates to apply.

    Returns:
        (str): Returns `success` if successful.
    """
    chore = get_object_or_404(Chore, id=chore_id)
    chore.chore_name = payload.chore_name
    chore.area_id = payload.area_id
    chore.status = payload.status
    chore.nextDue = payload.nextDue
    chore.lastCompleted = payload.lastCompleted
    chore.intervalNumber = payload.intervalNumber
    chore.unit = payload.unit
    chore.active_months.set(payload.active_months)
    chore.assignee_id = payload.assignee_id
    chore.effort = payload.effort
    chore.save()
    return {"success": True}

delete_chore(request, chore_id)

The function delete_chore deletes a given Chore object.

Endpoint
  • Path: /api/v2/chores/{chore_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
chore_id int

ID of the Chore object to delete.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
@api.delete("/chores/{chore_id}")
def delete_chore(request, chore_id: int):
    """
    The function `delete_chore` deletes a given Chore object.

    Endpoint:
        - **Path**: `/api/v2/chores/{chore_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        chore_id (int): ID of the Chore object to delete.

    Returns:
        (str): Returns `success` if successful.
    """
    chore = get_object_or_404(Chore, id=chore_id)
    chore.delete()
    return {"success": True}

toggle_vacation(request)

The function toggle_vacation toggles vacation mode.

Endpoint
  • Path: /api/v2/toggle_vacation
  • Method: POST

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
@api.post("/toggle_vacation")
def toggle_vacation(request):
    """
    The function `toggle_vacation` toggles vacation mode.

    Endpoint:
        - **Path**: `/api/v2/toggle_vacation`
        - **Method**: `POST`

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

    Returns:
        (str): Returns success if successful.
    """
    enabling = False
    option = get_object_or_404(Option, id=1)
    if option.vacation_mode:
        enabling = False
    else:
        enabling = True
    option.vacation_mode = not option.vacation_mode
    option.save()
    if enabling:
        chores = Chore.objects.filter(status=0)
        for chore in chores:
            chore.status = 3
            chore.vacationPause = chore.duedays
            chore.save()
    else:
        chores = Chore.objects.filter(status=3)
        for chore in chores:
            chore.status = 0
            chore.nextDue = date.today() + timedelta(days=chore.vacationPause)
            chore.save()
    return {"success": True}

calculate_duedays(next_due)

The function calculate_duedays calculates the days until due based on a given date.

Parameters:

Name Type Description Default
next_due date

The chore next due date.

required

Returns:

Type Description
int

The number of days until due date.

Source code in backend/backend/api.py
973
974
975
976
977
978
979
980
981
982
983
984
def calculate_duedays(next_due):
    """
    The function `calculate_duedays` calculates the days until due based on a given date.

    Args:
        next_due (date): The chore next due date.

    Returns:
        (int): The number of days until due date.
    """
    delta = next_due - date.today()
    return delta.days

toggle_chore(request, chore_id, payload)

The function toggle_chore toggles wether a Chore is active/inactive.

Endpoint
  • Path: /api/v2/chores/togglechore/{chore_id}
  • Method: PATCH

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
chore_id int

ID of the Chore object to update.

required
payload ToggleActive

ToggleActive schema with status to set for the Chore.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
@api.patch("/chores/togglechore/{chore_id}")
def toggle_chore(request, chore_id: int, payload: TogglActive):
    """
    The function `toggle_chore` toggles wether a Chore is active/inactive.

    Endpoint:
        - **Path**: `/api/v2/chores/togglechore/{chore_id}`
        - **Method**: `PATCH`

    Args:
        request (HttpRequest): The HTTP request object.
        chore_id (int): ID of the Chore object to update.
        payload (ToggleActive): ToggleActive schema with status to set for the Chore.

    Returns:
        (str): Returns `success` if successful.
    """
    chore = get_object_or_404(Chore, id=chore_id)
    chore.status = payload.status
    chore.save()
    return {"success": True}

snooze_chore(request, chore_id, payload)

The function snooze_chore updates a given Chore object's next due date.

Endpoint
  • Path: /api/v2/chores/snoozechore/{chore_id}
  • Method: PATCH

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
chore_id int

ID of the Chore object to update.

required
payload SnoozeChore

SnoozeChore schema with nextDue date to update chore with.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
@api.patch("/chores/snoozechore/{chore_id}")
def snooze_chore(request, chore_id: int, payload: SnoozeChore):
    """
    The function `snooze_chore` updates a given Chore object's next due date.

    Endpoint:
        - **Path**: `/api/v2/chores/snoozechore/{chore_id}`
        - **Method**: `PATCH`

    Args:
        request (HttpRequest): The HTTP request object.
        chore_id (int): ID of the Chore object to update.
        payload (SnoozeChore): SnoozeChore schema with nextDue date to update chore with.

    Returns:
        (str): Returns `success` if successful.
    """
    chore = get_object_or_404(Chore, id=chore_id)
    chore.nextDue = payload.nextDue
    chore.save()
    return {"success": True}

claim_chore(request, chore_id, payload)

The function claim_chore assigns a given Chore object to a user.

Endpoint
  • Path: /api/v2/chores/claimchore/{chore_id}
  • Method: PATCH

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
chore_id int

ID of the Chore object to update.

required
payload ClaimChore

ClaimChore schema with a CustomUser ID to assign to chore.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
@api.patch("/chores/claimchore/{chore_id}")
def claim_chore(request, chore_id: int, payload: ClaimChore):
    """
    The function `claim_chore` assigns a given Chore object to a user.

    Endpoint:
        - **Path**: `/api/v2/chores/claimchore/{chore_id}`
        - **Method**: `PATCH`

    Args:
        request (HttpRequest): The HTTP request object.
        chore_id (int): ID of the Chore object to update.
        payload (ClaimChore): ClaimChore schema with a CustomUser ID to assign to chore.

    Returns:
        (str): Returns `success` if successful.
    """
    chore = get_object_or_404(Chore, id=chore_id)
    chore.assignee_id = payload.assignee_id
    chore.save()
    return {"success": True}

complete_chore(request, chore_id, payload)

The function complete_chore completes a given Chore object.

Endpoint
  • Path: /api/v2/chores/completechore/{chore_id}
  • Method: PATCH

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
chore_id int

ID of the Chore object to update.

required
payload CompleteChore

CompleteChore schema to update Chore with.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
@api.patch("/chores/completechore/{chore_id}")
def complete_chore(request, chore_id: int, payload: CompleteChore):
    """
    The function `complete_chore` completes a given Chore object.

    Endpoint:
        - **Path**: `/api/v2/chores/completechore/{chore_id}`
        - **Method**: `PATCH`

    Args:
        request (HttpRequest): The HTTP request object.
        chore_id (int): ID of the Chore object to update.
        payload (CompleteChore): CompleteChore schema to update Chore with.

    Returns:
        (str): Returns `success` if successful.
    """
    chore = get_object_or_404(Chore, id=chore_id)
    chore.lastCompleted = payload.lastCompleted
    if chore.unit == "day(s)":
        chore.nextDue = payload.lastCompleted + relativedelta(
            days=chore.intervalNumber
        )
    elif chore.unit == "week(s)":
        chore.nextDue = payload.lastCompleted + relativedelta(
            weeks=chore.intervalNumber
        )
    elif chore.unit == "month(s)":
        chore.nextDue = payload.lastCompleted + relativedelta(
            months=chore.intervalNumber
        )
    elif chore.unit == "year(s)":
        chore.nextDue = payload.lastCompleted + relativedelta(
            years=chore.intervalNumber
        )
    chore.assignee = None
    chore.save()
    HistoryItem.objects.create(
        completed_date=payload.lastCompleted,
        completed_by_id=payload.completed_by_id,
        chore=chore,
    )
    return {"success": True}

Schemas

ChoreIn

Schema to represent a Chore.

Attributes:

Name Type Description
chore_name str

Name of the chore. Optional.

area_id int

ID of the area. Optional.

intervalNumber int

The repeat interval of the chore. Optional.

unit str

The repeat unit of the chore. Optional.

active_months List[int]

A list of month ids this chore is active. Optional.

effort int

The effort required for this chore. Optional.

nextDue date

The date chore is next due. Optional.

lastCompleted date

The date chore was last completed. Optional.

assignee_id int

ID of the assigned user. Optional.

status int

ID of the status. Optional.

Source code in backend/backend/api.py
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
class ChoreIn(Schema):
    """
    Schema to represent a Chore.

    Attributes:
        chore_name (str): Name of the chore. Optional.
        area_id (int): ID of the area. Optional.
        intervalNumber (int): The repeat interval of the chore. Optional.
        unit (str): The repeat unit of the chore. Optional.
        active_months (List[int]): A list of month ids this chore is active. Optional.
        effort (int): The effort required for this chore. Optional.
        nextDue (date): The date chore is next due. Optional.
        lastCompleted (date): The date chore was last completed. Optional.
        assignee_id (int): ID of the assigned user. Optional.
        status (int): ID of the status. Optional.
    """

    chore_name: Optional[str]
    area_id: Optional[int]
    intervalNumber: Optional[int]
    unit: Optional[str]
    active_months: Optional[List[int]]
    effort: Optional[int]
    nextDue: Optional[date]
    lastCompleted: Optional[date]
    assignee_id: Optional[int]
    status: Optional[int]

ChoreOut

Schema to represent a Chore.

Attributes:

Name Type Description
id int

ID of the chore.

chore_name str

Name of the chore.

area_id int

ID of an Area object assigned to the chore.

area AreaOut

Area object assigned to the chore.

nextDue date

Date chore is next due.

lastCompleted date

Date chore was last completed.

intervalNumber int

Repeat interval for the chore.

unit str

Repeat unit for the chore.

active_months List[int]

List of Month ids chode is active.

assignee_id int

ID of a user assigned to the chore. Default=None.

effort int

Effort required for the chore.

vacationPause bool

Due days when paused for vacation.

expand bool

Toggle expand menu in UI.

dirtiness int

Percentage dirty of the chore.

duedays int

Days until chore is due.

last_three_history_items List[LastHistoryItem]

List of 3 last history items of the chore.

status int

Status ID of the chore.

Source code in backend/backend/api.py
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
class ChoreOut(Schema):
    """
    Schema to represent a Chore.

    Attributes:
        id (int): ID of the chore.
        chore_name (str): Name of the chore.
        area_id (int): ID of an Area object assigned to the chore.
        area (AreaOut): Area object assigned to the chore.
        nextDue (date): Date chore is next due.
        lastCompleted (date): Date chore was last completed.
        intervalNumber (int): Repeat interval for the chore.
        unit (str): Repeat unit for the chore.
        active_months (List[int]): List of Month ids chode is active.
        assignee_id (int): ID of a user assigned to the chore. Default=None.
        effort (int): Effort required for the chore.
        vacationPause (bool): Due days when paused for vacation.
        expand (bool): Toggle expand menu in UI.
        dirtiness (int): Percentage dirty of the chore.
        duedays (int): Days until chore is due.
        last_three_history_items (List[LastHistoryItem]): List of 3 last history items of the chore.
        status (int): Status ID of the chore.
    """

    id: int
    chore_name: str
    area_id: int
    area: AreaOut
    nextDue: date
    lastCompleted: date
    intervalNumber: int
    unit: str
    active_months: List[int]
    assignee_id: Optional[int]
    assignee: CustomUserSchema = None
    effort: int
    vacationPause: int
    expand: bool
    dirtiness: int
    duedays: int
    last_three_history_items: List[LastHistoryItem]
    status: int

ChoreOutFull

Schema to represent a Chore with full Assigned User and no History.

Attributes:

Name Type Description
id int

ID of the chore.

chore_name str

Name of the chore.

area_id int

ID of an Area object assigned to the chore.

area AreaOut

Area object assigned to the chore.

nextDue date

Date chore is next due.

lastCompleted date

Date chore was last completed.

intervalNumber int

Repeat interval for the chore.

unit str

Repeat unit for the chore.

active_months List[int]

List of Month ids chode is active.

assignee_id int

ID of a user assigned to the chore. Default=None.

assignee CustomUserSchema

CustomUser object of the assigned user. Default=None.

effort int

Effort required for the chore.

vacationPause bool

Due days when paused for vacation.

expand bool

Toggle expand menu in UI.

dirtiness int

Percentage dirty of the chore.

duedays int

Days until chore is due.

status int

Status ID of the chore.

Source code in backend/backend/api.py
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
class ChoreOutFull(Schema):
    """
    Schema to represent a Chore with full Assigned User and no History.

    Attributes:
        id (int): ID of the chore.
        chore_name (str): Name of the chore.
        area_id (int): ID of an Area object assigned to the chore.
        area (AreaOut): Area object assigned to the chore.
        nextDue (date): Date chore is next due.
        lastCompleted (date): Date chore was last completed.
        intervalNumber (int): Repeat interval for the chore.
        unit (str): Repeat unit for the chore.
        active_months (List[int]): List of Month ids chode is active.
        assignee_id (int): ID of a user assigned to the chore. Default=None.
        assignee (CustomUserSchema): CustomUser object of the assigned user. Default=None.
        effort (int): Effort required for the chore.
        vacationPause (bool): Due days when paused for vacation.
        expand (bool): Toggle expand menu in UI.
        dirtiness (int): Percentage dirty of the chore.
        duedays (int): Days until chore is due.
        status (int): Status ID of the chore.
    """

    id: int
    chore_name: str
    area_id: int
    area: AreaOut
    nextDue: date
    lastCompleted: date
    intervalNumber: int
    unit: str
    active_months: List[MonthOut]
    assignee_id: Optional[int]
    assignee: CustomUserSchema = None
    effort: int
    vacationPause: int
    expand: bool
    dirtiness: int
    duedays: int
    status: int

TogglActive

Schema to toggle a Chore status.

Attributes:

Name Type Description
status int

ID of a status object.

Source code in backend/backend/api.py
256
257
258
259
260
261
262
263
264
class TogglActive(Schema):
    """
    Schema to toggle a Chore status.

    Attributes:
        status (int): ID of a status object.
    """

    status: int

CompleteChore

Schema to complete a Chore object.

Attributes:

Name Type Description
lastCompleted date

Date chore was completed.

completed_by_id int

ID of the user who completed chore.

Source code in backend/backend/api.py
267
268
269
270
271
272
273
274
275
276
277
class CompleteChore(Schema):
    """
    Schema to complete a Chore object.

    Attributes:
        lastCompleted (date): Date chore was completed.
        completed_by_id (int): ID of the user who completed chore.
    """

    lastCompleted: date
    completed_by_id: int

SnoozeChore

Schema to snooze a chore object.

Attributes:

Name Type Description
nextDue date

Date to set nextDue to.

Source code in backend/backend/api.py
280
281
282
283
284
285
286
287
288
class SnoozeChore(Schema):
    """
    Schema to snooze a chore object.

    Attributes:
        nextDue (date): Date to set nextDue to.
    """

    nextDue: date

ClaimChore

Schema to claim a Chore.

Attributes:

Name Type Description
assignee_id int

ID of a user to assign to chore. Optional.

Source code in backend/backend/api.py
291
292
293
294
295
296
297
298
299
class ClaimChore(Schema):
    """
    Schema to claim a Chore.

    Attributes:
        assignee_id (int): ID of a user to assign to chore. Optional.
    """

    assignee_id: Optional[int]

HistoryItem

Views

create_historyitem(request, payload)

The function create_historyitem creates a new HistoryItem object.

Endpoint
  • Path: /api/v2/historyitems
  • Method: POST

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
payload HistoryItemIn

HistoryItem object to create.

required

Returns:

Type Description
int

ID of the newly created HistoryItem object.

Source code in backend/backend/api.py
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
@api.post("/historyitems")
def create_historyitem(request, payload: HistoryItemIn):
    """
    The function `create_historyitem` creates a new HistoryItem object.

    Endpoint:
        - **Path**: `/api/v2/historyitems`
        - **Method**: `POST`

    Args:
        request (HttpRequest): The HTTP request object.
        payload (HistoryItemIn): HistoryItem object to create.

    Returns:
        (int): ID of the newly created HistoryItem object.
    """
    completed_by_id = payload.completed_by
    completed_by_object = get_object_or_404(CustomUser, id=completed_by_id)
    historyitem = HistoryItem.objects.create(
        completed_date=payload.completed_date,
        completed_by=completed_by_object,
        chore_id=payload.chore_id,
    )
    return {"id": historyitem.id}

get_historyitem(request, historyitem_id)

The function get_historyitem retrieves an HistoryItem object.

Endpoint
  • Path: /api/v2/historyitems/{historyitem_id}
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
historyitem_id int

ID of the HistoryItem object to retreive.

required

Returns:

Type Description
HistoryItemOut

The HistoryItem object.

Source code in backend/backend/api.py
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
@api.get("/historyitems/{historyitem_id}", response=HistoryItemOut)
def get_historyitem(request, historyitem_id: int):
    """
    The function `get_historyitem` retrieves an HistoryItem object.

    Endpoint:
        - **Path**: `/api/v2/historyitems/{historyitem_id}`
        - **Method**: `GET`

    Args:
        request (HttpRequest): The HTTP request object.
        historyitem_id (int): ID of the HistoryItem object to retreive.

    Returns:
        (HistoryItemOut): The HistoryItem object.
    """
    historyitem = get_object_or_404(HistoryItem, id=historyitem_id)
    return historyitem

list_historyitems(request, page=Query(1), page_size=Query(60))

The function list_historyitems retrieves a list of HistoryItem objects.

Endpoint
  • Path: /api/v2/historyitems
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
page int

The page of the paginated History Items to return. Default=1. Optional.

Query(1)
page_size int

The page size of paginated History Items. Default=60. Optional.

Query(60)

Returns:

Type Description
PaginatedHistoryItems

Paginated List of HistoryItem objects.

Source code in backend/backend/api.py
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
@api.get("/historyitems", response=PaginatedHistoryItems)
def list_historyitems(
    request,
    page: Optional[int] = Query(1),
    page_size: Optional[int] = Query(60),
):
    """
    The function `list_historyitems` retrieves a list of HistoryItem objects.

    Endpoint:
        - **Path**: `/api/v2/historyitems`
        - **Method**: `GET`

    Args:
        request (HttpRequest): The HTTP request object.
        page (int): The page of the paginated History Items to return. Default=1. Optional.
        page_size (int): The page size of paginated History Items. Default=60. Optional.

    Returns:
        (PaginatedHistoryItems): Paginated List of HistoryItem objects.
    """
    qs = HistoryItem.objects.all().order_by("-completed_date", "-id")
    total_pages = 0
    item_list = []
    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
    total_records = len(qs)
    paginated_items = PaginatedHistoryItems(
        items=item_list,
        current_page=page,
        total_pages=total_pages,
        total_records=total_records,
    )
    return paginated_items

update_historyitem(request, historyitem_id, payload)

The function update_historyitem updates a given HistoryItem object.

Endpoint
  • Path: /api/v2/historyitems/{historyitem_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
historyitem_id int

ID of the HistoryItem object to update.

required
payload HistoryItemIn

HistoryItem object with updates to apply.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
@api.put("/historyitems/{historyitem_id}")
def update_historyitem(request, historyitem_id: int, payload: HistoryItemIn):
    """
    The function `update_historyitem` updates a given HistoryItem object.

    Endpoint:
        - **Path**: `/api/v2/historyitems/{historyitem_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        historyitem_id (int): ID of the HistoryItem object to update.
        payload (HistoryItemIn): HistoryItem object with updates to apply.

    Returns:
        (str): Returns `success` if successful.
    """
    historyitem = get_object_or_404(HistoryItem, id=historyitem_id)
    historyitem.completed_date = payload.completed_date
    historyitem.completed_by = payload.completed_by
    historyitem.chore_id = payload.chore_id
    historyitem.save()
    return {"success": True}

delete_historyitem(request, historyitem_id)

The function delete_historyitem deletes a given HistoryItem object.

Endpoint
  • Path: /api/v2/historyitems/{historyitem_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
historyitem_id int

ID of the HistoryItem object to delete.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
@api.delete("/historyitems/{historyitem_id}")
def delete_historyitem(request, historyitem_id: int):
    """
    The function `delete_historyitem` deletes a given HistoryItem object.

    Endpoint:
        - **Path**: `/api/v2/historyitems/{historyitem_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        historyitem_id (int): ID of the HistoryItem object to delete.

    Returns:
        (str): Returns `success` if successful.
    """
    historyitem = get_object_or_404(HistoryItem, id=historyitem_id)
    historyitem.delete()
    return {"success": True}

Schemas

HistoryItemIn

Schema to represent a HistoryItem.

Attributes:

Name Type Description
completed_date date

The date the chore was completed.

completed_by str

A name of the user who completed the chore.

chore_id int

ID of the chore completed.

Source code in backend/backend/api.py
402
403
404
405
406
407
408
409
410
411
412
413
414
class HistoryItemIn(Schema):
    """
    Schema to represent a HistoryItem.

    Attributes:
        completed_date (date): The date the chore was completed.
        completed_by (str): A name of the user who completed the chore.
        chore_id (int): ID of the chore completed.
    """

    completed_date: date
    completed_by: int
    chore_id: int

HistoryItemOut

Schema to represent a HistoryItem.

Attributes:

Name Type Description
id int

ID of the HistoryItem.

completed_date date

The date the chore was completed.

completed_by CustomUserSchema

Object of the user who completed chore.

chore ChoreOutFull

Object of the chore completed.

Source code in backend/backend/api.py
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
class HistoryItemOut(Schema):
    """
    Schema to represent a HistoryItem.

    Attributes:
        id (int): ID of the HistoryItem.
        completed_date (date): The date the chore was completed.
        completed_by (CustomUserSchema): Object of the user who completed chore.
        chore (ChoreOutFull): Object of the chore completed.
    """

    id: int
    completed_date: date
    completed_by: CustomUserSchema
    chore: ChoreOutFull

LastHistoryItem

Schema to represent the last History Item for a chore.

Attributes:

Name Type Description
completed_date date

The date the chore was completed.

completed_by str

A name of the user who completed the chore.

Source code in backend/backend/api.py
302
303
304
305
306
307
308
309
310
311
312
class LastHistoryItem(Schema):
    """
    Schema to represent the last History Item for a chore.

    Attributes:
        completed_date (date): The date the chore was completed.
        completed_by (str): A name of the user who completed the chore.
    """

    completed_date: date
    completed_by: str

PaginatedHistoryItems

Schema to represent a paginated list of HistoryItems.

Attributes:

Name Type Description
items List[HistoryItemOut]

List of HistoryItem objects.

current_page int

Page number of current record set.

total_pages int

Total number of pages.

total_records int

Total numboer of HistoryItems.

Source code in backend/backend/api.py
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
class PaginatedHistoryItems(Schema):
    """
    Schema to represent a paginated list of HistoryItems.

    Attributes:
        items (List[HistoryItemOut]): List of HistoryItem objects.
        current_page (int): Page number of current record set.
        total_pages (int): Total number of pages.
        total_records (int): Total numboer of HistoryItems.
    """

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

Option

Views

get_option(request, option_id)

The function get_option retrieves an Option object.

Endpoint
  • Path: /api/v2/options/{option_id}
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
option_id int

ID of the Option object to retreive.

required

Returns:

Type Description
OptionOut

The Option object.

Source code in backend/backend/api.py
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
@api.get("/options/{option_id}", response=OptionOut)
def get_option(request, option_id: int):
    """
    The function `get_option` retrieves an Option object.

    Endpoint:
        - **Path**: `/api/v2/options/{option_id}`
        - **Method**: `GET`

    Args:
        request (HttpRequest): The HTTP request object.
        option_id (int): ID of the Option object to retreive.

    Returns:
        (OptionOut): The Option object.
    """
    option = get_object_or_404(Option, id=option_id)
    return option

list_options(request)

The function list_options retrieves a list of Option objects.

Endpoint
  • Path: /api/v2/options
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
List[OptionOut]

List of Option objects.

Source code in backend/backend/api.py
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
@api.get("/options", response=List[OptionOut])
def list_options(request):
    """
    The function `list_options` retrieves a list of Option objects.

    Endpoint:
        - **Path**: `/api/v2/options`
        - **Method**: `GET`

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

    Returns:
        (List[OptionOut]): List of Option objects.
    """
    qs = Option.objects.all()
    return qs

update_option(request, option_id, payload)

The function update_option updates a given Option object.

Endpoint
  • Path: /api/v2/options/{option_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
option_id int

ID of the Option object to update.

required
payload OptionIn

Option object with updates to apply.

required

Returns:

Type Description
str

Returns success if successful.

Source code in backend/backend/api.py
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
@api.put("/options/{option_id}")
def update_option(request, option_id: int, payload: OptionIn):
    """
    The function `update_option` updates a given Option object.

    Endpoint:
        - **Path**: `/api/v2/options/{option_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        option_id (int): ID of the Option object to update.
        payload (OptionIn): Option object with updates to apply.

    Returns:
        (str): Returns `success` if successful.
    """
    option = get_object_or_404(Option, id=option_id)
    option.vacation_mode = payload.vacation_mode
    option.med_thresh = payload.med_thresh
    option.high_thresh = payload.high_thresh
    option.save()
    return {"success": True}

Schemas

OptionIn

Schema to represent an Option object.

Attributes:

Name Type Description
vacation_mode bool

Toggle for vacation mode.

med_thresh int

Medium dirtiness threshold.

high_thresh int

High dirtiness threshold.

Source code in backend/backend/api.py
451
452
453
454
455
456
457
458
459
460
461
462
463
class OptionIn(Schema):
    """
    Schema to represent an Option object.

    Attributes:
        vacation_mode (bool): Toggle for vacation mode.
        med_thresh (int): Medium dirtiness threshold.
        high_thresh (int): High dirtiness threshold.
    """

    vacation_mode: bool
    med_thresh: int
    high_thresh: int

OptionOut

Schema to represent an Option object.

Attributes:

Name Type Description
id int

ID of the Option object.

vacation_mode bool

Toggle for vacation mode.

med_thresh int

Medium dirtiness threshold.

high_thresh int

High dirtiness threshold.

Source code in backend/backend/api.py
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
class OptionOut(Schema):
    """
    Schema to represent an Option object.

    Attributes:
        id (int): ID of the Option object.
        vacation_mode (bool): Toggle for vacation mode.
        med_thresh (int): Medium dirtiness threshold.
        high_thresh (int): High dirtiness threshold.
    """

    id: int
    vacation_mode: bool
    med_thresh: int
    high_thresh: int

Version

Views

list_version(request)

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

Endpoint
  • Path: /api/v2/version/list
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Name Type Description
VersionOut

a version object

Source code in backend/backend/api.py
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
@api.get("/version/list", response=VersionOut)
def list_version(request):
    """
    The function `list_version` retrieves the app version number
    from the backend.

    Endpoint:
        - **Path**: `/api/v2/version/list`
        - **Method**: `GET`

    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
32
33
34
35
36
37
38
39
40
41
42
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

Graphs

Views

get_weeklytotals(request, week=0)

The function get_weeklytotals retrieves the weekly totals.

Endpoint
  • Path: /api/v2/weeklytotals
  • Method: GET

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
week int

Flag to indicate if the totals for last week should be retrieved. Default=0.

0

Returns:

Type Description
GraphData

The graph data with labels and datasets.

Source code in backend/backend/api.py
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
582
583
584
585
586
587
588
589
590
591
@api.get("/weeklytotals", response=GraphData)
def get_weeklytotals(request, week: Optional[int] = 0):
    """
    The function `get_weeklytotals` retrieves the weekly totals.

    Endpoint:
        - **Path**: `/api/v2/weeklytotals`
        - **Method**: `GET`

    Args:
        request (HttpRequest): The HTTP request object.
        week (int): Flag to indicate if the totals for last week should be retrieved. Default=0.

    Returns:
        (GraphData): The graph data with labels and datasets.
    """
    labels = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
    today = timezone.now().date()
    days = week * 7
    start_of_week = (
        today - timedelta(days=today.weekday()) - timedelta(days=days)
    )
    end_of_week = start_of_week + timedelta(days=6)

    datasets = []
    users = CustomUser.objects.all()
    for user in users:
        user_name = None
        if user.first_name and user.first_name != "":
            user_name = user.first_name
        else:
            if len(user.email) > 15:
                if "@" in user.email:
                    parts = user.email.split("@")
                    if len(parts[0]) <= 9:
                        user_name = parts[0] + "@"
                    else:
                        user_name = parts[0][:8] + "*@"
                    if len(parts[1]) <= 5:
                        user_name += parts[1]
                    else:
                        user_name += parts[1][:4] + "*"
                else:
                    user_name = user.email[:14] + "*"
            else:
                user_name = user.email
        # Get records for this week or last week
        records_this_week = HistoryItem.objects.filter(
            completed_by=user,
            completed_date__gte=start_of_week,
            completed_date__lt=start_of_week + timedelta(days=7),
        )

        # Aggregate counts by date
        daily_counts = records_this_week.values("completed_date").annotate(
            count=Count("id")
        )

        # Initialize weekly counts with 0s
        weekly_counts = [0] * 7

        # Map counts to the correct day of the week
        for record in daily_counts:
            day_index = (record["completed_date"] - start_of_week).days
            weekly_counts[day_index] = record["count"]

        dataset_obj = DatasetObject(
            backgroundColor=user.user_color,
            data=weekly_counts,
            label=user_name,
        )
        datasets.append(dataset_obj)
    title = (
        start_of_week.strftime("%m/%d") + " to " + end_of_week.strftime("%m/%d")
    )
    graph = GraphData(labels=labels, datasets=datasets, title=title)
    return graph

Schemas

DatasetObject

Schema to represent a graph DataSet object.

Attributes:

Name Type Description
backgroundColor str

Hex value of the graph color. Optional.

data List(int

List of object IDs for the graph.

label str

Label for the gaph dataset.

Source code in backend/backend/api.py
484
485
486
487
488
489
490
491
492
493
494
495
496
class DatasetObject(Schema):
    """
    Schema to represent a graph DataSet object.

    Attributes:
        backgroundColor (str): Hex value of the graph color. Optional.
        data (List(int)): List of object IDs for the graph.
        label (str): Label for the gaph dataset.
    """

    backgroundColor: Optional[str]
    data: Optional[List[int]]
    label: Optional[str]

GraphData

Schema to represent a GraphData object.

Attributes:

Name Type Description
labels List[str]

List of labels for the graph data.

datasets List[DatasetObject]

List of DataSetObject objects.

title str

Title of the graph.

Source code in backend/backend/api.py
500
501
502
503
504
505
506
507
508
509
510
511
512
class GraphData(Schema):
    """
    Schema to represent a GraphData object.

    Attributes:
        labels (List[str]): List of labels for the graph data.
        datasets (List[DatasetObject]): List of DataSetObject objects.
        title (str): Title of the graph.
    """

    labels: List[str]
    datasets: List[DatasetObject]
    title: str