Implement token management and authentication features with logging
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, HTTPException, Depends, Header
|
||||
import logging
|
||||
import db
|
||||
import api_security as auth
|
||||
from pydantic import BaseModel
|
||||
from api import tokens
|
||||
|
||||
|
||||
|
||||
|
||||
#Logging
|
||||
|
||||
logging.basicConfig(
|
||||
@@ -42,8 +46,11 @@ class Item_weight(BaseModel):
|
||||
class Item_piece(BaseModel):
|
||||
pieces: int
|
||||
|
||||
class Item_duration(BaseModel):
|
||||
duration: str
|
||||
|
||||
@router.post("/insert", status_code=201)
|
||||
def insert(item_name: Item_name, item_weight: Item_weight, item_pieces: Item_piece):
|
||||
def insert(item_name: Item_name, item_weight: Item_weight, item_pieces: Item_piece, token: str = Depends(tokens.check_token)):
|
||||
name = item_name.name_of_clothes.upper()
|
||||
weight = item_weight.weight
|
||||
pieces = item_pieces.pieces
|
||||
@@ -54,7 +61,7 @@ def insert(item_name: Item_name, item_weight: Item_weight, item_pieces: Item_pie
|
||||
|
||||
|
||||
@router.put("/update/{clothe_name}/pieces", status_code=202)
|
||||
def update_pieces(clothe_name: str, item_pieces: Item_piece):
|
||||
def update_pieces(clothe_name: str, item_pieces: Item_piece, token: str = Depends(tokens.check_token)):
|
||||
name = clothe_name.upper()
|
||||
pieces = item_pieces.pieces
|
||||
if db.check_clothe(name) != None:
|
||||
@@ -68,7 +75,7 @@ def update_pieces(clothe_name: str, item_pieces: Item_piece):
|
||||
|
||||
|
||||
@router.put("/update/{clothe_name}/weight", status_code=202)
|
||||
def update_weight(clothe_name: str, item: Item_weight):
|
||||
def update_weight(clothe_name: str, item: Item_weight, token: str = Depends(tokens.check_token)):
|
||||
name = clothe_name.upper()
|
||||
weight = item.weight
|
||||
if db.check_clothe(name) != None:
|
||||
@@ -82,7 +89,7 @@ def update_weight(clothe_name: str, item: Item_weight):
|
||||
|
||||
|
||||
@router.delete("/{clothe_name}/delete", status_code=204)
|
||||
def delete(clothe_name: str):
|
||||
def delete(clothe_name: str, token: str = Depends(tokens.check_token)):
|
||||
name = clothe_name.upper()
|
||||
if db.check_clothe(name) != None:
|
||||
db.delete(name)
|
||||
@@ -90,4 +97,6 @@ def delete(clothe_name: str):
|
||||
return {"message": "Item was deleted"}
|
||||
else:
|
||||
logging.error(f"Item {name} not found")
|
||||
raise HTTPException(status_code=404, detail=f"Item {name} not found")
|
||||
raise HTTPException(status_code=404, detail=f"Item {name} not found")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user