Implentation of get current firm

This commit is contained in:
2025-04-18 01:04:03 +02:00
parent 654cf34c74
commit e1e8ad79b4
4 changed files with 28 additions and 5 deletions

2
.idea/misc.xml generated
View File

@@ -3,5 +3,5 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="Python 3.10" /> <option name="sdkName" value="Python 3.10" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="Remote Python 3.13.2 Docker Compose (api)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Remote Python 3.13.3 Docker Compose (api)" project-jdk-type="Python SDK" />
</project> </project>

View File

@@ -5,7 +5,7 @@
<sourceFolder url="file://$MODULE_DIR$/api/rpk-api" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/api/rpk-api" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/api/.venv" /> <excludeFolder url="file://$MODULE_DIR$/api/.venv" />
</content> </content>
<orderEntry type="jdk" jdkName="Remote Python 3.13.2 Docker Compose (api)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Remote Python 3.13.3 Docker Compose (api)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@@ -5,7 +5,7 @@ from pydantic import Field
from firm.core.models import CrudDocument from firm.core.models import CrudDocument
from firm.core.schemas import Writer, Reader from firm.core.schemas import Writer, Reader
from firm.entity.schemas import EntityIndividualCreate, EntityCorporationCreate from firm.entity.schemas import EntityIndividualCreate, EntityCorporationCreate, EntityRead
class CurrentFirmModel(CrudDocument): class CurrentFirmModel(CrudDocument):
@@ -34,7 +34,17 @@ class CurrentFirmModel(CrudDocument):
class CurrentFirmSchemaRead(Reader): class CurrentFirmSchemaRead(Reader):
pass entity: EntityRead
partner: EntityRead
instance: str
firm: str
primary_color: str
secondary_color: str
@classmethod
def from_model_and_entities(cls, model, entity, partner):
schema = cls(**model.model_dump(mode="json"), entity=entity, partner=partner)
return schema
class CurrentFirmSchemaCreate(Writer): class CurrentFirmSchemaCreate(Writer):
corporation: EntityCorporationCreate = Field(title="Informations sur la firme") corporation: EntityCorporationCreate = Field(title="Informations sur la firme")
@@ -51,3 +61,12 @@ class CurrentFirmSchemaUpdate(Writer):
class Partner(CrudDocument): class Partner(CrudDocument):
user_id: PydanticObjectId = Field() user_id: PydanticObjectId = Field()
entity_id: PydanticObjectId = Field() entity_id: PydanticObjectId = Field()
@classmethod
async def get_by_user_id(cls, db, user_id):
document = await cls._get_collection(db).find_one({"user_id": str(user_id)})
if not document:
return None
document["id"] = document.pop("_id")
return cls.model_validate(document)

View File

@@ -3,13 +3,17 @@ from fastapi import APIRouter, Depends
from firm.core.depends import get_authed_tenant_registry, get_uninitialized_registry from firm.core.depends import get_authed_tenant_registry, get_uninitialized_registry
from firm.current_firm import CurrentFirmModel, CurrentFirmSchemaRead, CurrentFirmSchemaCreate, CurrentFirmSchemaUpdate, Partner from firm.current_firm import CurrentFirmModel, CurrentFirmSchemaRead, CurrentFirmSchemaCreate, CurrentFirmSchemaUpdate, Partner
from firm.entity.models import Entity, Employee from firm.entity.models import Entity, Employee
from firm.entity.schemas import EntityRead
current_firm_router = APIRouter() current_firm_router = APIRouter()
@current_firm_router.get("/", response_model=CurrentFirmSchemaRead, response_description=f"Current Firm records retrieved") @current_firm_router.get("/", response_model=CurrentFirmSchemaRead, response_description=f"Current Firm records retrieved")
async def read(reg=Depends(get_authed_tenant_registry)) -> CurrentFirmSchemaRead: async def read(reg=Depends(get_authed_tenant_registry)) -> CurrentFirmSchemaRead:
document = await CurrentFirmModel.get_current(reg.db) document = await CurrentFirmModel.get_current(reg.db)
return CurrentFirmSchemaRead.from_model(document) entity = await Entity.get(reg.db, document.entity_id)
partner = await Partner.get_by_user_id(reg.db, reg.user.id)
partner = await Entity.get(reg.db, partner.entity_id)
return CurrentFirmSchemaRead.from_model_and_entities(document, EntityRead.from_model(entity), EntityRead.from_model(partner))
@current_firm_router.post("/", response_description=f"Current Firm added to the database") @current_firm_router.post("/", response_description=f"Current Firm added to the database")
async def create(schema: CurrentFirmSchemaCreate, reg=Depends(get_uninitialized_registry)) -> CurrentFirmSchemaRead: async def create(schema: CurrentFirmSchemaCreate, reg=Depends(get_uninitialized_registry)) -> CurrentFirmSchemaRead: