it-planet-springboard/api/app/application/company_profile_socials_repository.py

40 lines
1.3 KiB
Python

from typing import Sequence, List
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.domain.models import CompanyProfileSocial
class CompanyProfileSocialsRepository:
def __init__(self, db: AsyncSession):
self.db = db
async def get_by_company_profile_id(self, company_profile_id: int) -> Sequence[CompanyProfileSocial]:
query = (
select(CompanyProfileSocial)
.filter_by(company_id=company_profile_id)
)
result = await self.db.execute(query)
return result.scalars().all()
async def create_list(self, company_profile_socials: List[CompanyProfileSocial]) -> Sequence[CompanyProfileSocial]:
self.db.add_all(company_profile_socials)
await self.db.commit()
for company_profile_social in company_profile_socials:
await self.db.refresh(company_profile_social)
return company_profile_socials
async def delete_list(
self,
company_profile_socials: List[CompanyProfileSocial] | Sequence[CompanyProfileSocial]
) -> Sequence[CompanyProfileSocial]:
for company_profile_social in company_profile_socials:
await self.db.delete(company_profile_social)
await self.db.commit()
return company_profile_socials