._.
This commit is contained in:
parent
293a173b30
commit
9ddfe3b102
@ -1,23 +1,23 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fastapi import APIRouter, HTTPException, Depends
|
from fastapi import APIRouter, HTTPException, Depends
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.core.entities.accessory import AccessoryEntity
|
from app.core.entities.accessory import AccessoryEntity
|
||||||
from app.core.usecases.accessory_service import AccessoriesService
|
from app.core.usecases.accessory_service import AccessoriesService
|
||||||
from app.infrastructure.database.dependencies import get_db
|
from app.infrastructure.database.dependencies import get_db
|
||||||
|
from app.core.usecases.auth_service import verify_token
|
||||||
|
from app.infrastructure.database.models.users import User
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/accessories", response_model=List[AccessoryEntity])
|
@router.get("/accessories", response_model=List[AccessoryEntity])
|
||||||
def read_accessories(db: Session = Depends(get_db)):
|
def read_accessories(db: Session = Depends(get_db), current_user: User = Depends(verify_token)):
|
||||||
service = AccessoriesService(db)
|
service = AccessoriesService(db)
|
||||||
return service.get_all_accessories()
|
return service.get_all_accessories()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/accessories/{accessory_id}", response_model=AccessoryEntity)
|
@router.get("/accessories/{accessory_id}", response_model=AccessoryEntity)
|
||||||
def read_accessory(accessory_id: int, db: Session = Depends(get_db)):
|
def read_accessory(accessory_id: int, db: Session = Depends(get_db), current_user: User = Depends(verify_token)):
|
||||||
service = AccessoriesService(db)
|
service = AccessoriesService(db)
|
||||||
accessory = service.get_accessory_by_id(accessory_id)
|
accessory = service.get_accessory_by_id(accessory_id)
|
||||||
if accessory is None:
|
if accessory is None:
|
||||||
@ -26,13 +26,15 @@ def read_accessory(accessory_id: int, db: Session = Depends(get_db)):
|
|||||||
|
|
||||||
|
|
||||||
@router.post("/accessories", response_model=AccessoryEntity)
|
@router.post("/accessories", response_model=AccessoryEntity)
|
||||||
def create_accessory(accessory: AccessoryEntity, db: Session = Depends(get_db)):
|
def create_accessory(accessory: AccessoryEntity, db: Session = Depends(get_db),
|
||||||
|
current_user: User = Depends(verify_token)):
|
||||||
service = AccessoriesService(db)
|
service = AccessoriesService(db)
|
||||||
return service.create_accessory(accessory)
|
return service.create_accessory(accessory)
|
||||||
|
|
||||||
|
|
||||||
@router.put("/accessories/{accessory_id}", response_model=AccessoryEntity)
|
@router.put("/accessories/{accessory_id}", response_model=AccessoryEntity)
|
||||||
def update_accessory(accessory_id: int, accessory: AccessoryEntity, db: Session = Depends(get_db)):
|
def update_accessory(accessory_id: int, accessory: AccessoryEntity, db: Session = Depends(get_db),
|
||||||
|
current_user: User = Depends(verify_token)):
|
||||||
service = AccessoriesService(db)
|
service = AccessoriesService(db)
|
||||||
updated_accessory = service.update_accessory(accessory_id, accessory)
|
updated_accessory = service.update_accessory(accessory_id, accessory)
|
||||||
if updated_accessory is None:
|
if updated_accessory is None:
|
||||||
@ -41,7 +43,7 @@ def update_accessory(accessory_id: int, accessory: AccessoryEntity, db: Session
|
|||||||
|
|
||||||
|
|
||||||
@router.delete("/accessories/{accessory_id}", response_model=bool)
|
@router.delete("/accessories/{accessory_id}", response_model=bool)
|
||||||
def delete_accessory(accessory_id: int, db: Session = Depends(get_db)):
|
def delete_accessory(accessory_id: int, db: Session = Depends(get_db), current_user: User = Depends(verify_token)):
|
||||||
service = AccessoriesService(db)
|
service = AccessoriesService(db)
|
||||||
success = service.delete_accessory(accessory_id)
|
success = service.delete_accessory(accessory_id)
|
||||||
if not success:
|
if not success:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user