-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from Clochette-AbsINThe/dev
v1.1.0
- Loading branch information
Showing
79 changed files
with
4,817 additions
and
1,357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# clochette | ||
# Clochette | ||
[![codecov](https://codecov.io/github/Clochette-AbsINThe/clochette/branch/dev/graph/badge.svg?token=331WWE1Q9N)](https://codecov.io/github/Clochette-AbsINThe/clochette) | ||
[![deploy](https://github.com/Clochette-AbsINThe/clochette/actions/workflows/deploy.yml/badge.svg)](https://github.com/Clochette-AbsINThe/clochette/actions/workflows/deploy.yml) | ||
|
||
Site Web pour la gestion du bar Absinthe de TSP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
__all__ = [ | ||
'account', | ||
'auth', | ||
'barrel', | ||
'consumable_item', | ||
'consumable', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from fastapi import APIRouter, Depends, HTTPException, status | ||
from typing import Any | ||
|
||
from app.core.security import get_password_hash | ||
from app.core.translation import Translator | ||
from app.crud.crud_account import account as accounts | ||
from app.dependencies import get_current_account, get_db | ||
from app.schemas import account as account_schema | ||
|
||
|
||
router = APIRouter(tags=["account"]) | ||
translator = Translator(element="account") | ||
|
||
|
||
@router.get("/", response_model=list[account_schema.Account], dependencies=[Depends(get_current_account)]) | ||
async def read_accounts(db=Depends(get_db)) -> list: | ||
return accounts.query(db) | ||
|
||
|
||
@router.post("/", response_model=account_schema.Account, dependencies=[Depends(get_current_account)]) | ||
async def create_account(account: account_schema.AccountCreate, db=Depends(get_db)) -> dict: | ||
if accounts.query(db, username=account.username, limit=1): | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail=translator.ELEMENT_ALREADY_EXISTS | ||
) | ||
account.password = get_password_hash(account.password) | ||
return accounts.create(db, obj_in=account) | ||
|
||
|
||
@router.get("/{account_id}", response_model=account_schema.Account, dependencies=[Depends(get_current_account)]) | ||
async def read_account(account_id: int, db=Depends(get_db)) -> Any: | ||
account = accounts.read(db, account_id) | ||
if account is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
return account | ||
|
||
|
||
@router.put("/{account_id}", response_model=account_schema.Account, dependencies=[Depends(get_current_account)]) | ||
async def update_account(account_id: int, account: account_schema.AccountUpdate, db=Depends(get_db)): | ||
old_account = accounts.read(db, account_id) | ||
if old_account is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
results = accounts.query(db, username=account.username, limit=None) | ||
if results and results[0].id != old_account.id: | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail=translator.ELEMENT_ALREADY_EXISTS | ||
) | ||
account.password = get_password_hash(account.password) | ||
return accounts.update(db, db_obj=old_account, obj_in=account) | ||
|
||
|
||
@router.delete("/{account_id}", response_model=account_schema.Account, dependencies=[Depends(get_current_account)]) | ||
async def delete_account(account_id: int, db=Depends(get_db)) -> Any: | ||
account = accounts.read(db, account_id) | ||
if account is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
return accounts.delete(db, account_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from fastapi.security import OAuth2PasswordRequestForm | ||
from fastapi import APIRouter, Depends, HTTPException, status | ||
from typing import Any | ||
|
||
from app.core.security import create_access_token, verify_password | ||
from app.core.translation import Translator | ||
from app.crud.crud_account import account as accounts | ||
from app.dependencies import get_current_account, get_db | ||
from app.schemas import account as account_schema | ||
from app.schemas import token as token_schema | ||
|
||
|
||
router = APIRouter(tags=["auth"]) | ||
translator = Translator(element="auth") | ||
|
||
|
||
@router.post("/login/", response_model=token_schema.Token) | ||
async def login(form_data: OAuth2PasswordRequestForm = Depends(), db = Depends(get_db)) -> Any: | ||
account = (accounts.query(db, username=form_data.username, limit=1)[0:1] or [None])[0] | ||
if account is None or not verify_password(form_data.password, account.password): | ||
raise HTTPException( | ||
status_code=status.HTTP_401_UNAUTHORIZED, | ||
detail=translator.INVALID_CREDENTIALS, | ||
headers={"WWW-Authenticate": "Bearer"}, | ||
) | ||
return {'access_token': create_access_token(subject=account.username)} | ||
|
||
|
||
@router.get("/me/", response_model=account_schema.Account) | ||
def read_account_me(current_account: account_schema.Account = Depends(get_current_account)) -> Any: | ||
return current_account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
from fastapi import APIRouter, Depends, HTTPException, status | ||
|
||
from app.core.translation import Translator | ||
from app.crud.crud_barrel import barrel as barrels | ||
from app.dependencies import get_db | ||
from app.dependencies import get_current_account, get_db | ||
from app.schemas import barrel as barrel_schema | ||
|
||
|
||
router = APIRouter() | ||
router = APIRouter(tags=["barrel"]) | ||
translator = Translator(element="barrel") | ||
|
||
|
||
@router.get("/", response_model=list[barrel_schema.Barrel]) | ||
@router.get("/", response_model=list[barrel_schema.Barrel], dependencies=[Depends(get_current_account)]) | ||
async def read_barrels(db=Depends(get_db)) -> list: | ||
return barrels.query(db, empty=False, limit=None) | ||
|
||
|
||
@router.get("/mounted/", response_model=list[barrel_schema.Barrel]) | ||
@router.get("/mounted/", response_model=list[barrel_schema.Barrel], dependencies=[Depends(get_current_account)]) | ||
async def read_mounted_barrels(db=Depends(get_db)) -> list: | ||
return barrels.query(db, is_mounted=True, empty=False, limit=None) | ||
|
||
|
||
@router.get("/distincts/", response_model=list[barrel_schema.Barrel]) | ||
@router.get("/distincts/", response_model=list[barrel_schema.Barrel], dependencies=[Depends(get_current_account)]) | ||
async def read_distincts_barrels(db=Depends(get_db)) -> list: | ||
return barrels.query(db, distinct='drink_id', empty=False, limit=None) | ||
|
||
|
||
@router.get("/all/", response_model=list[barrel_schema.Barrel]) | ||
@router.get("/all/", response_model=list[barrel_schema.Barrel], dependencies=[Depends(get_current_account)]) | ||
async def read_all_barrels(db=Depends(get_db)) -> list: | ||
return barrels.query(db, limit=None) | ||
|
||
|
||
@router.put("/{barrel_id}", response_model=barrel_schema.Barrel) | ||
@router.put("/{barrel_id}", response_model=barrel_schema.Barrel, dependencies=[Depends(get_current_account)]) | ||
async def update_barrel(barrel_id: int, barrel: barrel_schema.BarrelUpdate, db=Depends(get_db)) -> barrel_schema.Barrel: | ||
db_barrel = barrels.read(db, barrel_id) | ||
if db_barrel is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail="Barrel not found" | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
return barrels.update(db, db_obj=db_barrel, obj_in=barrel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
from fastapi import APIRouter, Depends | ||
|
||
from app.crud.crud_consumable import consumable as consumables | ||
from app.dependencies import get_db | ||
from app.dependencies import get_current_account, get_db | ||
from app.schemas import consumable as consumable_schema | ||
|
||
|
||
router = APIRouter() | ||
router = APIRouter(tags=["consumable"]) | ||
|
||
|
||
@router.get("/", response_model=list[consumable_schema.Consumable]) | ||
@router.get("/", response_model=list[consumable_schema.Consumable], dependencies=[Depends(get_current_account)]) | ||
async def read_consumables(db=Depends(get_db)) -> list: | ||
return consumables.query(db, empty=False, limit=None) | ||
|
||
|
||
@router.get("/distincts/", response_model=list[consumable_schema.Consumable]) | ||
@router.get("/distincts/", response_model=list[consumable_schema.Consumable], dependencies=[Depends(get_current_account)]) | ||
async def read_consumables_distincts(db=Depends(get_db)) -> list: | ||
return consumables.query(db, distinct='consumable_item_id', empty=False, limit=None) | ||
|
||
|
||
@router.get("/all/", response_model=list[consumable_schema.Consumable]) | ||
@router.get("/all/", response_model=list[consumable_schema.Consumable], dependencies=[Depends(get_current_account)]) | ||
async def read_all_consumables(db=Depends(get_db)) -> list: | ||
return consumables.query(db, limit=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,70 @@ | ||
from fastapi import APIRouter, Depends, HTTPException, status | ||
from typing import Any | ||
|
||
from app.core.translation import Translator | ||
from app.crud.crud_consumable_item import consumable_item as consumable_items | ||
from app.crud.crud_consumable import consumable as consumables | ||
from app.dependencies import get_db | ||
from app.dependencies import get_current_account, get_db | ||
from app.schemas import consumable_item as consumable_item_schema | ||
|
||
|
||
router = APIRouter() | ||
router = APIRouter(tags=["consumable_item"]) | ||
translator = Translator(element="consumable_item") | ||
|
||
|
||
@router.get("/", response_model=list[consumable_item_schema.ConsumableItem]) | ||
@router.get("/", response_model=list[consumable_item_schema.ConsumableItem], dependencies=[Depends(get_current_account)]) | ||
async def read_consumable_items(db=Depends(get_db)) -> list: | ||
return consumable_items.read_multi(db) | ||
|
||
|
||
@router.post("/", response_model=consumable_item_schema.ConsumableItem) | ||
@router.post("/", response_model=consumable_item_schema.ConsumableItem, dependencies=[Depends(get_current_account)]) | ||
async def create_consumable_item(consumable_item: consumable_item_schema.ConsumableItemCreate, db=Depends(get_db)) -> dict: | ||
if consumable_items.query(db, name=consumable_item.name, limit=1): | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="Consumable item already exists" | ||
detail=translator.ELEMENT_ALREADY_EXISTS | ||
) | ||
return consumable_items.create(db, obj_in=consumable_item) | ||
|
||
|
||
@router.get("/{consumable_item_id}", response_model=consumable_item_schema.ConsumableItem) | ||
@router.get("/{consumable_item_id}", response_model=consumable_item_schema.ConsumableItem, dependencies=[Depends(get_current_account)]) | ||
async def read_consumable_item(consumable_item_id: int, db=Depends(get_db)) -> Any: | ||
consumable_item = consumable_items.read(db, consumable_item_id) | ||
if consumable_item is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail="Consumable item not found" | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
return consumable_item | ||
|
||
|
||
@router.put("/{consumable_item_id}", response_model=consumable_item_schema.ConsumableItem) | ||
@router.put("/{consumable_item_id}", response_model=consumable_item_schema.ConsumableItem, dependencies=[Depends(get_current_account)]) | ||
async def update_consumable_item(consumable_item_id: int, consumable_item: consumable_item_schema.ConsumableItemUpdate, db=Depends(get_db)): | ||
old_consumable_item = consumable_items.read(db, consumable_item_id) | ||
if old_consumable_item is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail="Consumabel item not found" | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
results = consumable_items.query(db, name=consumable_item.name, limit=None) | ||
if results and results[0].id != old_consumable_item.id: | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="Consumable item already exists" | ||
detail=translator.ELEMENT_ALREADY_EXISTS | ||
) | ||
return consumable_items.update(db, db_obj=old_consumable_item, obj_in=consumable_item) | ||
|
||
|
||
@router.delete("/{consumable_item_id}", response_model=consumable_item_schema.ConsumableItem) | ||
@router.delete("/{consumable_item_id}", response_model=consumable_item_schema.ConsumableItem, dependencies=[Depends(get_current_account)]) | ||
async def delete_consumable_item(consumable_item_id: int, db=Depends(get_db)): | ||
if consumable_items.read(db, consumable_item_id) is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail="Consumable item not found" | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
if consumables.query(db, consumable_item_id=consumable_item_id, limit=1): | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="Consumable item is in use" | ||
detail=translator.DELETION_OF_USED_ELEMENT | ||
) | ||
return consumable_items.delete(db, id=consumable_item_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,71 @@ | ||
from fastapi import APIRouter, Depends, HTTPException, status | ||
from typing import Any | ||
|
||
from app.core.translation import Translator | ||
from app.crud.crud_barrel import barrel as barrels | ||
from app.crud.crud_drink import drink as drinks | ||
from app.dependencies import get_db | ||
from app.dependencies import get_current_account, get_db | ||
from app.schemas import drink as drink_schema | ||
|
||
|
||
router = APIRouter() | ||
router = APIRouter(tags=["drink"]) | ||
translator = Translator(element="drink") | ||
|
||
|
||
@router.get("/{drink_id}", response_model=drink_schema.Drink) | ||
@router.get("/{drink_id}", response_model=drink_schema.Drink, dependencies=[Depends(get_current_account)]) | ||
async def read_drink(drink_id: int, db=Depends(get_db)) -> Any: | ||
drink = drinks.read(db, drink_id) | ||
if drink is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail="Drink not found" | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
return drink | ||
|
||
|
||
@router.get("/", response_model=list[drink_schema.Drink]) | ||
@router.get("/", response_model=list[drink_schema.Drink], dependencies=[Depends(get_current_account)]) | ||
async def read_drinks(db=Depends(get_db)): | ||
return drinks.read_multi(db) | ||
|
||
|
||
@router.post("/", response_model=drink_schema.Drink) | ||
@router.post("/", response_model=drink_schema.Drink, dependencies=[Depends(get_current_account)]) | ||
async def create_drink(drink: drink_schema.DrinkCreate, db=Depends(get_db)) -> dict: | ||
# Check if drink already exists | ||
if drinks.query(db, name=drink.name, limit=1): | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="Drink already exists" | ||
detail=translator.ELEMENT_ALREADY_EXISTS | ||
) | ||
return drinks.create(db, obj_in=drink) | ||
|
||
|
||
@router.put("/{drink_id}", response_model=drink_schema.Drink) | ||
@router.put("/{drink_id}", response_model=drink_schema.Drink, dependencies=[Depends(get_current_account)]) | ||
async def update_drink(drink_id: int, drink: drink_schema.DrinkUpdate, db=Depends(get_db)): | ||
old_drink = drinks.read(db, drink_id) | ||
if old_drink is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail="Drink not found" | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
results = drinks.query(db, name=drink.name, limit=None) | ||
if results and results[0].id != old_drink.id: | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="Consumable item already exists" | ||
detail=translator.ELEMENT_ALREADY_EXISTS | ||
) | ||
return drinks.update(db, db_obj=old_drink, obj_in=drink) | ||
|
||
|
||
@router.delete("/{drink_id}", response_model=drink_schema.Drink) | ||
@router.delete("/{drink_id}", response_model=drink_schema.Drink, dependencies=[Depends(get_current_account)]) | ||
async def delete_drink(drink_id: int, db=Depends(get_db)): | ||
if drinks.read(db, drink_id) is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, | ||
detail="Drink not found" | ||
detail=translator.ELEMENT_NOT_FOUND | ||
) | ||
if barrels.query(db, drink_id=drink_id, limit=1): | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="Drink is in use" | ||
detail=translator.DELETION_OF_USED_ELEMENT | ||
) | ||
return drinks.delete(db, id=drink_id) |
Oops, something went wrong.