Skip to content

API

Administration

Dependencies

GlobalAuth

Class to authenticate access to API

Parameters:

Name Type Description Default
HttpBearer
required
Source code in backend/administration/api/dependencies/auth.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class GlobalAuth(HttpBearer):
    """
    Class to authenticate access to API

    Args:
        HttpBearer ():
    """

    def authenticate(self, request, token):
        """
        Method to authenticate to api based on token provided

        Args:
            request (request): the request object
            token (token): the API token to authenticate

        Returns:
            token (api_key): the api key
        """
        api_key = config("VITE_API_KEY", default=None)
        if token == api_key:
            return token
authenticate(request, token)

Method to authenticate to api based on token provided

Parameters:

Name Type Description Default
request request

the request object

required
token token

the API token to authenticate

required

Returns:

Name Type Description
token api_key

the api key

Source code in backend/administration/api/dependencies/auth.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def authenticate(self, request, token):
    """
    Method to authenticate to api based on token provided

    Args:
        request (request): the request object
        token (token): the API token to authenticate

    Returns:
        token (api_key): the api key
    """
    api_key = config("VITE_API_KEY", default=None)
    if token == api_key:
        return token

current_date()

Gets a timezone adjusted date for todays date.

Returns:

Type Description
Date

Timezone adjusted date

Source code in backend/administration/api/dependencies/current_date.py
 7
 8
 9
10
11
12
13
14
15
16
17
def current_date():
    """
    Gets a timezone adjusted date for todays date.

    Returns:
        (Date): Timezone adjusted date
    """
    today = timezone.now()
    tz_timezone = pytz.timezone(os.environ.get("TIMEZONE"))
    today_tz = today.astimezone(tz_timezone).date()
    return today_tz

paginate_list(item_list, page_size, page)

Takes a recordset and returns it paginated. If page_size is 0, return all records.

Parameters:

Name Type Description Default
item_list RecordSet

A record set. Required.

required
page_size int

The number of items per page. Required.

required
page int

The current page. Required.

required

Returns:

Type Description
tuple

(paginated_list (list), total_records (int), total_pages (int))

Source code in backend/administration/api/dependencies/paginate_list.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def paginate_list(item_list, page_size: int, page: int):
    """
    Takes a recordset and returns it paginated. If page_size is 0,
    return all records.

    Args:
        item_list (RecordSet): A record set.  Required.
        page_size (int): The number of items per page. Required.
        page (int): The current page. Required.

    Returns:
        (tuple): (paginated_list (list), total_records (int), total_pages (int))
    """
    # Paginate items
    total_pages = 1
    paginated_list = None
    total_records = 0
    if page_size > 0:
        paginator = None
        paginator = Paginator(item_list, page_size)
        page_obj = paginator.page(page)
        paginated_list = list(page_obj.object_list)
        total_pages = paginator.num_pages
        total_records = len(item_list)
    else:
        paginated_list = list(item_list)
        total_records = len(paginated_list)
    return paginated_list, total_records, total_pages

Views

list_version(request)

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

Endpoint
  • Path: /api/v1/administration/version/list
  • Method: GET
  • Response Model: VersionOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
VersionOut

a version object

