27 lines
764 B
Python
27 lines
764 B
Python
from common.constants import CONFIG_KEYS
|
|
from common.serializers import ConfigSerializer
|
|
from common.utils import get_config
|
|
from rest_framework import status
|
|
from rest_framework.decorators import api_view
|
|
from rest_framework.response import Response
|
|
|
|
|
|
def get_all_configs():
|
|
return [get_config(key, value_only=False)._asdict() for key in CONFIG_KEYS]
|
|
|
|
|
|
@api_view(["GET"])
|
|
def configs(request, key=None):
|
|
if key:
|
|
if key not in CONFIG_KEYS:
|
|
return Response(status=status.HTTP_404_NOT_FOUND)
|
|
|
|
payload = ConfigSerializer(get_config(key, value_only=False)._asdict()).data
|
|
else:
|
|
payload = ConfigSerializer(get_all_configs(), many=True).data
|
|
|
|
return Response(
|
|
payload,
|
|
status=status.HTTP_200_OK,
|
|
)
|