it-planet-springboard/api/app/controllers/company_profiles_router.py

58 lines
1.9 KiB
Python

from typing import Optional
from fastapi import APIRouter, Depends, status, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from app.database.session import get_db
from app.domain.entities.company_profiles import CompanyProfileCreate, CompanyProfileRead, CompanyProfileUpdate
from app.domain.models import User
from app.infrastructure.company_profiles_service import CompanyProfilesService
from app.infrastructure.dependencies import require_employer
company_profiles_router = APIRouter()
@company_profiles_router.get(
'/me/',
response_model=Optional[CompanyProfileRead],
summary='Get a company profile',
description='Get a company profile',
)
async def get_my_company(
db: AsyncSession = Depends(get_db),
user: User = Depends(require_employer)
):
company_profile_service = CompanyProfilesService(db)
return await company_profile_service.get_company_by_creator_id(user.id)
@company_profiles_router.post(
'/',
response_model=Optional[CompanyProfileRead],
summary='Create a new company profile',
description='Create a new company profile',
)
async def create_company(
company_data: CompanyProfileCreate,
db: AsyncSession = Depends(get_db),
user: User = Depends(require_employer)
):
company_profile_service = CompanyProfilesService(db)
return await company_profile_service.create_company(company_data, user)
@company_profiles_router.put(
'/{company_id}/',
response_model=Optional[CompanyProfileRead],
summary='Update a company profile',
description='Update a company profile',
)
async def update_company(
company_id: int,
company_data: CompanyProfileUpdate,
db: AsyncSession = Depends(get_db),
user: User = Depends(require_employer),
):
company_profile_service = CompanyProfilesService(db)
return await company_profile_service.update_company(company_id, company_data, user)