[rewrite] Added initial route structure (WIP)

This commit is contained in:
Thastertyn 2024-12-02 21:15:25 +01:00
parent bb789a75e7
commit 3d00ae0aad
7 changed files with 105 additions and 22 deletions

4
backend/app/.mypy.ini Normal file
View File

@ -0,0 +1,4 @@
[mypy]
files = app/
plugins = sqlmypy
ignore_missing_imports = True

View File

@ -1,29 +1,29 @@
from flask import Flask # from flask import Flask
from flask_jwt_extended import JWTManager # from flask_jwt_extended import JWTManager
from flask_mail import Mail # from flask_mail import Mail
from flasgger import Swagger # from flasgger import Swagger
from app.doc.main_swag import main_swagger # from app.doc.main_swag import main_swagger
app = Flask(__name__) # app = Flask(__name__)
from app.config import FlaskTesting, FlaskProduction # from app.config import FlaskTesting, FlaskProduction
app.config.from_object(FlaskTesting) # app.config.from_object(FlaskTesting)
flask_mail = Mail(app) # flask_mail = Mail(app)
jwt_manager = JWTManager(app) # jwt_manager = JWTManager(app)
swag = Swagger(app, template=main_swagger) # swag = Swagger(app, template=main_swagger)
def create_app(): # def create_app():
from app.api import bp, bp_errors, bp_product, bp_user, bp_cart # from app.api import bp, bp_errors, bp_product, bp_user, bp_cart
app.register_blueprint(bp) # app.register_blueprint(bp)
app.register_blueprint(bp_errors) # app.register_blueprint(bp_errors)
app.register_blueprint(bp_product) # app.register_blueprint(bp_product)
app.register_blueprint(bp_user) # app.register_blueprint(bp_user)
app.register_blueprint(bp_cart) # app.register_blueprint(bp_cart)
from . import jwt_utils # from . import jwt_utils
return app # return app

View File

@ -1,6 +1,16 @@
from fastapi import FastAPI from fastapi import FastAPI
from .routes.cart_routes import router as cart_router
from .routes.user_routes import router as user_router
app = FastAPI(
title="SWAG Shop",
version="0.0.1"
)
app.include_router(user_router)
app.include_router(cart_router)
app = FastAPI()
@app.get("/") @app.get("/")
async def root(): async def root():

View File

View File

@ -0,0 +1,38 @@
from fastapi import APIRouter, Query
router = APIRouter(
prefix="/cart",
tags=["Cart"]
)
@router.get("/")
async def show_cart():
raise NotImplementedError
@router.put("/add/{product_id}")
async def add_to_cart(
product_id: int,
count: int = Query(
1, ge=1, description="Count must be greater than or equal to 1")
):
raise NotImplementedError
@router.delete("/remove/{product_id}")
async def remove_from_cart(product_id: int):
raise NotImplementedError
@router.put("/update/{product_id}")
async def update_count_in_cart(
product_id: int,
count: int = Query(..., description="Count must be provided")
):
raise NotImplementedError
@router.get("/purchase")
async def purchase():
raise NotImplementedError

View File

View File

@ -0,0 +1,31 @@
from fastapi import APIRouter, Body
router = APIRouter(
prefix="/user",
tags=["User"]
)
@router.delete("/delete", summary="Delete user")
async def delete_user():
raise NotImplementedError("delete_user() needs to be implemented.")
@router.post("/login", summary="User login")
async def login(data: dict = Body(...)):
raise NotImplementedError("login() needs to be implemented.")
@router.delete("/logout", summary="User logout")
async def logout():
raise NotImplementedError("logout() needs to be implemented.")
@router.post("/register", summary="Register new user")
async def register(data: dict = Body(...)):
raise NotImplementedError("register() needs to be implemented.")
@router.put("/update", summary="Update user details")
async def update_user(data: dict = Body(...)):
raise NotImplementedError("update_user() needs to be implemented.")