[rewrite] Changes services to crud, modified routes abit
This commit is contained in:
1 parent
543aadf521
commit
f5547be799
21 files changed
+126
-29
No files matched your search
@@ -6,11 +6,14 @@ from fastapi.security import OAuth2PasswordRequestForm
|
||||
|
||||
from app.api.dependencies import SessionDep
|
||||
|
||||
from app.schemas.user_schemas import Token
|
||||
|
||||
from app.core import security
|
||||
from app.core.config import settings
|
||||
|
||||
from app.schemas.user_schemas import Token
|
||||
|
||||
from app.crud import user_crud
|
||||
|
||||
|
||||
router = APIRouter(tags=["login"])
|
||||
|
||||
|
||||
@@ -22,9 +25,9 @@ def login_access_token(
|
||||
OAuth2 compatible token login, get an access token for future requests
|
||||
"""
|
||||
user = None
|
||||
# user = crud.authenticate(
|
||||
# session=session, email=form_data.username, password=form_data.password
|
||||
# )
|
||||
user = user_crud.authenticate(
|
||||
session=session, email=form_data.username, password=form_data.password, shop_id=None
|
||||
)
|
||||
if not user:
|
||||
raise HTTPException(status_code=400, detail="Incorrect email or password")
|
||||
elif not user:
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api.routes.shop import shop_login_routes, shop_user_routes
|
||||
|
||||
api_router = APIRouter()
|
||||
|
||||
api_router.include_router(shop_login_routes.router)
|
||||
api_router.include_router(shop_user_routes.router)
|
||||
@@ -0,0 +1,41 @@
|
||||
from typing import Annotated
|
||||
from datetime import timedelta
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
|
||||
from app.api.dependencies import SessionDep
|
||||
|
||||
from app.core import security
|
||||
from app.core.config import settings
|
||||
|
||||
from app.schemas.user_schemas import Token
|
||||
|
||||
from app.crud import user_crud
|
||||
|
||||
|
||||
router = APIRouter(tags=["Shop-Login"])
|
||||
|
||||
|
||||
@router.post("/login/access-token")
|
||||
def login_access_token(
|
||||
session: SessionDep,
|
||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
|
||||
) -> Token:
|
||||
"""
|
||||
OAuth2 compatible token login, get an access token for future requests
|
||||
"""
|
||||
user = None
|
||||
user = user_crud.authenticate(
|
||||
session=session, email=form_data.username, password=form_data.password, shop_id=None
|
||||
)
|
||||
if not user:
|
||||
raise HTTPException(status_code=400, detail="Incorrect email or password")
|
||||
elif not user:
|
||||
raise HTTPException(status_code=400, detail="Inactive user")
|
||||
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||
return Token(
|
||||
access_token=security.create_access_token(
|
||||
user.id, expires_delta=access_token_expires
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,37 @@
|
||||
import uuid
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Body, Path
|
||||
|
||||
from app.schemas.user_schemas import UserRegisterSchema, UserLoginSchema
|
||||
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/user",
|
||||
tags=["Shop-Users"]
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/delete", summary="Delete user")
|
||||
async def delete_user(shop_uuid=Annotated[uuid.UUID, Path(title="UUID of the shop")]):
|
||||
raise NotImplementedError("delete_user() needs to be implemented.")
|
||||
|
||||
|
||||
@router.post("/login", summary="User login")
|
||||
async def login(login_data: UserLoginSchema, shop_uuid=Annotated[uuid.UUID, Path(title="UUID of the shop")]):
|
||||
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(user_data: UserRegisterSchema):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@router.put("/update", summary="Update user details")
|
||||
async def update_user(data: dict = Body(...)):
|
||||
raise NotImplementedError("update_user() needs to be implemented.")
|
||||
@@ -1,11 +1,14 @@
|
||||
from fastapi import APIRouter
|
||||
import uuid
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Path
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/shop",
|
||||
prefix="/shop/{shop_uuid}",
|
||||
tags=["Shop"]
|
||||
)
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def get_shop_info():
|
||||
@router.get("/login")
|
||||
async def get_shop_info(shop_uuid=Annotated[uuid.UUID, Path(title="UUID of the shop")]):
|
||||
raise NotImplementedError
|
||||
@@ -2,7 +2,6 @@ from fastapi import APIRouter, Body
|
||||
|
||||
from app.schemas.user_schemas import UserRegisterSchema, UserLoginSchema
|
||||
|
||||
from app.services.user_service import create_user
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/user",
|
||||
|
||||
Reference in new issue
Block a user