Source code in backend/administration/api/views/version.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@version_router.get("/list", response=VersionOut)
def list_version(request):
    """
    The function `list_version` retrieves the app version number
    from the backend.

    Endpoint:
        - **Path**: `/api/v1/administration/version/list`
        - **Method**: `GET`
        - **Response Model**: `VersionOut`

    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, "Record retrieval error")

Schemas

VersionOut

Schema to represent a Version

Attributes:

Name Type Description
id int

The id of the Version. Required.

version_number str

The version number. Required.

Source code in backend/administration/api/schemas/version.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
class VersionOut(Schema):
    """
    Schema to represent a Version

    Attributes:
        id (int): The id of the Version. Required.
        version_number (str): The version number. Required.
    """

    id: int
    version_number: str

Material

Dependencies

Views

create_material(request, payload)

The function create_material creates a Material

Endpoint
  • Path: /api/v1/material/material/create
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload MaterialIn

An object using schema of MaterialIn.

required

Returns:

Name Type Description
id int

returns the id of the created Material

Source code in backend/material/api/views/material.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@material_router.post("/create")
def create_material(request, payload: MaterialIn):
    """
    The function `create_material` creates a Material

    Endpoint:
        - **Path**: `/api/v1/material/material/create`
        - **Method**: `POST`

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

    Returns:
        id (int): returns the id of the created Material
    """

    try:
        material = Material.objects.create(**payload.dict())
        return {"id": material.id}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Material already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record creation error")

create_material_object(request, payload)

The function create_material_object creates a MaterialObject

Endpoint
  • Path: /api/v1/material/material_object/create
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload MaterialObjectIn

An object using schema of MaterialObjectIn.

required

Returns:

Name Type Description
id int

returns the id of the created MaterialObject

Source code in backend/material/api/views/material_object.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@material_object_router.post("/create")
def create_material_object(request, payload: MaterialObjectIn):
    """
    The function `create_material_object` creates a MaterialObject

    Endpoint:
        - **Path**: `/api/v1/material/material_object/create`
        - **Method**: `POST`

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

    Returns:
        id (int): returns the id of the created MaterialObject
    """

    try:
        material_object = MaterialObject.objects.create(**payload.dict())
        return {"id": material_object.id}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "MaterialObject already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record creation error")

create_store(request, payload)

The function create_store creates a store

Endpoint
  • Path: /api/v1/store/create
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload StoreIn

An object using schema of StoreIn.

required

Returns:

Name Type Description
id int

returns the id of the created store

Source code in backend/material/api/views/store.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@store_router.post("/create")
def create_store(request, payload: StoreIn):
    """
    The function `create_store` creates a store

    Endpoint:
        - **Path**: `/api/v1/store/create`
        - **Method**: `POST`

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

    Returns:
        id (int): returns the id of the created store
    """

    try:
        store = Store.objects.create(**payload.dict())
        return {"id": store.id}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Store already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record creation error")

delete_material(request, material_id)

The function delete_material deletes the Material specified by id.

Endpoint
  • Path: /api/v1/material/material/delete/{material_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
material_id int

the id of the Material to delete

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Material with the specified ID does not exist.

Source code in backend/material/api/views/material.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
@material_router.delete("/delete/{material_id}")
def delete_material(request, material_id: int):
    """
    The function `delete_material` deletes the Material specified by id.

    Endpoint:
        - **Path**: `/api/v1/material/material/delete/{material_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        material_id (int): the id of the Material to delete

    Returns:
        success (bool): True

    Raises:
        Http404: If the Material with the specified ID does not exist.
    """

    try:
        material = get_object_or_404(Material, id=material_id)
        material.delete()
        return {"success": True}
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

delete_material_object(request, material_object_id)

The function delete_material_object deletes the MaterialObject specified by id.

Endpoint
  • Path: /api/v1/material/material_object/delete/{material_object_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
material_object_id int

the id of the MaterialObject to delete

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the MaterialObject with the specified ID does not exist.

Source code in backend/material/api/views/material_object.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
@material_object_router.delete("/delete/{material_object_id}")
def delete_material_object(request, material_object_id: int):
    """
    The function `delete_material_object` deletes the MaterialObject specified by id.

    Endpoint:
        - **Path**: `/api/v1/material/material_object/delete/{material_object_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        material_object_id (int): the id of the MaterialObject to delete

    Returns:
        success (bool): True

    Raises:
        Http404: If the MaterialObject with the specified ID does not exist.
    """

    try:
        material_object = get_object_or_404(
            MaterialObject, id=material_object_id
        )
        material_object.delete()
        return {"success": True}
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

delete_store(request, store_id)

The function delete_store deletes the store specified by id.

Endpoint
  • Path: /api/v1/store/delete/{store_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
store_id int

the id of the store to delete

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the store with the specified ID does not exist.

Source code in backend/material/api/views/store.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@store_router.delete("/delete/{store_id}")
def delete_store(request, store_id: int):
    """
    The function `delete_store` deletes the store specified by id.

    Endpoint:
        - **Path**: `/api/v1/store/delete/{store_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        store_id (int): the id of the store to delete

    Returns:
        success (bool): True

    Raises:
        Http404: If the store with the specified ID does not exist.
    """

    try:
        store = get_object_or_404(Store, id=store_id)
        store.delete()
        return {"success": True}
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_material(request, material_id)

The function get_material retrieves the Material by id

Endpoint
  • Path: /api/v1/material/material/get/{material_id}
  • Method: GET
  • Response Model: MaterialOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
material_id int

The id of the Material to retrieve.

required

Returns:

Type Description
MaterialOut

The Material object

Raises:

Type Description
Http404

If the Material with the specified ID does not exist.

Source code in backend/material/api/views/material.py
105
106
107
108
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
@material_router.get(
    "/get/{material_id}",
    response=MaterialOut,
)
def get_material(request, material_id: int):
    """
    The function `get_material` retrieves the Material by id

    Endpoint:
        - **Path**: `/api/v1/material/material/get/{material_id}`
        - **Method**: `GET`
        - **Response Model**: `MaterialOut`

    Args:
        request (HttpRequest): The HTTP request object.
        material_id (int): The id of the Material to retrieve.

    Returns:
        (MaterialOut): The Material object

    Raises:
        Http404: If the Material with the specified ID does not exist.
    """

    try:
        material = get_object_or_404(Material, id=material_id)
        return material
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_material_object(request, material_object_id)

The function get_material_object retrieves the MaterialObject by id

Endpoint
  • Path: /api/v1/material/material_object/get/{material_object_id}
  • Method: GET
  • Response Model: MaterialObjectOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
material_object_id int

The id of the MaterialObject to retrieve.

required

Returns:

Type Description
MaterialObjectOut

The MaterialObject object

Raises:

Type Description
Http404

If the MaterialObject with the specified ID does not exist.

Source code in backend/material/api/views/material_object.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
138
139
140
@material_object_router.get(
    "/get/{material_object_id}",
    response=MaterialObjectOut,
)
def get_material_object(request, material_object_id: int):
    """
    The function `get_material_object` retrieves the MaterialObject by id

    Endpoint:
        - **Path**: `/api/v1/material/material_object/get/{material_object_id}`
        - **Method**: `GET`
        - **Response Model**: `MaterialObjectOut`

    Args:
        request (HttpRequest): The HTTP request object.
        material_object_id (int): The id of the MaterialObject to retrieve.

    Returns:
        (MaterialObjectOut): The MaterialObject object

    Raises:
        Http404: If the MaterialObject with the specified ID does not exist.
    """

    try:
        material_object = get_object_or_404(
            MaterialObject, id=material_object_id
        )
        return material_object
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_material_status(request, material_status_id)

The function get_material_status retrieves the MaterialStatus by id

Endpoint
  • Path: /api/v1/material/material_status/get/{material_status_id}
  • Method: GET
  • Response Model: MaterialStatusOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
material_status_id int

The id of the MaterialStatus to retrieve.

required

Returns:

Type Description
MaterialStatusOut

The MaterialStatus object

Raises:

Type Description
Http404

If the MaterialStatus with the specified ID does not exist.

Source code in backend/material/api/views/material_status.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@material_status_router.get(
    "/get/{material_status_id}",
    response=MaterialStatusOut,
)
def get_material_status(request, material_status_id: int):
    """
    The function `get_material_status` retrieves the MaterialStatus by id

    Endpoint:
        - **Path**: `/api/v1/material/material_status/get/{material_status_id}`
        - **Method**: `GET`
        - **Response Model**: `MaterialStatusOut`

    Args:
        request (HttpRequest): The HTTP request object.
        material_status_id (int): The id of the MaterialStatus to retrieve.

    Returns:
        (MaterialStatusOut): The MaterialStatus object

    Raises:
        Http404: If the MaterialStatus with the specified ID does not exist.
    """

    try:
        material_status = get_object_or_404(
            MaterialStatus, id=material_status_id
        )
        return material_status
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_store(request, store_id)

The function get_store retrieves the store by id

Endpoint
  • Path: /api/v1/store/get/{store_id}
  • Method: GET
  • Response Model: StoreOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
store_id int

The id of the store to retrieve.

required

Returns:

Type Description
StoreOut

The store object

Raises:

Type Description
Http404

If the store with the specified ID does not exist.

Source code in backend/material/api/views/store.py
105
106
107
108
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
@store_router.get(
    "/get/{store_id}",
    response=StoreOut,
)
def get_store(request, store_id: int):
    """
    The function `get_store` retrieves the store by id

    Endpoint:
        - **Path**: `/api/v1/store/get/{store_id}`
        - **Method**: `GET`
        - **Response Model**: `StoreOut`

    Args:
        request (HttpRequest): The HTTP request object.
        store_id (int): The id of the store to retrieve.

    Returns:
        (StoreOut): The store object

    Raises:
        Http404: If the store with the specified ID does not exist.
    """

    try:
        store = get_object_or_404(Store, id=store_id)
        return store
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_wood_species(request, wood_species_id)

The function get_wood_species retrieves the WoodSpecies by id

Endpoint
  • Path: /api/v1/material/wood_species/get/{wood_species_id}
  • Method: GET
  • Response Model: WoodSpeciesOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
wood_species_id int

The id of the WoodSpecies to retrieve.

required

Returns:

Type Description
WoodSpeciesOut

The WoodSpecies object

Raises:

Type Description
Http404

If the WoodSpecies with the specified ID does not exist.

Source code in backend/material/api/views/wood_species.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@wood_species_router.get(
    "/get/{wood_species_id}",
    response=WoodSpeciesOut,
)
def get_wood_species(request, wood_species_id: int):
    """
    The function `get_wood_species` retrieves the WoodSpecies by id

    Endpoint:
        - **Path**: `/api/v1/material/wood_species/get/{wood_species_id}`
        - **Method**: `GET`
        - **Response Model**: `WoodSpeciesOut`

    Args:
        request (HttpRequest): The HTTP request object.
        wood_species_id (int): The id of the WoodSpecies to retrieve.

    Returns:
        (WoodSpeciesOut): The WoodSpecies object

    Raises:
        Http404: If the WoodSpecies with the specified ID does not exist.
    """

    try:
        wood_species = get_object_or_404(WoodSpecies, id=wood_species_id)
        return wood_species
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_materials(request)

The function list_materials retrieves a list of materials, ordered by material_name ascending.

Endpoint
  • Path: /api/v1/material/material/list
  • Method: GET
  • Response Model: MaterialOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
MaterialOut

a list of Material objects

Source code in backend/material/api/views/material.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
@material_router.get("/list", response=List[MaterialOut])
def list_materials(request):
    """
    The function `list_materials` retrieves a list of materials,
    ordered by material_name ascending.

    Endpoint:
        - **Path**: `/api/v1/material/material/list`
        - **Method**: `GET`
        - **Response Model**: `MaterialOut`

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

    Returns:
        (MaterialOut): a list of Material objects
    """

    try:
        qs = Material.objects.all().order_by(
            "material_object__material_object_name"
        )
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_material_objects(request)

The function list_material_objects retrieves a list of material_objects, ordered by material_object_name ascending.

Endpoint
  • Path: /api/v1/material/material_object/list
  • Method: GET
  • Response Model: MaterialObjectOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
MaterialObjectOut

a list of MaterialObject objects

Source code in backend/material/api/views/material_object.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
@material_object_router.get("/list", response=List[MaterialObjectOut])
def list_material_objects(request):
    """
    The function `list_material_objects` retrieves a list of material_objects,
    ordered by material_object_name ascending.

    Endpoint:
        - **Path**: `/api/v1/material/material_object/list`
        - **Method**: `GET`
        - **Response Model**: `MaterialObjectOut`

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

    Returns:
        (MaterialObjectOut): a list of MaterialObject objects
    """

    try:
        qs = MaterialObject.objects.all().order_by("material_object_name")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_material_statuses(request)

The function list_material_statuses retrieves a list of material_statuses, ordered by id ascending.

Endpoint
  • Path: /api/v1/material/material_status/list
  • Method: GET
  • Response Model: MaterialStatusOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
MaterialStatusOut

a list of MaterialStatus objects

Source code in backend/material/api/views/material_status.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
@material_status_router.get("/list", response=List[MaterialStatusOut])
def list_material_statuses(request):
    """
    The function `list_material_statuses` retrieves a list of material_statuses,
    ordered by id ascending.

    Endpoint:
        - **Path**: `/api/v1/material/material_status/list`
        - **Method**: `GET`
        - **Response Model**: `MaterialStatusOut`

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

    Returns:
        (MaterialStatusOut): a list of MaterialStatus objects
    """

    try:
        qs = MaterialStatus.objects.all().order_by("id")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_stores(request)

The function list_stores retrieves a list of storees, ordered by store_name ascending.

Endpoint
  • Path: /api/v1/store/list
  • Method: GET
  • Response Model: StoreOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
StoreOut

a list of store objects

Source code in backend/material/api/views/store.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
@store_router.get("/list", response=List[StoreOut])
def list_stores(request):
    """
    The function `list_stores` retrieves a list of storees,
    ordered by store_name ascending.

    Endpoint:
        - **Path**: `/api/v1/store/list`
        - **Method**: `GET`
        - **Response Model**: `StoreOut`

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

    Returns:
        (StoreOut): a list of store objects
    """

    try:
        qs = Store.objects.all().order_by("store_name")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_wood_species(request)

The function list_wood_species retrieves a list of wood_species, ordered by id ascending.

Endpoint
  • Path: /api/v1/material/wood_species/list
  • Method: GET
  • Response Model: WoodSpeciesOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
WoodSpeciesOut

a list of WoodSpecies objects

Source code in backend/material/api/views/wood_species.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@wood_species_router.get("/list", response=List[WoodSpeciesOut])
def list_wood_species(request):
    """
    The function `list_wood_species` retrieves a list of wood_species,
    ordered by id ascending.

    Endpoint:
        - **Path**: `/api/v1/material/wood_species/list`
        - **Method**: `GET`
        - **Response Model**: `WoodSpeciesOut`

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

    Returns:
        (WoodSpeciesOut): a list of WoodSpecies objects
    """

    try:
        qs = WoodSpecies.objects.all().order_by("id")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

update_material(request, material_id, payload)

The function update_material updates the Material specified by id.

Endpoint
  • Path: /api/v1/material/material/get/{material_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
material_id int

the id of the Material to update

required
payload MaterialIn

a Material object

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Material with the specified ID does not exist.

Source code in backend/material/api/views/material.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 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
@material_router.put("/update/{material_id}")
def update_material(request, material_id: int, payload: MaterialIn):
    """
    The function `update_material` updates the Material specified by id.

    Endpoint:
        - **Path**: `/api/v1/material/material/get/{material_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        material_id (int): the id of the Material to update
        payload (MaterialIn): a Material object

    Returns:
        success (bool): True

    Raises:
        Http404: If the Material with the specified ID does not exist.
    """

    try:
        material = get_object_or_404(Material, id=material_id)
        material.material_name = payload.material_object.material_object_name
        material.save()
        return {"success": True}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Material already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record update error")

update_material_object(request, material_object_id, payload)

The function update_material_object updates the MaterialObject specified by id.

Endpoint
  • Path: /api/v1/material/material_object/get/{material_object_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
material_object_id int

the id of the MaterialObject to update

required
payload MaterialObjectIn

a MaterialObject object

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the MaterialObject with the specified ID does not exist.

Source code in backend/material/api/views/material_object.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 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
@material_object_router.put("/update/{material_object_id}")
def update_material_object(
    request, material_object_id: int, payload: MaterialObjectIn
):
    """
    The function `update_material_object` updates the MaterialObject specified by id.

    Endpoint:
        - **Path**: `/api/v1/material/material_object/get/{material_object_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        material_object_id (int): the id of the MaterialObject to update
        payload (MaterialObjectIn): a MaterialObject object

    Returns:
        success (bool): True

    Raises:
        Http404: If the MaterialObject with the specified ID does not exist.
    """

    try:
        material_object = get_object_or_404(
            MaterialObject, id=material_object_id
        )
        material_object.material_object_name = payload.material_object_name
        material_object.save()
        return {"success": True}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "MaterialObject already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record update error")

update_store(request, store_id, payload)

The function update_store updates the store specified by id.

Endpoint
  • Path: /api/v1/store/get/{store_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
store_id int

the id of the store to update

required
payload StoreIn

a store object

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the store with the specified ID does not exist.

Source code in backend/material/api/views/store.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 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
@store_router.put("/update/{store_id}")
def update_store(request, store_id: int, payload: StoreIn):
    """
    The function `update_store` updates the store specified by id.

    Endpoint:
        - **Path**: `/api/v1/store/get/{store_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        store_id (int): the id of the store to update
        payload (StoreIn): a store object

    Returns:
        success (bool): True

    Raises:
        Http404: If the store with the specified ID does not exist.
    """

    try:
        store = get_object_or_404(Store, id=store_id)
        store.store_name = payload.store_name
        store.save()
        return {"success": True}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Store already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record update error")

Schemas

MaterialIn

Schema to validate a Material

Attributes:

Name Type Description
material_object_id int

The ID of a MaterialObject. Required.

quantity int

The number of MaterialObjects. Required. Defaults to 1.

material_status_id Optional[int]

The ID of a MaterialStatus. Defaults to None.

project_id Optional[int]

The ID of a Project. Defaults to None.

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

    Attributes:
        material_object_id (int): The ID of a MaterialObject. Required.
        quantity (int): The number of MaterialObjects. Required. Defaults to 1.
        material_status_id (Optional[int]): The ID of a MaterialStatus. Defaults
            to None.
        project_id (Optional[int]): The ID of a Project. Defaults to None.
    """

    material_object_id: int
    quantity: int = 1
    material_status_id: Optional[int] = None
    project_id: Optional[int] = None

MaterialOut

Schema to represent a Material

Attributes:

Name Type Description
id int

The id of the Material. Required.

material_object MaterialObjectOut

A reference to a MaterialObject. Required.

quantity int

The number of MaterialObjects. Required. Defaults to 1.

material_status Optional[MaterialStatusOut]

A reference to a MaterialStatus. Defaults to None.

project Optional[ProjectOut]

A reference to a Project. Defaults to None.

Source code in backend/material/api/schemas/material.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class MaterialOut(Schema):
    """
    Schema to represent a Material

    Attributes:
        id (int): The id of the Material.  Required.
        material_object (MaterialObjectOut): A reference to a MaterialObject. Required.
        quantity (int): The number of MaterialObjects. Required. Defaults to 1.
        material_status (Optional[MaterialStatusOut]): A reference to a MaterialStatus. Defaults
            to None.
        project (Optional[ProjectOut]): A reference to a Project. Defaults to None.
    """

    id: int
    material_object: MaterialObjectOut
    quantity: int = 1
    material_status: Optional[MaterialStatusOut] = None
    project: Optional[ProjectOut]

MaterialObjectIn

Schema to validate a MaterialObject

Attributes:

Name Type Description
material_object_name str

The name of the material object. Required.

thickness_in Optional[Decimal]

The thickness in inches. Defaults to None.

thickness_in Optional[Decimal]

The thickness of the material object in inches. Defaults to None.

width_in Optional[Decimal]

The width of the material object in inches. Defaults to None.

length_in Optional[Decimal]

The length of the material object in inches. Defaults to None.

wood_species_id Optional[int]

An instance of WoodSpecies. Defaults to None.

store_id Optional[int]

An instance of Store. Defaults to None.

store_aisle Optional[str]

The aisle of Store this material object is found. Defaults to None.

store_bin Optional[str]

The bin of the aisle this material object is found. Defaults to None.

store_price Optional[Decimal]

The price at the store of this material object. Defaults to None.

Source code in backend/material/api/schemas/material_object.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class MaterialObjectIn(Schema):
    """
    Schema to validate a MaterialObject

    Attributes:
        material_object_name (str): The name of the material object. Required.
        thickness_in (Optional[Decimal]): The thickness in inches. Defaults to None.
        thickness_in (Optional[Decimal]): The thickness of the material object in inches.
            Defaults to None.
        width_in (Optional[Decimal]): The width of the material object in inches. Defaults
            to None.
        length_in (Optional[Decimal]): The length of the material object in inches. Defaults
            to None.
        wood_species_id (Optional[int]): An instance of WoodSpecies.  Defaults to None.
        store_id (Optional[int]): An instance of Store.  Defaults to None.
        store_aisle (Optional[str]): The aisle of Store this material object is found. Defaults
            to None.
        store_bin (Optional[str]): The bin of the aisle this material object is found. Defaults
            to None.
        store_price (Optional[Decimal]): The price at the store of this material object. Defaults
            to None.
    """

    material_object_name: str
    thickness_in: Decimal = Field(
        whole_digits=10, decimal_places=5, default=None
    )
    width_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)
    length_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)
    wood_species_id: Optional[int]
    store_id: Optional[int] = None
    store_aisle: Optional[str] = None
    store_bin: Optional[str] = None
    store_price: Decimal = Field(
        whole_digits=10, decimal_places=2, default=0.00
    )

MaterialObjectOut

Schema to represent a MaterialObject

Attributes:

Name Type Description
id int

The id of the MaterialObject. Required.

material_object_name str

The name of the material object. Required.

thickness_in Optional[Decimal]

The thickness of the material object in inches. Defaults to None.

width_in Optional[Decimal]

The width of the material object in inches. Defaults to None.

length_in Optional[Decimal]

The length of the material object in inches. Defaults to None.

wood_species Optional[WoodSpeciesOut]

An instance of WoodSpecies. Defaults to None.

store Optioanl[StoreOut]

An instance of Store. Defaults to None.

store_aisle Optional[str]

The aisle of Store this material object is found. Defaults to None.

store_bin Optional[str]

The bin of the aisle this material object is found. Defaults to None.

store_price Optional[Decimal]

The price at the store of this material object. Defaults to 0.00.

Source code in backend/material/api/schemas/material_object.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class MaterialObjectOut(Schema):
    """
    Schema to represent a MaterialObject

    Attributes:
        id (int): The id of the MaterialObject. Required.
        material_object_name (str): The name of the material object. Required.
        thickness_in (Optional[Decimal]): The thickness of the material object in inches.
            Defaults to None.
        width_in (Optional[Decimal]): The width of the material object in inches. Defaults
            to None.
        length_in (Optional[Decimal]): The length of the material object in inches. Defaults to
            None.
        wood_species (Optional[WoodSpeciesOut]): An instance of WoodSpecies. Defaults to None.
        store (Optioanl[StoreOut]): An instance of Store. Defaults to None.
        store_aisle (Optional[str]): The aisle of Store this material object is found. Defaults
            to None.
        store_bin (Optional[str]): The bin of the aisle this material object is found. Defaults to
            None.
        store_price (Optional[Decimal]): The price at the store of this material object. Defaults to
            0.00.
    """

    id: int
    material_object_name: str
    thickness_in: Decimal = Field(
        whole_digits=10, decimal_places=5, default=None
    )
    width_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)
    length_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)
    wood_species: Optional[WoodSpeciesOut] = None
    store: Optional[StoreOut] = None
    store_aisle: Optional[str] = None
    store_bin: Optional[str] = None
    store_price: Decimal = Field(
        whole_digits=10, decimal_places=2, default=0.00
    )

