Spaces:
Sleeping
Sleeping
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) | |
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} | |
async def get_metadata(): | |
results = await get_data(db_conn) | |
return results | |
async def update_metadata(id: int, reference: MetadataRequest): | |
response = await update_data(id, reference, db_conn) | |
return response | |
async def delete_metadata(id: int): | |
response = await delete_data(id, db_conn) | |
return response | |