File size: 1,386 Bytes
9002555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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