MaterialStatusOut

Schema to represent a material status

Attributes:

Name Type Description
id int

The id of the material status. Required.

material_status str

The material status name. Required.

Source code in backend/material/api/schemas/material_status.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
class MaterialStatusOut(Schema):
    """
    Schema to represent a material status

    Attributes:
        id (int): The id of the material status. Required.
        material_status (str): The material status name. Required.
    """

    id: int
    material_status: str

StoreIn

Schema to validate a Store

Attributes:

Name Type Description
store_name str

The name of the Store. Required.

Source code in backend/material/api/schemas/store.py
19
20
21
22
23
24
25
26
27
class StoreIn(Schema):
    """
    Schema to validate a Store

    Attributes:
        store_name (str): The name of the Store. Required.
    """

    store_name: str

StoreOut

Schema to represent a Store

Attributes:

Name Type Description
id int

The id of the Store. Required.

store_name str

The name of the Store. Required.

Source code in backend/material/api/schemas/store.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
class StoreOut(Schema):
    """
    Schema to represent a Store

    Attributes:
        id (int): The id of the Store. Required.
        store_name (str): The name of the Store. Required.
    """

    id: int
    store_name: str

WoodSpeciesOut

Schema to represent a WoodSpecies

Attributes:

Name Type Description
id int

The id of the WoodSpecies. Required.

