dsmultimedika's picture
Build Application
9002555
raw
history blame
1.39 kB
from fastapi import Form, APIRouter, File, UploadFile, HTTPException, Request
from db.repository import get_db_conn
from config import MYSQL_CONFIG
from api.function import data_ingestion, get_data, delete_data, update_data
from service.dto import MetadataRequest
router = APIRouter(tags=["Topics"])
db_conn = get_db_conn(MYSQL_CONFIG)
@router.post("/topic")
async def upload_file(
title: str = Form(...),
author: str = Form(...),
category: str = Form(...),
year: int = Form(...),
publisher: str = Form(...),
file: UploadFile = File(...),
# content_table: UploadFile = File(...)
):
reference = {
"title": title,
"author": author,
"category": category,
"year": year,
"publisher": publisher,
}
# response = await data_ingestion(db_conn, reference, file, content_table)
response = await data_ingestion(db_conn, reference, file)
return {"filename": file.filename, "response": response}
@router.get("/topic")
async def get_metadata():
results = await get_data(db_conn)
return results
@router.put("/topic/{id}")
async def update_metadata(id: int, reference: MetadataRequest):
response = await update_data(id, reference, db_conn)
return response
@router.delete("/topic/{id}")
async def delete_metadata(id: int):
response = await delete_data(id, db_conn)
return response