Skip to content

Commit

Permalink
Merge pull request #84 from Clochette-AbsINThe/dev
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
SamuelGuillemet authored Nov 29, 2022
2 parents 062f9bf + 89af3c0 commit 4052376
Show file tree
Hide file tree
Showing 79 changed files with 4,817 additions and 1,357 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
bump_version_scheme: patch
tag_prefix: v
release_name: <RELEASE_TAG>
max_commits: 10
max_commits: 25
- name: Check Output Parameters
run: |
echo "Got tag name ${{ steps.release.outputs.tag_name }}"
Expand Down
5 changes: 4 additions & 1 deletion README.md
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
7 changes: 6 additions & 1 deletion backend/app/api/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

import app.api.v1.endpoints as endpoints


endpoints_modules = [import_module('app.api.v1.endpoints.' + endpoint) for endpoint in endpoints.__all__]

api_v1_router = APIRouter()


for module in endpoints_modules:
api_v1_router.include_router(module.router, prefix="/{prefix}".format(prefix=module.__name__.split('.')[-1]))
api_v1_router.include_router(
module.router,
prefix="/{prefix}".format(prefix=module.__name__.split('.')[-1]),
)
2 changes: 2 additions & 0 deletions backend/app/api/v1/endpoints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
__all__ = [
'account',
'auth',
'barrel',
'consumable_item',
'consumable',
Expand Down
68 changes: 68 additions & 0 deletions backend/app/api/v1/endpoints/account.py
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)
31 changes: 31 additions & 0 deletions backend/app/api/v1/endpoints/auth.py
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
18 changes: 10 additions & 8 deletions backend/app/api/v1/endpoints/barrel.py
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)
10 changes: 5 additions & 5 deletions backend/app/api/v1/endpoints/consumable.py
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)
28 changes: 15 additions & 13 deletions backend/app/api/v1/endpoints/consumable_item.py
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)
28 changes: 15 additions & 13 deletions backend/app/api/v1/endpoints/drink.py
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)
Loading

0 comments on commit 4052376

Please sign in to comment.