add profile
parent
7690d9e1b7
commit
601a0128b0
|
@ -7,12 +7,12 @@ from core.services.office import services
|
|||
router = APIRouter(prefix='/offices')
|
||||
|
||||
|
||||
@router.get('/offices')
|
||||
@router.get('/')
|
||||
async def list_offices(offices: list[JdeOfficeDetailResponse] = Depends(services.list_offices_service)) -> list[
|
||||
JdeOfficeDetailResponse]:
|
||||
return offices
|
||||
|
||||
|
||||
@router.post('/offices')
|
||||
@router.post('/')
|
||||
async def update_office(data: UpdateOfficeRequest):
|
||||
await services.update_office(data)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
from fastapi import APIRouter, Path
|
||||
|
||||
from core.models.office.db import ProfileDB
|
||||
from core.models.office.requests import CreateOrUpdateProfileRequest
|
||||
from core.registry import profile_storage
|
||||
|
||||
router = APIRouter(prefix='/profiles')
|
||||
|
||||
|
||||
|
@ -11,13 +15,13 @@ async def create_profile():
|
|||
|
||||
|
||||
@router.get('/')
|
||||
async def list_profiles():
|
||||
pass
|
||||
async def list_profiles() -> list[ProfileDB]:
|
||||
return profile_storage.list_all_profiles()
|
||||
|
||||
|
||||
@router.get('/{profile_id}')
|
||||
async def get_profile(profile_id: int = Path()):
|
||||
pass
|
||||
async def get_profile(profile_id: int = Path()) -> ProfileDB:
|
||||
return profile_storage.get_by_id(profile_id)
|
||||
|
||||
|
||||
@router.delete('/{profile_id}')
|
||||
|
@ -25,6 +29,6 @@ async def delete_profile(profile_id: int = Path()):
|
|||
pass
|
||||
|
||||
|
||||
@router.put('/{profile_id}')
|
||||
async def update_profile(profile_id: int = Path()):
|
||||
pass
|
||||
@router.put('/')
|
||||
async def update_profile(data: CreateOrUpdateProfileRequest):
|
||||
profile_storage.create_or_update_profile(data=data)
|
||||
|
|
|
@ -7,10 +7,10 @@ class ProfileResponse(ProfileDB):
|
|||
|
||||
|
||||
class ExtendedResponse(BaseModel):
|
||||
features: str | None
|
||||
contact_person: ProfileResponse | None
|
||||
person_count: int | None
|
||||
rating: int | None
|
||||
features: str | None = None
|
||||
contact_person: ProfileResponse | None = None
|
||||
person_count: int | None = None
|
||||
rating: int | None = None
|
||||
|
||||
|
||||
class JdeOfficeDetailResponse(JdeOfficeDB):
|
||||
|
|
|
@ -7,7 +7,7 @@ from ...models.office.requests import UpdateOfficeRequest
|
|||
async def list_offices_service() -> list[JdeOfficeDetailResponse]:
|
||||
offices = await grab_data()
|
||||
offices.sort(key=lambda x: x.code)
|
||||
offices_additional_data = {data.code: data for data in office_storage.list_all_offices()}
|
||||
offices_additional_data = {data.code: data.model_dump() for data in office_storage.list_all_offices()}
|
||||
response_data = [
|
||||
JdeOfficeDetailResponse(**office.model_dump(), changeable_info=None or offices_additional_data.get(office.code)) for office in offices
|
||||
]
|
||||
|
|
|
@ -10,14 +10,14 @@ class OfficeStorage(BaseStorage):
|
|||
row = self.get_by('office', code=idx)
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail='Office not found')
|
||||
office = JdeOfficeLocalDB(code=row[0], features=row[1], contact_person_id=row[2], person_count=row[3],
|
||||
office = JdeOfficeLocalDB(code=str(row[0]), features=row[1], contact_person_id=row[2], person_count=row[3],
|
||||
rating=row[4])
|
||||
return office
|
||||
|
||||
def list_all_offices(self):
|
||||
rows = self.list_by('office')
|
||||
return [
|
||||
JdeOfficeLocalDB(code=row[0],
|
||||
JdeOfficeLocalDB(code=str(row[0]),
|
||||
features=row[1],
|
||||
contact_person_id=row[2],
|
||||
person_count=row[3],
|
||||
|
|
Loading…
Reference in New Issue