Skip to content

Commit 57f638d

Browse files
committed
Backend: Día 5
1 parent 3445755 commit 57f638d

File tree

15 files changed

+132
-19
lines changed

15 files changed

+132
-19
lines changed
113 Bytes
Binary file not shown.
Binary file not shown.

Backend/FastAPI/db/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Clase en vídeo (22/12/2022): https://www.twitch.tv/videos/1686104006
2+
3+
### MongoDB client ###
4+
5+
# Descarga versión community: https://www.mongodb.com/try/download
6+
# Instalación:https://www.mongodb.com/docs/manual/tutorial
7+
# Módulo conexión MongoDB: pip install pymongo
8+
# Ejecución: sudo mongod --dbpath "/path/a/la/base/de/datos/"
9+
# Conexión: mongodb://localhost
10+
11+
from pymongo import MongoClient
12+
13+
db_client = MongoClient()
Binary file not shown.

Backend/FastAPI/db/models/user.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Clase en vídeo (22/12/2022): https://www.twitch.tv/videos/1686104006
2+
3+
### User model ###
4+
5+
from pydantic import BaseModel
6+
7+
8+
class User(BaseModel):
9+
id: str | None
10+
username: str
11+
email: str
Binary file not shown.

Backend/FastAPI/db/schemas/user.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Clase en vídeo (22/12/2022): https://www.twitch.tv/videos/1686104006
2+
3+
### User schema ###
4+
5+
def user_schema(user) -> dict:
6+
return {"id": str(user["_id"]),
7+
"username": user["username"],
8+
"email": user["email"]}
9+
10+
11+
def users_schema(users) -> list:
12+
return [user_schema(user) for user in users]

Backend/FastAPI/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Instala FastAPI: pip install "fastapi[all]"
88

99
from fastapi import FastAPI
10-
from routers import products, users
10+
from routers import products, users, basic_auth_users, jwt_auth_users, users_db
1111
from fastapi.staticfiles import StaticFiles
1212

1313
app = FastAPI()
@@ -16,6 +16,11 @@
1616
app.include_router(products.router)
1717
app.include_router(users.router)
1818

19+
# Routers - Clase en vídeo (22/12/2022): https://www.twitch.tv/videos/1686104006
20+
app.include_router(basic_auth_users.router)
21+
app.include_router(jwt_auth_users.router)
22+
app.include_router(users_db.router)
23+
1924
# Recursos estáticos - Clase en vídeo (14/12/2022): https://www.twitch.tv/videos/1679022882
2025
app.mount("/static", StaticFiles(directory="static"), name="static")
2126

Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)