From bc859c63f5751c4e56234076f177d61874125be6 Mon Sep 17 00:00:00 2001 From: Kurbanov Bulat Date: Sun, 9 Jan 2022 01:48:36 +0300 Subject: [PATCH] Add update service status endpoint --- src/app/views.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/views.py b/src/app/views.py index 6ef9848..43240c9 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -2,7 +2,7 @@ from fastapi import APIRouter, HTTPException, status, Depends from app.depends import check_token from app.serializers import ServiceCreate, ServiceDetail -from app.models import Service +from app.models import Service, Statuses # TODO: add redis cache @@ -31,3 +31,17 @@ async def get_service(id: int): @router.post("/", response_model=ServiceDetail) async def register_service(data: ServiceCreate): return await Service.objects.create(**data.dict()) + + +@router.patch("/{id}/update_status") +async def update_service_state(id: int, new_status: Statuses): + service = await Service.objects.get_or_none(id=id) + + if service is None: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) + + service.status = new_status + + await service.update(['status']) + + return service