wood_species_name str

The name of the WoodSpecies. Required.

Source code in backend/material/api/schemas/wood_species.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
class WoodSpeciesOut(Schema):
    """
    Schema to represent a WoodSpecies

    Attributes:
        id (int): The id of the WoodSpecies. Required.
        wood_species_name (str): The name of the WoodSpecies. Required.
    """

    id: int
    wood_species_name: str

Note

Dependencies

Views

create_note(request, payload)

The function create_note creates a Note

Endpoint
  • Path: /api/v1/note/note/create
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload NoteIn

An object using schema of NoteIn.

required

Returns:

Name Type Description
id int

returns the id of the created Note

Source code in backend/note/api/views/note.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@note_router.post("/create")
def create_note(request, payload: NoteIn):
    """
    The function `create_note` creates a Note

    Endpoint:
        - **Path**: `/api/v1/note/note/create`
        - **Method**: `POST`

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

    Returns:
        id (int): returns the id of the created Note
    """

    try:
        note = Note.objects.create(**payload.dict())
        return {"id": note.id}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Note already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record creation error")

delete_note(request, note_id)

The function delete_note deletes the Note specified by id.

Endpoint
  • Path: /api/v1/note/note/delete/{note_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
note_id int

the id of the Note to delete

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Note with the specified ID does not exist.

Source code in backend/note/api/views/note.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
@note_router.delete("/delete/{note_id}")
def delete_note(request, note_id: int):
    """
    The function `delete_note` deletes the Note specified by id.

    Endpoint:
        - **Path**: `/api/v1/note/note/delete/{note_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        note_id (int): the id of the Note to delete

    Returns:
        success (bool): True

    Raises:
        Http404: If the Note with the specified ID does not exist.
    """

    try:
        note = get_object_or_404(Note, id=note_id)
        note.delete()
        return {"success": True}
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_note(request, note_id)

The function get_note retrieves the Note by id

Endpoint
  • Path: /api/v1/note/note/get/{note_id}
  • Method: GET
  • Response Model: NoteOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
note_id int

The id of the Note to retrieve.

required

Returns:

Type Description
NoteOut

The Note object

Raises:

Type Description
Http404

If the Note with the specified ID does not exist.

Source code in backend/note/api/views/note.py
104
105
106
107
108
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
@note_router.get(
    "/get/{note_id}",
    response=NoteOut,
)
def get_note(request, note_id: int):
    """
    The function `get_note` retrieves the Note by id

    Endpoint:
        - **Path**: `/api/v1/note/note/get/{note_id}`
        - **Method**: `GET`
        - **Response Model**: `NoteOut`

    Args:
        request (HttpRequest): The HTTP request object.
        note_id (int): The id of the Note to retrieve.

    Returns:
        (NoteOut): The Note object

    Raises:
        Http404: If the Note with the specified ID does not exist.
    """

    try:
        note = get_object_or_404(Note, id=note_id)
        return note
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_notes(request)

The function list_notes retrieves a list of notes, ordered by note_date descending.

Endpoint
  • Path: /api/v1/note/note/list
  • Method: GET
  • Response Model: NoteOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
NoteOut

a list of Note objects

Source code in backend/note/api/views/note.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
@note_router.get("/list", response=List[NoteOut])
def list_notes(request):
    """
    The function `list_notes` retrieves a list of notes,
    ordered by note_date descending.

    Endpoint:
        - **Path**: `/api/v1/note/note/list`
        - **Method**: `GET`
        - **Response Model**: `NoteOut`

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

    Returns:
        (NoteOut): a list of Note objects
    """

    try:
        qs = Note.objects.all().order_by("-note_date")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

update_note(request, note_id, payload)

The function update_note updates the Note specified by id.

Endpoint
  • Path: /api/v1/note/note/get/{note_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
note_id int

the id of the Note to update

required
payload NoteIn

a Note object

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Note with the specified ID does not exist.

Source code in backend/note/api/views/note.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
@note_router.put("/update/{note_id}")
def update_note(request, note_id: int, payload: NoteIn):
    """
    The function `update_note` updates the Note specified by id.

    Endpoint:
        - **Path**: `/api/v1/note/note/get/{note_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        note_id (int): the id of the Note to update
        payload (NoteIn): a Note object

    Returns:
        success (bool): True

    Raises:
        Http404: If the Note with the specified ID does not exist.
    """

    try:
        note = get_object_or_404(Note, id=note_id)
        note.save()
        return {"success": True}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Note already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record update error")

Schemas

NoteIn

Schema to validate a Note

Attributes:

Name Type Description
note_date date

The date of this note. Required. Defaults to current date.

note str

The text of the note. Required. 508 limit.

project_id Optional[int]

A reference to a Project by ID. Defaults to None.

Source code in backend/note/api/schemas/note.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class NoteIn(Schema):
    """
    Schema to validate a Note

    Attributes:
        note_date (date): The date of this note. Required. Defaults to
            current date.
        note (str): The text of the note. Required. 508 limit.
        project_id (Optional[int]): A reference to a Project by ID. Defaults to
            None.
    """

    note_date: date
    note: str
    project_id: Optional[int] = None

NoteOut

Schema to represent a Note

Attributes:

Name Type Description
id int

The id of the Note. Required.

note str

The text of the note. Required. 508 limit.

note_date date

The date of this note. Required. Defaults to current date.

attachment Optional[HttpUrl]

An attachment for this note. Defaults to None.

project Optional[ProjectOut]

A reference to a Project. Defaults to None.

Source code in backend/note/api/schemas/note.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class NoteOut(Schema):
    """
    Schema to represent a Note

    Attributes:
        id (int): The id of the Note.  Required.
        note (str): The text of the note. Required. 508 limit.
        note_date (date): The date of this note. Required. Defaults to
            current date.
        attachment (Optional[HttpUrl]): An attachment for this note. Defaults
            to None.
        project (Optional[ProjectOut]): A reference to a Project. Defaults to
            None.
    """

    id: int
    note_date: date
    note: str
    attachment: Optional[HttpUrl] = None
    project: Optional[ProjectOut] = None

Part

Dependencies

Views

create_part(request, payload)

The function create_part creates a Part

Endpoint
  • Path: /api/v1/part/part/create
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload PartIn

An object using schema of PartIn.

required

Returns:

Name Type Description
id int

returns the id of the created Part

Source code in backend/part/api/views/part.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@part_router.post("/create")
def create_part(request, payload: PartIn):
    """
    The function `create_part` creates a Part

    Endpoint:
        - **Path**: `/api/v1/part/part/create`
        - **Method**: `POST`

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

    Returns:
        id (int): returns the id of the created Part
    """

    try:
        part = Part.objects.create(**payload.dict())
        return {"id": part.id}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Part already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record creation error")

delete_part(request, part_id)

The function delete_part deletes the Part specified by id.

Endpoint
  • Path: /api/v1/part/part/delete/{part_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
part_id int

the id of the Part to delete

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Part with the specified ID does not exist.

Source code in backend/part/api/views/part.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@part_router.delete("/delete/{part_id}")
def delete_part(request, part_id: int):
    """
    The function `delete_part` deletes the Part specified by id.

    Endpoint:
        - **Path**: `/api/v1/part/part/delete/{part_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        part_id (int): the id of the Part to delete

    Returns:
        success (bool): True

    Raises:
        Http404: If the Part with the specified ID does not exist.
    """

    try:
        part = get_object_or_404(Part, id=part_id)
        part.delete()
        return {"success": True}
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_part(request, part_id)

The function get_part retrieves the Part by id

Endpoint
  • Path: /api/v1/part/part/get/{part_id}
  • Method: GET
  • Response Model: PartOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
part_id int

The id of the Part to retrieve.

required

Returns:

Type Description
PartOut

The Part object

Raises:

Type Description
Http404

If the Part with the specified ID does not exist.

Source code in backend/part/api/views/part.py
105
106
107
108
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
@part_router.get(
    "/get/{part_id}",
    response=PartOut,
)
def get_part(request, part_id: int):
    """
    The function `get_part` retrieves the Part by id

    Endpoint:
        - **Path**: `/api/v1/part/part/get/{part_id}`
        - **Method**: `GET`
        - **Response Model**: `PartOut`

    Args:
        request (HttpRequest): The HTTP request object.
        part_id (int): The id of the Part to retrieve.

    Returns:
        (PartOut): The Part object

    Raises:
        Http404: If the Part with the specified ID does not exist.
    """

    try:
        part = get_object_or_404(Part, id=part_id)
        return part
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_part_status(request, part_status_id)

The function get_part_status retrieves the PartStatus by id

Endpoint
  • Path: /api/v1/part/part_status/get/{part_status_id}
  • Method: GET
  • Response Model: PartStatusOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
part_status_id int

The id of the PartStatus to retrieve.

required

Returns:

Type Description
PartStatusOut

The PartStatus object

Raises:

Type Description
Http404

If the PartStatus with the specified ID does not exist.

Source code in backend/part/api/views/part_status.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@part_status_router.get(
    "/get/{part_status_id}",
    response=PartStatusOut,
)
def get_part_status(request, part_status_id: int):
    """
    The function `get_part_status` retrieves the PartStatus by id

    Endpoint:
        - **Path**: `/api/v1/part/part_status/get/{part_status_id}`
        - **Method**: `GET`
        - **Response Model**: `PartStatusOut`

    Args:
        request (HttpRequest): The HTTP request object.
        part_status_id (int): The id of the PartStatus to retrieve.

    Returns:
        (PartStatusOut): The PartStatus object

    Raises:
        Http404: If the PartStatus with the specified ID does not exist.
    """

    try:
        part_status = get_object_or_404(PartStatus, id=part_status_id)
        return part_status
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_part_statuses(request)

The function list_part_statuses retrieves a list of part_statuses, ordered by id ascending.

Endpoint
  • Path: /api/v1/part/part_status/list
  • Method: GET
  • Response Model: PartStatusOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
PartStatusOut

a list of PartStatus objects

Source code in backend/part/api/views/part_status.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@part_status_router.get("/list", response=List[PartStatusOut])
def list_part_statuses(request):
    """
    The function `list_part_statuses` retrieves a list of part_statuses,
    ordered by id ascending.

    Endpoint:
        - **Path**: `/api/v1/part/part_status/list`
        - **Method**: `GET`
        - **Response Model**: `PartStatusOut`

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

    Returns:
        (PartStatusOut): a list of PartStatus objects
    """

    try:
        qs = PartStatus.objects.all().order_by("id")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_parts(request)

The function list_parts retrieves a list of parts, ordered by part_name ascending.

Endpoint
  • Path: /api/v1/part/part/list
  • Method: GET
  • Response Model: PartOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
PartOut

a list of Part objects

Source code in backend/part/api/views/part.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
@part_router.get("/list", response=List[PartOut])
def list_parts(request):
    """
    The function `list_parts` retrieves a list of parts,
    ordered by part_name ascending.

    Endpoint:
        - **Path**: `/api/v1/part/part/list`
        - **Method**: `GET`
        - **Response Model**: `PartOut`

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

    Returns:
        (PartOut): a list of Part objects
    """

    try:
        qs = Part.objects.all().order_by("part_name")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

update_part(request, part_id, payload)

The function update_part updates the Part specified by id.

Endpoint
  • Path: /api/v1/part/part/get/{part_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
part_id int

the id of the Part to update

required
payload PartIn

a Part object

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Part with the specified ID does not exist.

Source code in backend/part/api/views/part.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 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
@part_router.put("/update/{part_id}")
def update_part(request, part_id: int, payload: PartIn):
    """
    The function `update_part` updates the Part specified by id.

    Endpoint:
        - **Path**: `/api/v1/part/part/get/{part_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        part_id (int): the id of the Part to update
        payload (PartIn): a Part object

    Returns:
        success (bool): True

    Raises:
        Http404: If the Part with the specified ID does not exist.
    """

    try:
        part = get_object_or_404(Part, id=part_id)
        part.part_name = payload.part_name
        part.save()
        return {"success": True}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Part already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record update error")

Schemas

PartIn

Schema to validate a Part

Attributes:

Name Type Description
quantity int

The quantity of this part. Required.

part_name str

The name of the part. Required. 254 limit.

part_status_id int

A reference to a Part Status id. Required.

rough_thickness_in Decimal

The rough thickness of the part in inches. Required.

rough_width_in Decimal

The rough width of the part in inches. Required.

rough_length_in Decimal

The rough length of the part in inches. Required.

finished_thickness_in Decimal

The finished thickness of the part in inches. Required.

finished_width_in Decimal

The finished width of the part in inches. Required.

finished_length_in Decimal

The finished length of the part in inches. Required.

project_id int

A referece to a Project id. Required.

Source code in backend/part/api/schemas/part.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class PartIn(Schema):
    """
    Schema to validate a Part

    Attributes:
        quantity (int): The quantity of this part. Required.
        part_name (str): The name of the part. Required. 254 limit.
        part_status_id (int): A reference to a Part Status id. Required.
        rough_thickness_in (Decimal): The rough thickness of the part in inches.
            Required.
        rough_width_in (Decimal): The rough width of the part in inches. Required.
        rough_length_in (Decimal): The rough length of the part in inches. Required.
        finished_thickness_in (Decimal): The finished thickness of the part in inches.
            Required.
        finished_width_in (Decimal): The finished width of the part in inches. Required.
        finished_length_in (Decimal): The finished length of the part in inches. Required.
        project_id (int): A referece to a Project id. Required.
    """

    quantity: int
    part_name: str
    part_status_id: int
    rough_thickness_in: Decimal = Field(whole_digits=10, decimal_places=5)
    rough_width_in: Decimal = Field(whole_digits=10, decimal_places=5)
    rough_length_in: Decimal = Field(whole_digits=10, decimal_places=5)
    finished_thickness_in: Decimal = Field(whole_digits=10, decimal_places=5)
    finished_width_in: Decimal = Field(whole_digits=10, decimal_places=5)
    finished_length_in: Decimal = Field(whole_digits=10, decimal_places=5)
    project_id: int

PartOut

Schema to represent a Part

Attributes:

Name Type Description
id int

The id of the Part. Required.

quantity int

The quantity of this part. Required.

part_name str

The name of the part. Required. 254 limit.

part_status PartStatusOut

A reference to a Part Status. Required.

rough_thickness_in Decimal

The rough thickness of the part in inches. Required.

rough_width_in Decimal

The rough width of the part in inches. Required.

rough_length_in Decimal

The rough length of the part in inches. Required.

finished_thickness_in Decimal

The finished thickness of the part in inches. Required.

finished_width_in Decimal

The finished width of the part in inches. Required.

finished_length_in Decimal

The finished length of the part in inches. Required.

project ProjectOut

A referece to a Project. Required.

Source code in backend/part/api/schemas/part.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class PartOut(Schema):
    """
    Schema to represent a Part

    Attributes:
        id (int): The id of the Part.  Required.
        quantity (int): The quantity of this part. Required.
        part_name (str): The name of the part. Required. 254 limit.
        part_status (PartStatusOut): A reference to a Part Status. Required.
        rough_thickness_in (Decimal): The rough thickness of the part in inches.
            Required.
        rough_width_in (Decimal): The rough width of the part in inches. Required.
        rough_length_in (Decimal): The rough length of the part in inches. Required.
        finished_thickness_in (Decimal): The finished thickness of the part in inches.
            Required.
        finished_width_in (Decimal): The finished width of the part in inches. Required.
        finished_length_in (Decimal): The finished length of the part in inches. Required.
        project (ProjectOut): A referece to a Project. Required.
    """

    id: int
    quantity: int
    part_name: str
    part_status: PartStatusOut
    rough_thickness_in: Decimal = Field(whole_digits=10, decimal_places=5)
    rough_width_in: Decimal = Field(whole_digits=10, decimal_places=5)
    rough_length_in: Decimal = Field(whole_digits=10, decimal_places=5)
    finished_thickness_in: Decimal = Field(whole_digits=10, decimal_places=5)
    finished_width_in: Decimal = Field(whole_digits=10, decimal_places=5)
    finished_length_in: Decimal = Field(whole_digits=10, decimal_places=5)
    project: ProjectOut

PartStatusOut

Schema to represent a PartStatus

Attributes:

Name Type Description
id int

The id of the PartStatus. Required.

part_status str

The text status of a part. Required. Unique. 254 limit.

Source code in backend/part/api/schemas/part_status.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class PartStatusOut(Schema):
    """
    Schema to represent a PartStatus

    Attributes:
        id (int): The id of the PartStatus.  Required.
        part_status (str): The text status of a part. Required. Unique.
            254 limit.
    """

    id: int
    part_status: str

Project

Dependencies

Views

create_project(request, payload)

The function create_project creates a Project

Endpoint
  • Path: /api/v1/project/project/create
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload ProjectIn

An object using schema of ProjectIn.

required

Returns:

Name Type Description
id int

returns the id of the created Project

Source code in backend/project/api/views/project.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@project_router.post("/create")
def create_project(request, payload: ProjectIn):
    """
    The function `create_project` creates a Project

    Endpoint:
        - **Path**: `/api/v1/project/project/create`
        - **Method**: `POST`

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

    Returns:
        id (int): returns the id of the created Project
    """

    try:
        project = Project.objects.create(**payload.dict())
        return {"id": project.id}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Project already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record creation error")

delete_project(request, project_id)

The function delete_project deletes the Project specified by id.

Endpoint
  • Path: /api/v1/project/project/delete/{project_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
project_id int

the id of the Project to delete

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Project with the specified ID does not exist.

Source code in backend/project/api/views/project.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
@project_router.delete("/delete/{project_id}")
def delete_project(request, project_id: int):
    """
    The function `delete_project` deletes the Project specified by id.

    Endpoint:
        - **Path**: `/api/v1/project/project/delete/{project_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        project_id (int): the id of the Project to delete

    Returns:
        success (bool): True

    Raises:
        Http404: If the Project with the specified ID does not exist.
    """

    try:
        project = get_object_or_404(Project, id=project_id)
        project.delete()
        return {"success": True}
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_project(request, project_id)

The function get_project retrieves the Project by id

Endpoint
  • Path: /api/v1/project/project/get/{project_id}
  • Method: GET
  • Response Model: ProjectOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
project_id int

The id of the Project to retrieve.

required

Returns:

Type Description
ProjectOut

The Project object

Raises:

Type Description
Http404

If the Project with the specified ID does not exist.

Source code in backend/project/api/views/project.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@project_router.get(
    "/get/{project_id}",
    response=ProjectOut,
)
def get_project(request, project_id: int):
    """
    The function `get_project` retrieves the Project by id

    Endpoint:
        - **Path**: `/api/v1/project/project/get/{project_id}`
        - **Method**: `GET`
        - **Response Model**: `ProjectOut`

    Args:
        request (HttpRequest): The HTTP request object.
        project_id (int): The id of the Project to retrieve.

    Returns:
        (ProjectOut): The Project object

    Raises:
        Http404: If the Project with the specified ID does not exist.
    """

    try:
        project = get_object_or_404(Project, id=project_id)
        return project
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_project_phase(request, project_phase_id)

The function get_project_phase retrieves the ProjectPhase by id

Endpoint
  • Path: /api/v1/project/project_phase/get/{project_phase_id}
  • Method: GET
  • Response Model: ProjectPhaseOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
project_phase_id int

The id of the ProjectPhase to retrieve.

required

Returns:

Type Description
ProjectPhaseOut

The ProjectPhase object

Raises:

Type Description
Http404

If the ProjectPhase with the specified ID does not exist.

Source code in backend/project/api/views/project_phase.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@project_phase_router.get(
    "/get/{project_phase_id}",
    response=ProjectPhaseOut,
)
def get_project_phase(request, project_phase_id: int):
    """
    The function `get_project_phase` retrieves the ProjectPhase by id

    Endpoint:
        - **Path**: `/api/v1/project/project_phase/get/{project_phase_id}`
        - **Method**: `GET`
        - **Response Model**: `ProjectPhaseOut`

    Args:
        request (HttpRequest): The HTTP request object.
        project_phase_id (int): The id of the ProjectPhase to retrieve.

    Returns:
        (ProjectPhaseOut): The ProjectPhase object

    Raises:
        Http404: If the ProjectPhase with the specified ID does not exist.
    """

    try:
        project_phase = get_object_or_404(ProjectPhase, id=project_phase_id)
        return project_phase
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_project_status(request, project_status_id)

The function get_project_status retrieves the ProjectStatus by id

Endpoint
  • Path: /api/v1/project/project_status/get/{project_status_id}
  • Method: GET
  • Response Model: ProjectStatusOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
project_status_id int

The id of the ProjectStatus to retrieve.

required

Returns:

Type Description
ProjectStatusOut

The ProjectStatus object

Raises:

Type Description
Http404

If the ProjectStatus with the specified ID does not exist.

Source code in backend/project/api/views/project_status.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@project_status_router.get(
    "/get/{project_status_id}",
    response=ProjectStatusOut,
)
def get_project_status(request, project_status_id: int):
    """
    The function `get_project_status` retrieves the ProjectStatus by id

    Endpoint:
        - **Path**: `/api/v1/project/project_status/get/{project_status_id}`
        - **Method**: `GET`
        - **Response Model**: `ProjectStatusOut`

    Args:
        request (HttpRequest): The HTTP request object.
        project_status_id (int): The id of the ProjectStatus to retrieve.

    Returns:
        (ProjectStatusOut): The ProjectStatus object

    Raises:
        Http404: If the ProjectStatus with the specified ID does not exist.
    """

    try:
        project_status = get_object_or_404(ProjectStatus, id=project_status_id)
        return project_status
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_project_phases(request)

The function list_project_phases retrieves a list of project_phases, ordered by id ascending.

Endpoint
  • Path: /api/v1/project/project_phase/list
  • Method: GET
  • Response Model: ProjectPhaseOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
ProjectPhaseOut

a list of ProjectPhase objects

Source code in backend/project/api/views/project_phase.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@project_phase_router.get("/list", response=List[ProjectPhaseOut])
def list_project_phases(request):
    """
    The function `list_project_phases` retrieves a list of project_phases,
    ordered by id ascending.

    Endpoint:
        - **Path**: `/api/v1/project/project_phase/list`
        - **Method**: `GET`
        - **Response Model**: `ProjectPhaseOut`

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

    Returns:
        (ProjectPhaseOut): a list of ProjectPhase objects
    """

    try:
        qs = ProjectPhase.objects.all().order_by("id")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_project_statuses(request)

The function list_project_statuses retrieves a list of project_statuses, ordered by project_status_name ascending.

Endpoint
  • Path: /api/v1/project/project_status/list
  • Method: GET
  • Response Model: ProjectStatusOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
ProjectStatusOut

a list of ProjectStatus objects

Source code in backend/project/api/views/project_status.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@project_status_router.get("/list", response=List[ProjectStatusOut])
def list_project_statuses(request):
    """
    The function `list_project_statuses` retrieves a list of project_statuses,
    ordered by project_status_name ascending.

    Endpoint:
        - **Path**: `/api/v1/project/project_status/list`
        - **Method**: `GET`
        - **Response Model**: `ProjectStatusOut`

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

    Returns:
        (ProjectStatusOut): a list of ProjectStatus objects
    """

    try:
        qs = ProjectStatus.objects.all().order_by("project_status_name")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_projects(request, page=1, page_size=10, dash=False)

The function list_projects retrieves a list of projects, ordered by project_name ascending.

Endpoint
  • Path: /api/v1/project/project/list
  • Method: GET
  • Response Model: ProjectOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
dash bool

Filters projects that are not in progress or on hold. Defaults to False.

False

Returns:

Type Description
ProjectOut

a list of Project objects

Source code in backend/project/api/views/project.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@project_router.get("/list", response=PaginatedProjects)
def list_projects(
    request,
    page: Optional[int] = 1,
    page_size: Optional[int] = 10,
    dash: Optional[bool] = False,
):
    """
    The function `list_projects` retrieves a list of projects,
    ordered by project_name ascending.

    Endpoint:
        - **Path**: `/api/v1/project/project/list`
        - **Method**: `GET`
        - **Response Model**: `ProjectOut`

    Args:
        request (HttpRequest): The HTTP request object.
        dash (bool): Filters projects that are not in progress
            or on hold. Defaults to False.

    Returns:
        (ProjectOut): a list of Project objects
    """

    try:
        qs = None
        if dash:
            qs = (
                Project.objects.all()
                .filter(project_status__id__lt=3)
                .order_by("project_status__id", "due_date", "project_name")
            )
        else:
            qs = Project.objects.all().order_by(
                "project_status__id", "due_date", "project_name"
            )

        # Paginate projects
        paginated_list, total_records, total_pages = paginate_list(
            qs, page_size, page
        )
        paginated_obj = PaginatedProjects(
            projects=paginated_list,
            current_page=page,
            total_pages=total_pages,
            total_records=total_records,
        )

        return paginated_obj
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

update_project(request, project_id, payload)

The function update_project updates the Project specified by id.

Endpoint
  • Path: /api/v1/project/project/get/{project_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
project_id int

the id of the Project to update

required
payload ProjectIn

a Project object

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Project with the specified ID does not exist.

Source code in backend/project/api/views/project.py
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
@project_router.put("/update/{project_id}")
def update_project(request, project_id: int, payload: ProjectIn):
    """
    The function `update_project` updates the Project specified by id.

    Endpoint:
        - **Path**: `/api/v1/project/project/get/{project_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        project_id (int): the id of the Project to update
        payload (ProjectIn): a Project object

    Returns:
        success (bool): True

    Raises:
        Http404: If the Project with the specified ID does not exist.
    """

    try:
        project = get_object_or_404(Project, id=project_id)
        project.project_name = payload.project_name
        project.save()
        return {"success": True}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Project already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record update error")

Schemas

PaginatedProjects

Schema to provide a paginated list of ProjectOut.

Attributes:

Name Type Description
projects List[ProjectOut]

A list of ProjectOut. Required.

current_page int

The current page returned. Required.

total_pages int

The total number of pages. Required.

total_records int

The total number of projects. Required.

Source code in backend/project/api/schemas/project.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class PaginatedProjects(Schema):
    """
    Schema to provide a paginated list of ProjectOut.

    Attributes:
        projects (List[ProjectOut]): A list of ProjectOut. Required.
        current_page (int): The current page returned. Required.
        total_pages (int): The total number of pages. Required.
        total_records (int): The total number of projects. Required.
    """

    projects: List[ProjectOut]
    current_page: int
    total_pages: int
    total_records: int

ProjectIn

Schema to validate a Project

Attributes:

Name Type Description
project_name str

The name of the poject. Required. Unique. 254 limit.

project_status ProjectStatusOut

A reference to a Project Status. Required.

start_date Optional[date]

The date this project started. Defaults to None.

due_date Optional[date]

The date this project is due. Defaults to None.

completed_date Optional[date]

The date this project completed. Defaults to None.

depth_in Optional[Decimal]

The depth in inches. Defaults to 0.

width_in Optional[Decimal]

The width in inches. Defaults to 0.

height_in Optional[Decimal]

The height in inches. Defaults to 0.

Source code in backend/project/api/schemas/project.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class ProjectIn(Schema):
    """
    Schema to validate a Project

    Attributes:
        project_name (str): The name of the poject. Required. Unique. 254 limit.
        project_status (ProjectStatusOut): A reference to a Project Status. Required.
        start_date (Optional[date]): The date this project started. Defaults to None.
        due_date (Optional[date]): The date this project is due. Defaults to None.
        completed_date (Optional[date]): The date this project completed. Defaults to None.
        depth_in (Optional[Decimal]): The depth in inches. Defaults to 0.
        width_in (Optional[Decimal]): The width in inches. Defaults to 0.
        height_in (Optional[Decimal]): The height in inches. Defaults to 0.
    """

    project_name: str
    project_status: ProjectStatusOut
    start_date: Optional[date] = None
    due_date: Optional[date] = None
    completed_date: Optional[date] = None
    depth_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)
    width_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)
    height_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)

ProjectOut

Schema to represent a Project

Attributes:

Name Type Description
id int

The id of the Project. Required.

project_name str

The name of the poject. Required. Unique. 254 limit.

project_status ProjectStatusOut

A reference to a Project Status. Required.

project_image Optional[str]

An image for the project. Defaults to None.

start_date Optional[date]

The date this project started. Defaults to None.

due_date Optional[date]

The date this project is due. Defaults to None.

completed_date Optional[date]

The date this project completed. Defaults to None.

depth_in Optional[Decimal]

The depth in inches. Defaults to 0.

width_in Optional[Decimal]

The width in inches. Defaults to 0.

height_in Optional[Decimal]

The height in inches. Defaults to 0.

Source code in backend/project/api/schemas/project.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class ProjectOut(Schema):
    """
    Schema to represent a Project

    Attributes:
        id (int): The id of the Project.  Required.
        project_name (str): The name of the poject. Required. Unique. 254 limit.
        project_status (ProjectStatusOut): A reference to a Project Status. Required.
        project_image (Optional[str]): An image for the project. Defaults to None.
        start_date (Optional[date]): The date this project started. Defaults to None.
        due_date (Optional[date]): The date this project is due. Defaults to None.
        completed_date (Optional[date]): The date this project completed. Defaults to None.
        depth_in (Optional[Decimal]): The depth in inches. Defaults to 0.
        width_in (Optional[Decimal]): The width in inches. Defaults to 0.
        height_in (Optional[Decimal]): The height in inches. Defaults to 0.
    """

    id: int
    project_name: str
    project_status: ProjectStatusOut
    project_image: Optional[str] = None
    start_date: Optional[date] = None
    due_date: Optional[date] = None
    completed_date: Optional[date] = None
    depth_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)
    width_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)
    height_in: Decimal = Field(whole_digits=10, decimal_places=5, default=None)

ProjectPhaseOut

Schema to represent a ProjectPhase

Attributes:

Name Type Description
id int

The id of the ProjectPhase. Required.

project_phase str

The text phase of a project. Required. Unique.

Source code in backend/project/api/schemas/project_phase.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
class ProjectPhaseOut(Schema):
    """
    Schema to represent a ProjectPhase

    Attributes:
        id (int): The id of the ProjectPhase.  Required.
        project_phase (str): The text phase of a project. Required. Unique.
    """

    id: int
    project_phase: str

ProjectStatusOut

Schema to represent a ProjectStatus

Attributes:

Name Type Description
id int

The id of the ProjectStatus. Required.

project_status str

The text status of a project. Required. Unique.

Source code in backend/project/api/schemas/project_status.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
class ProjectStatusOut(Schema):
    """
    Schema to represent a ProjectStatus

    Attributes:
        id (int): The id of the ProjectStatus.  Required.
        project_status (str): The text status of a project. Required. Unique.
    """

    id: int
    project_status: str

Task

Dependencies

Views

create_task(request, payload)

The function create_task creates a Task

Endpoint
  • Path: /api/v1/task/task/create
  • Method: POST

Parameters:

Name Type Description Default
request
required
payload TaskIn

An object using schema of TaskIn.

required

Returns:

Name Type Description
id int

returns the id of the created Task

Source code in backend/task/api/views/task.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@task_router.post("/create")
def create_task(request, payload: TaskIn):
    """
    The function `create_task` creates a Task

    Endpoint:
        - **Path**: `/api/v1/task/task/create`
        - **Method**: `POST`

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

    Returns:
        id (int): returns the id of the created Task
    """

    try:
        task = Task.objects.create(**payload.dict())
        return {"id": task.id}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Task already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record creation error")

delete_task(request, task_id)

The function delete_task deletes the Task specified by id.

Endpoint
  • Path: /api/v1/task/task/delete/{task_id}
  • Method: DELETE

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
task_id int

the id of the Task to delete

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Task with the specified ID does not exist.

Source code in backend/task/api/views/task.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
@task_router.delete("/delete/{task_id}")
def delete_task(request, task_id: int):
    """
    The function `delete_task` deletes the Task specified by id.

    Endpoint:
        - **Path**: `/api/v1/task/task/delete/{task_id}`
        - **Method**: `DELETE`

    Args:
        request (HttpRequest): The HTTP request object.
        task_id (int): the id of the Task to delete

    Returns:
        success (bool): True

    Raises:
        Http404: If the Task with the specified ID does not exist.
    """

    try:
        task = get_object_or_404(Task, id=task_id)
        task.delete()
        return {"success": True}
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_task(request, task_id)

The function get_task retrieves the Task by id

Endpoint
  • Path: /api/v1/task/task/get/{task_id}
  • Method: GET
  • Response Model: TaskOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
task_id int

The id of the Task to retrieve.

required

Returns:

Type Description
TaskOut

The Task object

Raises:

Type Description
Http404

If the Task with the specified ID does not exist.

Source code in backend/task/api/views/task.py
105
106
107
108
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
@task_router.get(
    "/get/{task_id}",
    response=TaskOut,
)
def get_task(request, task_id: int):
    """
    The function `get_task` retrieves the Task by id

    Endpoint:
        - **Path**: `/api/v1/task/task/get/{task_id}`
        - **Method**: `GET`
        - **Response Model**: `TaskOut`

    Args:
        request (HttpRequest): The HTTP request object.
        task_id (int): The id of the Task to retrieve.

    Returns:
        (TaskOut): The Task object

    Raises:
        Http404: If the Task with the specified ID does not exist.
    """

    try:
        task = get_object_or_404(Task, id=task_id)
        return task
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

get_task_status(request, task_status_id)

The function get_task_status retrieves the TaskStatus by id

Endpoint
  • Path: /api/v1/task/task_status/get/{task_status_id}
  • Method: GET
  • Response Model: TaskStatusOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
task_status_id int

The id of the TaskStatus to retrieve.

required

Returns:

Type Description
TaskStatusOut

The TaskStatus object

Raises:

Type Description
Http404

If the TaskStatus with the specified ID does not exist.

Source code in backend/task/api/views/task_status.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@task_status_router.get(
    "/get/{task_status_id}",
    response=TaskStatusOut,
)
def get_task_status(request, task_status_id: int):
    """
    The function `get_task_status` retrieves the TaskStatus by id

    Endpoint:
        - **Path**: `/api/v1/task/task_status/get/{task_status_id}`
        - **Method**: `GET`
        - **Response Model**: `TaskStatusOut`

    Args:
        request (HttpRequest): The HTTP request object.
        task_status_id (int): The id of the TaskStatus to retrieve.

    Returns:
        (TaskStatusOut): The TaskStatus object

    Raises:
        Http404: If the TaskStatus with the specified ID does not exist.
    """

    try:
        task_status = get_object_or_404(TaskStatus, id=task_status_id)
        return task_status
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_task_statuses(request)

The function list_task_statuses retrieves a list of task_statuses, ordered by id ascending.

Endpoint
  • Path: /api/v1/task/task_status/list
  • Method: GET
  • Response Model: TaskStatusOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns:

Type Description
TaskStatusOut

a list of TaskStatus objects

Source code in backend/task/api/views/task_status.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@task_status_router.get("/list", response=List[TaskStatusOut])
def list_task_statuses(request):
    """
    The function `list_task_statuses` retrieves a list of task_statuses,
    ordered by id ascending.

    Endpoint:
        - **Path**: `/api/v1/task/task_status/list`
        - **Method**: `GET`
        - **Response Model**: `TaskStatusOut`

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

    Returns:
        (TaskStatusOut): a list of TaskStatus objects
    """

    try:
        qs = TaskStatus.objects.all().order_by("id")
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

list_tasks(request)

The function list_tasks retrieves a list of tasks, ordered by task_name ascending.

Endpoint
  • Path: /api/v1/task/task/list
  • Method: GET
  • Response Model: TaskOut

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required

Returns: (TaskOut): a list of Task objects

Source code in backend/task/api/views/task.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@task_router.get("/list", response=List[TaskOut])
def list_tasks(request):
    """
    The function `list_tasks` retrieves a list of tasks,
    ordered by task_name ascending.

    Endpoint:
        - **Path**: `/api/v1/task/task/list`
        - **Method**: `GET`
        - **Response Model**: `TaskOut`

    Args:
        request (HttpRequest): The HTTP request object.
    Returns:
        (TaskOut): a list of Task objects
    """

    try:
        qs = (
            Task.objects.all()
            .filter(task_status__id__lt=4)
            .exclude(project__project_status__id__gte=3)
            .order_by(
                "task_status__id",
                "due_date",
                "project__project_status__id",
                "project__due_date",
                "task_name",
            )
        )
        return qs
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record retrieval error")

update_task(request, task_id, payload)

The function update_task updates the Task specified by id.

Endpoint
  • Path: /api/v1/task/task/get/{task_id}
  • Method: PUT

Parameters:

Name Type Description Default
request HttpRequest

The HTTP request object.

required
task_id int

the id of the Task to update

required
payload TaskIn

a Task object

required

Returns:

Name Type Description
success bool

True

Raises:

Type Description
Http404

If the Task with the specified ID does not exist.

Source code in backend/task/api/views/task.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 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
@task_router.put("/update/{task_id}")
def update_task(request, task_id: int, payload: TaskIn):
    """
    The function `update_task` updates the Task specified by id.

    Endpoint:
        - **Path**: `/api/v1/task/task/get/{task_id}`
        - **Method**: `PUT`

    Args:
        request (HttpRequest): The HTTP request object.
        task_id (int): the id of the Task to update
        payload (TaskIn): a Task object

    Returns:
        success (bool): True

    Raises:
        Http404: If the Task with the specified ID does not exist.
    """

    try:
        task = get_object_or_404(Task, id=task_id)
        task.task_name = payload.task_name
        task.save()
        return {"success": True}
    except IntegrityError as integrity_error:
        # Check if the integrity error is due to a duplicate
        if "unique constraint" in str(integrity_error).lower():
            raise HttpError(400, "Task already exists")
        else:
            # Log other types of integry errors
            raise HttpError(400, "DB integrity error")
    except Exception as e:
        # Log other types of exceptions
        raise HttpError(500, "Record update error")

Schemas

TaskStatusOut

Schema to represent a TaskStatus

Attributes:

Name Type Description
id int

The id of the TaskStatus. Required.

task_status str

The status text of a task. Required. Unique. 254 limit.

Source code in backend/task/api/schemas/task_status.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
class TaskStatusOut(Schema):
    """
    Schema to represent a TaskStatus

    Attributes:
        id (int): The id of the TaskStatus.  Required.
        task_status (str): The status text of a task. Required. Unique. 254 limit.
    """

    id: int
    task_status: str

TaskIn

Schema to validate a Task

Attributes:

Name Type Description
task_name str

The name of the task. Required. Unique. 254 limit.

task_status_id int

A reference to a Task Status by id. Required.

start_date Optional[date]

The date this task started. Defaults to None.

due_date Optional[date]

The date this task is due. Defaults to None.

completed_date Optional[date]

The date this task completed. Defaults to None.

project_id Optional[int]

A referece to a Project by id. Defaults to None.

phase_id Optional[int]

A reference to a Project Phase by id. Defaults to None.

step Optional[int]

The number representing the order of the step. Defaults to None.

part Optional[int]

A reference to a Part by id. Defaults to None.

Source code in backend/task/api/schemas/task.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class TaskIn(Schema):
    """
    Schema to validate a Task

    Attributes:
        task_name (str): The name of the task. Required. Unique. 254 limit.
        task_status_id (int): A reference to a Task Status by id. Required.
        start_date (Optional[date]): The date this task started. Defaults to None.
        due_date (Optional[date]): The date this task is due. Defaults to None.
        completed_date (Optional[date]): The date this task completed. Defaults to None.
        project_id (Optional[int]): A referece to a Project by id. Defaults to None.
        phase_id (Optional[int]): A reference to a Project Phase by id. Defaults to None.
        step (Optional[int]): The number representing the order of the step. Defaults to None.
        part (Optional[int]): A reference to a Part by id. Defaults to None.
    """

    task_name: str
    task_status_id: int
    start_date: Optional[date] = None
    due_date: Optional[date] = None
    completed_date: Optional[date] = None
    project_id: Optional[int] = None
    phase_id: Optional[int] = None
    step: Optional[int] = None
    part_id: Optional[int] = None

TaskOut

Schema to represent a Task

Attributes:

Name Type Description
id int

The id of the Task. Required.

task_name str

The name of the task. Required. Unique. 254 limit.

task_status TaskStatusOut

A reference to a Task Status. Required.

start_date Optional[date]

The date this task started. Defaults to None.

due_date Optional[date]

The date this task is due. Defaults to None.

completed_date Optional[date]

The date this task completed. Defaults to None.

project Optional[ProjectOut]

A referece to a Project. Defaults to None.

phase Optional[ProjectPhaseOut]

A reference to a Project Phase. Defaults to None.

step Optional[int]

The number representing the order of the step. Defaults to None.

part Optional[PartOut]

A reference to a Part. Defaults to None.

Source code in backend/task/api/schemas/task.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class TaskOut(Schema):
    """
    Schema to represent a Task

    Attributes:
        id (int): The id of the Task.  Required.
        task_name (str): The name of the task. Required. Unique. 254 limit.
        task_status (TaskStatusOut): A reference to a Task Status. Required.
        start_date (Optional[date]): The date this task started. Defaults to None.
        due_date (Optional[date]): The date this task is due. Defaults to None.
        completed_date (Optional[date]): The date this task completed. Defaults to None.
        project (Optional[ProjectOut]): A referece to a Project. Defaults to None.
        phase (Optional[ProjectPhaseOut]): A reference to a Project Phase. Defaults to None.
        step (Optional[int]): The number representing the order of the step. Defaults to None.
        part (Optional[PartOut]): A reference to a Part. Defaults to None.
    """

    id: int
    task_name: str
    task_status: TaskStatusOut
    start_date: Optional[date] = None
    due_date: Optional[date] = None
    completed_date: Optional[date] = None
    project: Optional[ProjectOut] = None
    phase: Optional[ProjectPhaseOut] = None
    step: Optional[int] = None
    part: Optional[PartOut] = None