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

44 lines
1.7 KiB
Python

from typing import Optional, List
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from app.database.session import get_db
from app.domain.entities.company_profile_socials import CompanyProfileSocialRead, CompanyProfileSocialCreate
from app.domain.models import User
from app.infrastructure.company_profile_socials_service import CompanyProfileSocialsService
from app.infrastructure.dependencies import require_employer
company_profile_socials_router = APIRouter()
@company_profile_socials_router.get(
'/{company_profile_id}/',
response_model=Optional[List[CompanyProfileSocialRead]],
summary='Get company profile socials',
description='Get company profile socials',
)
async def get_company_profile_socials(
company_profile_id: int,
db: AsyncSession = Depends(get_db),
):
company_profile_socials_service = CompanyProfileSocialsService(db)
return await company_profile_socials_service.get_by_company_profile_id(company_profile_id)
@company_profile_socials_router.post(
'/{company_profile_id}/',
response_model=Optional[List[CompanyProfileSocialRead]],
summary='Replace company profile social',
description='Replace company profile social',
)
async def replace_company_profile_social(
company_profile_id: int,
company_profile_socials: List[CompanyProfileSocialCreate],
db: AsyncSession = Depends(get_db),
user: User = Depends(require_employer),
):
company_profile_social_service = CompanyProfileSocialsService(db)
return await company_profile_social_service.replace_company_profile_socials(company_profile_socials,
company_profile_id, user)