first commit
This commit is contained in:
53
app/api/v1/status.py
Normal file
53
app/api/v1/status.py
Normal file
@ -0,0 +1,53 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user