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