Feat(Doc): Improved documentation for backend

This commit is contained in:
minhtrannhat 2023-07-16 22:07:30 -04:00
parent eab8670780
commit 62daa16646
Signed by: minhtrannhat
GPG Key ID: E13CFA85C53F8062
6 changed files with 70 additions and 60 deletions

View File

@ -6,6 +6,10 @@
- `prettier`: Formatter - `prettier`: Formatter
### Frontend Technical Write-up
Inside the `backend\` folder
## Backend ## Backend
### Development workflow ### Development workflow
@ -42,26 +46,4 @@
### Backend Technical Write-up ### Backend Technical Write-up
#### Quart specific terminologies Inside the `backend\` folder
`blueprint`: a collection of route handlers/API functionalities.
#### API route trailing slashes
API paths should end with a slash i.e: `/sessions/` rather than `/session`.
This is because requests sent to `/sessions` will be redirected to `/sessions/` whereas `/sessions/` won't get redirected.
#### Difference between database schema and database model
- A schema defines the structure of data within the database.
- A model is a class that can be represented as rows in the database, i.e ID row, age row as class member.
#### Managing user's sessions (Authentication)
- Login should results in a cookie being set in the user's browser, which is being sent in every subsequent request.
The presence and value of this cookie are used to determine whether the member is logged in, and which member made the request.
- Logout results in the cookie being deleted.
#### Idempotent routes
Idempotence is a property of a route where the final state is achieved no matter how many times the route is called, that is, calling the route once or 10 times has the same effect. This is a useful property as it means the route can be safely retried if the request fails. For RESTful and HTTP APIs, the routes using GET, PUT, and DELETE verbs are expected to be idempotent.

27
backend/README.md Normal file
View File

@ -0,0 +1,27 @@
# Backend Technical Write Up
## General Bits of Information
### Quart specific terminologies
`blueprint`: a collection of route handlers/API functionalities.
### API route trailing slashes
API paths should end with a slash i.e: `/sessions/` rather than `/session`.
This is because requests sent to `/sessions` will be redirected to `/sessions/` whereas `/sessions/` won't get redirected.
### Difference between database schema and database model
- A schema defines the structure of data within the database.
- A model is a class that can be represented as rows in the database, i.e ID row, age row as class member.
### Managing user's sessions (Authentication)
- Login should results in a cookie being set in the user's browser, which is being sent in every subsequent request.
The presence and value of this cookie are used to determine whether the member is logged in, and which member made the request.
- Logout results in the cookie being deleted.
### Idempotent routes
Idempotence is a property of a route where the final state is achieved no matter how many times the route is called, that is, calling the route once or 10 times has the same effect. This is a useful property as it means the route can be safely retried if the request fails. For RESTful and HTTP APIs, the routes using GET, PUT, and DELETE verbs are expected to be idempotent.

View File

@ -3,7 +3,7 @@ name = "Todo_api"
version = "" version = ""
description = "" description = ""
authors = [ authors = [
{name = "Minh Tran Nhat", email = "minhtrannhat@minhtrannhat.com"}, {name = "Minh Tran Nhat", email = "minh@minhtrannhat.com"},
] ]
requires-python = ">=3.10" requires-python = ">=3.10"
license = {text = "Private"} license = {text = "Private"}
@ -58,7 +58,7 @@ ignore_missing_imports = true
[tool.pdm.scripts] [tool.pdm.scripts]
format-black = "black src/ tests/" format-black = "black src/ tests/"
format-djhtml = "djhtml src/backend/templates -t 2 --in-place" format-djhtml = "djhtml src/backend/templates -t 2"
format-isort = "isort src tests" format-isort = "isort src tests"
format = {composite = ["format-black", "format-djhtml", "format-isort"]} format = {composite = ["format-black", "format-djhtml", "format-isort"]}

View File

@ -29,7 +29,7 @@ async def select_todos(
WHERE member_id = :member_id WHERE member_id = :member_id
AND complete = :complete""" AND complete = :complete"""
values = {"member_id": member_id, "complete": complete} values = {"member_id": member_id, "complete": complete}
return [Todo(**row) async for row in await connection.iterate(query, values)] return [Todo(**row) async for row in connection.iterate(query, values)]
async def select_todo( async def select_todo(

View File

@ -115,6 +115,7 @@ def recreate_db() -> None:
"-U", "-U",
"postgres", "postgres",
"-c", "-c",
f"ALTER DATABASE {db_url.path.removeprefix('/')} OWNER TO {db_url.username}", f"ALTER DATABASE \
{db_url.path.removeprefix('/')} OWNER TO {db_url.username}",
] ]
) )

View File

@ -1,13 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Todo - email</title> <title>Todo - email</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head> </head>
<body style=" <body style="
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
font-size: 14px; font-size: 14px;
font-style: normal; font-style: normal;
@ -34,6 +34,6 @@
</td> </td>
</tr> </tr>
</table> </table>
</body> </body>
</html> </html>