Skip to content

Commit 6f7d4fb

Browse files
update to instructions on how to run database
1 parent 7d69e5c commit 6f7d4fb

File tree

7 files changed

+61
-31
lines changed

7 files changed

+61
-31
lines changed

alembic/env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# access to the values within the .ini file in use.
1212
config = context.config
1313
config.set_main_option(
14-
# "sqlalchemy.url", "sqlite:///./src/sql_app.db"
15-
"sqlalchemy.url", "sqlite:///./src/sql_app.db"
14+
"sqlalchemy.url", "sqlite:///./src/sql_app.db",
15+
# f"mysql://{settings.database_username}:{settings.database_password}@{settings.database_port}/{settings.database_name}"
1616
)
1717
# Interpret the config file for Python logging.
1818
# This line sets up loggers basically.

docs/how-to-create-db.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# How to create initial DB
22

3-
@todo - SQLite
4-
3+
The application can run 2 types of databases by simply changing your `DEBUGGING` environment variable.
54

5+
If you have followed instructions for a manual build in the `README.md` doc,
6+
then you will already have already created a `.env` file. Make sure that DEBUGGING is set 1 (which means True). When the application is run, an empty sqlite `sql_app.db` file will automatically be created in the `/src` folder.

docs/how-to-manage-api-products.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
# How manage products via API
2+
- All of the products routes live in the same router. The url is prefixed with `/api/products`.
3+
24

35
How to:
6+
## Nonauthentication-Required Routes
7+
- All of the routes in this category are open to the public.
8+
9+
**Get ->**
10+
The route used to get one product is named `get_product.` This route expects to recieve a product id (integer) in the url.
11+
12+
**Get All ->**
13+
The route used to update a product is named `get_products.` This route will return all products, and an empty list if there are none.
14+
15+
16+
## Authenticaion-Required Routes
17+
- All of the routes in this category require for the user to be authenticated. For more information on user authentication, see the `/docs/how-to-secure-api` documentation.
18+
19+
**Create ->**
20+
The route used to create a product is named `create_product`. This route expects to recieve raw json. The exact data required and corresponding types allowed can be seen in `/src/schemas.py`, under the class ProductBase.
21+
22+
**Update ->**
23+
The route used to update a product is named `update_product.` This route expects to recieve a product id (integer) in the url, as raw as json, specifying which column needs to be changed. The exact data required and corresponding types allowed can be seen in `/src/schemas.py`, under the class ProductBase.
424

5-
- visualize all products
6-
- create (secure way)
7-
- reserved for app registered users
8-
- update (secure way)
9-
- reserved for app registered users
10-
- delete (secure way)
11-
- reserved for app registered users
25+
**Delete ->**
26+
The route used to delete one product is named `get_product.` This route expects to recieve a product id (integer) in the url.

docs/how-to-manage-api-sales.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
# How manage Sales via API
1+
# How manage sales via API
2+
- All of the sales routes live in the same router. The url is prefixed with `/api/sales`.
23

34

45
How to:
6+
## Nonauthentication-Required Routes
7+
- All of the routes in this category are open to the public.
58

6-
- visualize all sales
7-
- create (secure way)
8-
- reserved for app registered users
9-
- update (secure way)
10-
- reserved for app registered users
11-
- delete (secure way)
12-
- reserved for app registered users
9+
**Get ->**
10+
The route used to get one sale is named `get_sale.` This route expects to recieve a sale id (integer) in the url.
11+
12+
**Get All ->**
13+
The route used to update a sale is named `get_sales.` This route will return all sales, and an empty list if there are none.
14+
15+
16+
## Authenticaion-Required Routes
17+
- All of the routes in this category require for the user to be authenticated. For more information on user authentication, see the `/docs/how-to-secure-api` documentation.
18+
19+
**Create ->**
20+
The route used to create a sale is named `create_sale`. This route expects to recieve raw json. The exact data required and corresponding types allowed can be seen in `/src/schemas.py`, under the class SaleBase.
21+
22+
**Update ->**
23+
The route used to update a sale is named `update_sale.` This route expects to recieve a sale id (integer) in the url, as raw as json, specifying which column needs to be changed. The exact data required and corresponding types allowed can be seen in `/src/schemas.py`, under the class SaleBase.
24+
25+
**Delete ->**
26+
The route used to delete one sale is named `get_sale.` This route expects to recieve a sale id (integer) in the url.

docs/how-to-migrate-db.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# How to Migrate DB
22

3-
@todo
3+
The database migration tool we are using is `Alembic.`
44

55

docs/how-to-secure-api.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# How the API is secured
22

3-
A secured API means:
3+
The application is secured using jwt, or `json web tokens`. Communicating to the api that you are authorized occurs in two ways, differing on whether you're manually making requests or trying to access pages that require authentication.
44

5-
- Get requests (get all, get item) can be used in public space
6-
- Mutating requests are reserved for users registered in the app
7-
- create
8-
- update
9-
- delete
5+
**Getting Authorized**
6+
Getting authorized is the basic process of recieving a jwt token and storing it in your browser. This is done when you successfully send the correct credentials to login route, `/api/auth/login`. This route is looking to recieve form data with two key/value pairs, "username", which holds the users email, and "password" which holds the user's password.
7+
8+
**Making Authorized Requests**
9+
The majority of the routes in this category are going to be prefixed with `/api`. You can tell specifically by looking at the route, it will have this argument ` current_user: int = Depends(oauth2.get_current_user)`, meaning that the route depends on an authorized user and won't function without one. Oauth2 is doing most of the heavy lifting in this case. It checks the request's Header for a particualr key/value pair. The key it is searching for is `Authorization`, and the value is the token type (bearer) and the actual token, `Bearer {my.jwt.token}`. This form of authorization applies to all create, update, and delete nodes.
10+
11+
**Navigating to Authorized Webpages**
12+
All of the routes in this category will have no prefix `/`, as they are user interface routes. All of the routes that require authorization will have the decorator function `@oauth2.auth_required`. This function take a look at the request's cookies, particularly with the key `Authorization`, which stores the users looking for jwt token. If a jwt token is not found or has expired, the user is forwarded to signin page. A cookie is used in this case because it persists across all requests.
1013

11-
This logic applies to all API nodes:
12-
- products
13-
- sales

docs/how-to-use-mysql.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# How to create initial DB
22

3-
@todo - MySql
4-
3+
Switching the application over from SQLITE to Mysql is as simple as changing the projects environment variable `DEBUGGING` to 0, which means false. The application will automatically look for a mysql server with the proper authentication. However, it's very important that you already have mysql installed and an empty schema.
54

5+
Furthermore, the Alembic configuration should be changed so that it is pointing to the correct url. The config for alembic is `/alembic/env.py`.

0 commit comments

Comments
 (0)