|
|
|
|
@ -3,7 +3,7 @@ from re import IGNORECASE, sub as substitute
|
|
|
|
|
from typing import List, Optional
|
|
|
|
|
from urllib.parse import unquote_plus
|
|
|
|
|
|
|
|
|
|
from fastapi import Depends, FastAPI, File, HTTPException, UploadFile
|
|
|
|
|
from fastapi import Depends, FastAPI, File, HTTPException, UploadFile, status
|
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
|
|
|
|
from . import crud, models, schemas, spreadsheet
|
|
|
|
|
@ -58,7 +58,7 @@ def create_items(file: UploadFile = File(...), db: Session = Depends(get_db)):
|
|
|
|
|
)
|
|
|
|
|
if unknown_headers:
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=422,
|
|
|
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
|
|
|
detail="Unknown headers in the spreadsheet: {}. Missing headers from the database: {}. Check the coordinated format".format(
|
|
|
|
|
unknown_headers, missing_headers
|
|
|
|
|
),
|
|
|
|
|
@ -81,11 +81,13 @@ def create_items(file: UploadFile = File(...), db: Session = Depends(get_db)):
|
|
|
|
|
|
|
|
|
|
except spreadsheet.InvalidFileException:
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=422, detail="Invalid file upload (expected .xlsx)"
|
|
|
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
|
|
|
detail="Invalid file upload (expected .xlsx)",
|
|
|
|
|
)
|
|
|
|
|
except spreadsheet.DataInUnnamedColumnException:
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=422, detail="Data is found in a column with empty header"
|
|
|
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
|
|
|
detail="Data is found in a column with empty header",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return schemas.InsertStatus(
|
|
|
|
|
@ -105,7 +107,9 @@ def read_item(item_id: int, db: Session = Depends(get_db)):
|
|
|
|
|
"""индивидуальные страницы для каждого Описания набора данных"""
|
|
|
|
|
db_item = crud.get_item(db=db, item_id=item_id)
|
|
|
|
|
if db_item is None:
|
|
|
|
|
raise HTTPException(status_code=404, detail="Item not found")
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND, detail="Item not found"
|
|
|
|
|
)
|
|
|
|
|
return db_item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -149,7 +153,9 @@ def search(q: str, skip: int = 0, limit: int = 20, db: Session = Depends(get_db)
|
|
|
|
|
# replace all full ИЛИ words with OR
|
|
|
|
|
q = substitute(r"\bИЛИ\b", "OR", q, flags=IGNORECASE)
|
|
|
|
|
if len(q) < 3:
|
|
|
|
|
raise HTTPException(status_code=400, detail="Query too short")
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=status.HTTP_400_BAD_REQUEST, detail="Query too short"
|
|
|
|
|
)
|
|
|
|
|
return crud.get_item_by_description(db=db, needle=q, skip=skip, limit=limit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|