from typing import Optional, List from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import joinedload from app.domain.models import CompanyProfile, CompanyProfileSocial class CompanyProfilesRepository: def __init__(self, db: AsyncSession): self.db = db async def get_by_id(self, company_id: int) -> Optional[CompanyProfile]: query = ( select(CompanyProfile) .filter_by(id=company_id) .options( joinedload(CompanyProfile.logo), joinedload(CompanyProfile.official_photo), joinedload(CompanyProfile.industry), joinedload(CompanyProfile.socials), joinedload(CompanyProfile.verification_requests), ) ) result = await self.db.execute(query) return result.scalars().first() async def get_company_by_creator_id(self, user_id: int) -> Optional[CompanyProfile]: query = ( select(CompanyProfile) .filter_by(creator_user_id=user_id) .options( joinedload(CompanyProfile.logo), joinedload(CompanyProfile.official_photo), joinedload(CompanyProfile.industry), joinedload(CompanyProfile.socials), joinedload(CompanyProfile.verification_requests), ) ) result = await self.db.execute(query) return result.scalars().first() async def create(self, company: CompanyProfile) -> CompanyProfile: self.db.add(company) await self.db.commit() await self.db.refresh(company) return company async def update(self, company: CompanyProfile) -> CompanyProfile: await self.db.merge(company) await self.db.commit() return company