Files

55 lines
2.0 KiB
Python

from fastapi import status, HTTPException, APIRouter, Depends, UploadFile
from fastapi.responses import FileResponse
from sqlalchemy.orm import Session
from minio import Minio
from typing import List
from io import BytesIO
from os import remove
from starlette.background import BackgroundTask
from ..database import get_db
from ..storage import get_client
from .. import models, schemas, security
router = APIRouter(
prefix="/services",
dependencies=[Depends(security.verify_api_key)],
tags=['Services']
)
@router.get("/resume/{filename}")
def get_resume(filename: str, client: Minio = Depends(get_client)):
response = client.fget_object("tgjobs", filename, filename)
if not response:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
task = BackgroundTask(remove, filename)
return FileResponse(path=filename, filename=response.object_name, media_type=response.content_type, background=task)
@router.get("/hardskills/", response_model=List[schemas.Hard_skill])
def get_all_hardskills(db: Session = Depends(get_db)):
hardskills = db.query(models.Hard_skills).filter(models.Hard_skills.Title.ilike("%")).all()
if not hardskills:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
return hardskills
@router.get("/hardskills/{title}", response_model=List[schemas.Hard_skill])
def get_hardskills(title: str, db: Session = Depends(get_db)):
hardskills = db.query(models.Hard_skills).filter(models.Hard_skills.Title.ilike("%" + title + "%")).all()
if not hardskills:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
return hardskills
@router.post("/resume/")
async def upload_resume_to_cloud(file: UploadFile, client: Minio = Depends(get_client)):
response = client.put_object("tgjobs", file.filename, BytesIO(await file.read()), file.size, file.content_type)
if not response:
raise HTTPException(status_code=status.HTTP_409_CONFLICT)
return {"filename": response.object_name}