54 lines
1.1 KiB
Python
54 lines
1.1 KiB
Python
from time import time
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from app import mongo
|
|
from app.utils.response_util import response
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/", tags=[""])
|
|
async def post(params: dict):
|
|
start_time = time()
|
|
data = params["status"]
|
|
|
|
data["id"] = await mongo.get_next_id(mongo.statuses_collection)
|
|
await mongo.statuses_collection.insert_one(data)
|
|
|
|
return response({
|
|
"message": "Статус создан",
|
|
"ok": True
|
|
}, start_time=start_time)
|
|
|
|
|
|
@router.patch("/", tags=[""])
|
|
async def patch(params: dict):
|
|
start_time = time()
|
|
data = params["status"]
|
|
|
|
await mongo.statuses_collection.update_one({
|
|
"id": data["id"]
|
|
}, {
|
|
"$set": data
|
|
})
|
|
|
|
return response({
|
|
"message": "Статус обновлен",
|
|
"ok": True
|
|
}, start_time=start_time)
|
|
|
|
|
|
@router.delete("/{status_id}", tags=[""])
|
|
async def delete(status_id: int):
|
|
start_time = time()
|
|
|
|
await mongo.statuses_collection.delete_one({
|
|
"id": status_id
|
|
})
|
|
|
|
return response({
|
|
"message": "Статус удален",
|
|
"ok": True
|
|
}, start_time=start_time)
|