Compare commits

..

2 Commits

Author SHA1 Message Date
37ffa1d346 Reformat code 2020-10-19 10:41:40 -05:00
3060a9fafb Write README.md 2020-10-16 18:56:31 -05:00
6 changed files with 306 additions and 98 deletions

202
README.md
View File

@ -1,3 +1,203 @@
# InvMan
Inventory Manager
## Table of Contents
1. [What is InvMan?](#what-is-invman)
2. [API Usage](#api-usage)
1. [GET Requests](#get-requests-getting-information)
2. [POST Requests](#post-requests-creating-objects)
## What is InvMan?
InvMan is a Flask app which provides a web API and web UI to keep inventory using a PostgreSQL backend.
---
## API Usage
### GET requests (getting information)
---
Please keep in mind:
* Text surrounded by `[` and `]` are parameters which should be replaced.
* Names are case-sensitive.
Get a list of locations
```plaintext
GET /api/v1/locations
```
Get information about a location
```plaintext
GET /api/v1/location/name/[location-name]
```
Get the quantities of all products at a location
```plaintext
GET /api/v1/location/[location-name]/quantities
```
Get the quantity of a product (by UPC) at a location
```plaintext
GET /api/v1/location/[location-name]/quantity/upc/[product-upc]
```
Get the quantity of a product (by name) at a location
```plaintext
GET /api/v1/location/[location-name]/quantity/name/[product-name]
```
Get a list of products
```plaintext
GET /api/v1/products
```
Get information about a product (by UPC)
```plaintext
GET /api/v1/product/upc/[product-upc]
```
Get information about a product (by name)
```plaintext
GET /api/v1/product/name/[product-name]
```
Get a list of brands
```plaintext
GET /api/v1/brands
```
Get information about a brand
```plaintext
GET /api/v1/brand/name/[brand-name]
```
Get a list of units
```plaintext
GET /api/v1/units
```
Get information about a unit (by name)
```plaintext
GET /api/v1/unit/name/[unit-name]
```
Get a list of purchases
```plaintext
GET /api/v1/purchases
```
Get information about a purchase (by id)
```plaintext
GET /api/v1/purchase/id/[purchase-id]
```
Get a list of uses
```plaintext
GET /api/v1/uses
```
Get information about a use (by id)
```plaintext
GET /api/v1/purchase/id/[use-id]
```
### POST Requests (creating objects)
---
Create a location
```plaintext
POST /api/v1/create_location
```
Request form:
| Argument Name | Description | Required? |
| ------------- | --------------------------- | --------- |
| name | Name of the location | Yes |
| description | Description of the location | No |
---
Create a brand
```plaintext
POST /api/v1/create_brand
```
Request form:
| Argument Name | Description | Required? |
| ------------- | ------------------------ | --------- |
| name | Name of the brand | Yes |
| description | Description of the brand | No |
---
Create a unit
```plaintext
POST /api/v1/create_unit
```
Request form:
| Argument Name | Description | Required? |
| ------------- | ----------------------- | --------- |
| name | Name of the unit | Yes |
| description | Description of the unit | No |
---
Create a product
```plaintext
POST /api/v1/create_product
```
Request form:
| Argument Name | Description | Required? |
| ------------- | ----------------------------- | --------- |
| upc | UPC of the product | Yes |
| brand | Brand which makes the product | Yes |
| name | Name of the product | Yes |
| size | Size of the product | Yes |
| sizeunit | Unit used in `size` | Yes |
| description | Description of the product | No |
---
Create a purchase
```plaintext
POST /api/v1/create_purchase
```
| Argument Name | Description | Required? |
| ------------- | -------------------------------------- | --------- |
| upc | UPC of the product which was purchased | Yes |
| quantity | Quantity of the product purchased | Yes |
| date | Date of this purchase | Yes |
| location | Location to link this purchase to | Yes |
---
Create a use
```plaintext
POST /api/v1/create_use
```
| Argument Name | Description | Required? |
| ------------- | --------------------------------- | --------- |
| upc | UPC of the product which was used | Yes |
| quantity | Quantity of the product used | Yes |
| date | Date of this usage | Yes |
| location | Location to link this usage to | Yes |

View File

@ -1,25 +1,27 @@
<!DOCTYPE HTML>
<html>
<body>
<table border=1>
<tr>
<th>UPC</th>
<td>Brand</td>
<td>Name</td>
<td>Size</td>
<td>Size Unit</td>
<td>Description</td>
</tr>
{% for upc, brand, name, size, sizeunit, description in data %}
<tr>
<th> {{ upc }} </th>
<td> {{ brand }} </td>
<td> {{ name }} </td>
<td> {{ size }} </td>
<td> {{ sizeunit }} </td>
<td> {{ description }} </td>
</tr>
{% endfor %}
</table>
</body>
<body>
<table border=1>
<tr>
<th>UPC</th>
<td>Brand</td>
<td>Name</td>
<td>Size</td>
<td>Size Unit</td>
<td>Description</td>
</tr>
{% for upc, brand, name, size, sizeunit, description in data %}
<tr>
<th> {{ upc }} </th>
<td> {{ brand }} </td>
<td> {{ name }} </td>
<td> {{ size }} </td>
<td> {{ sizeunit }} </td>
<td> {{ description }} </td>
</tr>
{% endfor %}
</table>
</body>
</html>

View File

@ -1,29 +1,31 @@
<!DOCTYPE HTML>
<html>
<body>
<form action="./purchases">
<input type="text" placeholder="Location" name="location" />
<input type="submit" />
<br>
<input type="reset" value="Reset" onclick="parent.location='./purchases'" />
</form>
<table border=1>
<tr>
<th>ID</th>
<td>UPC</td>
<td>Quantity</td>
<td>Date</td>
<td>Location</td>
</tr>
{% for id, upc, quantity, date, location in data %}
<tr>
<th> {{ id }}</th>
<th> {{ upc }} </th>
<td> {{ quantity }} </td>
<td> {{ date }}</td>
<td> {{ location }} </td>
</tr>
{% endfor %}
</table>
</body>
<body>
<form action="./purchases">
<input type="text" placeholder="Location" name="location" />
<input type="submit" />
<br>
<input type="reset" value="Reset" onclick="parent.location='./purchases'" />
</form>
<table border=1>
<tr>
<th>ID</th>
<td>UPC</td>
<td>Quantity</td>
<td>Date</td>
<td>Location</td>
</tr>
{% for id, upc, quantity, date, location in data %}
<tr>
<th> {{ id }}</th>
<th> {{ upc }} </th>
<td> {{ quantity }} </td>
<td> {{ date }}</td>
<td> {{ location }} </td>
</tr>
{% endfor %}
</table>
</body>
</html>

View File

@ -1,25 +1,27 @@
<!DOCTYPE HTML>
<html>
<body>
<form action="./quantities">
<input type="text" placeholder="Location" name="location" />
<input type="submit" />
<br>
<input type="reset" value="Reset" onclick="parent.location='./quantities'" />
</form>
<table border=1>
<tr>
<th>UPC</th>
<td>Quantity</td>
<td>Location</td>
</tr>
{% for upc, quantity, location in data %}
<tr>
<th> {{ upc }} </th>
<td> {{ quantity }} </td>
<td> {{ location }} </td>
</tr>
{% endfor %}
</table>
</body>
<body>
<form action="./quantities">
<input type="text" placeholder="Location" name="location" />
<input type="submit" />
<br>
<input type="reset" value="Reset" onclick="parent.location='./quantities'" />
</form>
<table border=1>
<tr>
<th>UPC</th>
<td>Quantity</td>
<td>Location</td>
</tr>
{% for upc, quantity, location in data %}
<tr>
<th> {{ upc }} </th>
<td> {{ quantity }} </td>
<td> {{ location }} </td>
</tr>
{% endfor %}
</table>
</body>
</html>

View File

@ -1,29 +1,31 @@
<!DOCTYPE HTML>
<html>
<body>
<form action="./uses">
<input type="text" placeholder="Location" name="location" />
<input type="submit" />
<br>
<input type="reset" value="Reset" onclick="parent.location='./uses'" />
</form>
<table border=1>
<tr>
<th>ID</th>
<td>UPC</td>
<td>Quantity</td>
<td>Date</td>
<td>Location</td>
</tr>
{% for id, upc, quantity, date, location in data %}
<tr>
<th> {{ id }}</th>
<th> {{ upc }} </th>
<td> {{ quantity }} </td>
<td> {{ date }}</td>
<td> {{ location }} </td>
</tr>
{% endfor %}
</table>
</body>
<body>
<form action="./uses">
<input type="text" placeholder="Location" name="location" />
<input type="submit" />
<br>
<input type="reset" value="Reset" onclick="parent.location='./uses'" />
</form>
<table border=1>
<tr>
<th>ID</th>
<td>UPC</td>
<td>Quantity</td>
<td>Date</td>
<td>Location</td>
</tr>
{% for id, upc, quantity, date, location in data %}
<tr>
<th> {{ id }}</th>
<th> {{ upc }} </th>
<td> {{ quantity }} </td>
<td> {{ date }}</td>
<td> {{ location }} </td>
</tr>
{% endfor %}
</table>
</body>
</html>

View File

@ -316,7 +316,7 @@ def api_create_product():
session.commit()
print("committed")
return jsonify({'api_endpoints': [f'/api/v1/product/upc/{request.form["upc"]}',
f'/api/v1/product/name/{request.form["name"]}']})
f'/api/v1/product/name/{request.form["name"]}']})
except IntegrityError:
session.rollback()
return jsonify({'error': 'INTEGRITY_ERROR'})