44 lines
986 B
Python
44 lines
986 B
Python
import json
|
|
|
|
from fastapi import APIRouter, Response, status
|
|
from pydantic import BaseModel
|
|
|
|
import backend.elastic as elastic
|
|
import backend.mongo as mongo
|
|
from api.middleware.verify_token import VerifyTokenRoute
|
|
|
|
document_routes = APIRouter(route_class=VerifyTokenRoute)
|
|
|
|
|
|
class Document(BaseModel):
|
|
name: str
|
|
access: list
|
|
data: str
|
|
owner: str
|
|
|
|
|
|
class Data(BaseModel):
|
|
data: str
|
|
|
|
|
|
@document_routes.post("/document/create")
|
|
def create(aux: Document, response: Response):
|
|
mongo.create_document(json.loads(json.dumps(aux.__dict__)))
|
|
response.status_code = status.HTTP_201_CREATED
|
|
|
|
|
|
@document_routes.get("/document/{id}")
|
|
def get_by_id(id: str):
|
|
return mongo.get_document_by_id(id)
|
|
|
|
|
|
@document_routes.put("/document/{id}")
|
|
def edit_data(data: Data, id: str, response: Response):
|
|
mongo.edit_data(id, data.data)
|
|
response.status_code = status.HTTP_202_ACCEPTED
|
|
|
|
|
|
@document_routes.get("/document")
|
|
def search():
|
|
return elastic.search("test-index")
|