2024-07-18 18:23:30 +00:00
|
|
|
#
|
|
|
|
# Copyright 2024 AE UTBM
|
|
|
|
# ae@utbm.fr / ae.info@utbm.fr
|
|
|
|
#
|
|
|
|
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
|
|
|
# https://ae.utbm.fr.
|
|
|
|
#
|
2024-09-22 23:37:25 +00:00
|
|
|
# You can find the source code of the website at https://github.com/ae-utbm/sith
|
2024-07-18 18:23:30 +00:00
|
|
|
#
|
|
|
|
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
2024-09-23 08:25:27 +00:00
|
|
|
# SEE : https://raw.githubusercontent.com/ae-utbm/sith/master/LICENSE
|
2024-07-18 18:23:30 +00:00
|
|
|
# OR WITHIN THE LOCAL FILE "LICENSE"
|
|
|
|
#
|
|
|
|
#
|
|
|
|
from ninja_extra import ControllerBase, api_controller, route
|
|
|
|
|
|
|
|
from core.api_permissions import CanView, IsRoot
|
|
|
|
from counter.models import Counter
|
|
|
|
from counter.schemas import CounterSchema
|
|
|
|
|
|
|
|
|
|
|
|
@api_controller("/counter")
|
|
|
|
class CounterController(ControllerBase):
|
|
|
|
@route.get("", response=list[CounterSchema], permissions=[IsRoot])
|
|
|
|
def fetch_all(self):
|
2024-10-09 22:06:22 +00:00
|
|
|
return Counter.objects.annotate_is_open()
|
2024-07-18 18:23:30 +00:00
|
|
|
|
|
|
|
@route.get("{counter_id}/", response=CounterSchema, permissions=[CanView])
|
|
|
|
def fetch_one(self, counter_id: int):
|
2024-10-09 22:06:22 +00:00
|
|
|
return self.get_object_or_exception(
|
|
|
|
Counter.objects.annotate_is_open(), pk=counter_id
|
|
|
|
)
|
2024-07-18 18:23:30 +00:00
|
|
|
|
|
|
|
@route.get("bar/", response=list[CounterSchema], permissions=[CanView])
|
|
|
|
def fetch_bars(self):
|
2024-10-09 22:06:22 +00:00
|
|
|
counters = list(Counter.objects.annotate_is_open().filter(type="BAR"))
|
2024-07-18 18:23:30 +00:00
|
|
|
for c in counters:
|
|
|
|
self.check_object_permissions(c)
|
|
|
|
return counters
|