Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/691b0f10-2f54-8005-9100-81f83803b484
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== ### ==== <syntaxhighlight lang="python">class AdminClientVehicleCreateSchema(BaseModel): ... client_id: UUID organization_id: UUID | None vehicle_number: Annotated[str, constr(min_length=1, max_length=50)] type: VehicleTypeEnum | None status: VehicleStatusEnum = VehicleStatusEnum.active model_name: str | None = Field(..., max_length=100) model_year: int | None access_scopes: list[str] | None </syntaxhighlight> ์ข์ ์ : * ClientVehicleCreateSchema์ ๊ตฌ์กฐ๊ฐ ๊ฑฐ์ ํํ์ด๋ผ ์ฝ๊ธฐ ์ฝ๊ณ , ๋๋ฉ์ธ ๊ฐ๊ฐ๋ ๋ง์์. * vehicle_number์ ๊ธธ์ด ์ ์ฝ ๋ฃ์ด๋ ๊ฒ๋ ์ข์ต๋๋ค. ๊ณ ๋ คํด ๋ณผ ์ : # access_scopes ์ ์ฝ - ํ์ฌ๋ ์์ ๋ก์ด list[str]๋ผ์, FE๋ ๋ค๋ฅธ ์๋น์ค์์ ์คํ/์ผ์ด์ค ๋ฌธ์ ๋ก ๊ผฌ์ผ ์ฌ์ง๊ฐ ์์ต๋๋ค. - ๋์ค์๋ผ๋ enum-ishํ ๋ ๋ฒจ๋ก ๋ฌถ๊ณ ์ถ๋ค๋ฉด: - ์ต์ํ ์์ ๋ฆฌ์คํธ(ALLOWED_ACCESS_SCOPES = {"dispatch", "weighing", ...})๋ก ๊ฒ์ฆํ๋ validator๋ฅผ ํ๋ ๋ถ์ด๋ ๊ฒ๋ ์ต์ ์ ๋๋ค. # ๊ธฐ์กด ์คํค๋ง์์ ์ฝ๋ ์ค๋ณต ์ต์ํ - ClientVehicleCreateSchema์ ํ๋ ๊ตฌ์ฑ์ด ๋ง์ด ๊ฒน์นฉ๋๋ค. - ๋์ค์ ํ๋ ํ๋๋ฅผ ๋ณ๊ฒฝํ ์ผ์ด ์๊ธฐ๋ฉด ๋ ๋ค ์์ ํด์ผ ํด์ ์ด์ง ๋ถ์ฑ๊ฐ ๋ ์ ์์ด์. - ์๋ฅผ ๋ค๋ฉด: </code>`<code>python class BaseClientVehicleCreate(BaseModel): vehicle_number: ... type: ... status: ... model_name: ... model_year: ... class ClientVehicleCreateSchema(BaseClientVehicleCreate): client_id: UUID | None = Field(None, ...?) # ๊ธฐ์กด ์ ์ ๋ฐ๋ผ class AdminClientVehicleCreateSchema(BaseClientVehicleCreate): client_id: UUID = ... organization_id: UUID | None = ... access_scopes: list[str] | None = ... </code>`<code> - ์ง๊ธ ๋น์ฅ ํ์๋ ์๋๊ณ , โํ ๋ฒ ๋ ๊ฐ์ ์์ ์๊ธฐ๋ฉด ๋ฆฌํฉํฐ๋ง ํ๋ณดโ ์ ๋๋ก ๋ณด์ ๋๋ค. ==== <syntaxhighlight lang="python">stmt = select(VehicleOrgAccess).where( ==== VehicleOrgAccess.vehicle_id == vehicle_id, VehicleOrgAccess.organization_id == organization_id, ) result = await self.session.execute(stmt) access = result.scalar_one_or_none() if access is None: access = VehicleOrgAccess( vehicle_id=vehicle_id, organization_id=organization_id, scopes=scopes or None, created_by=created_by, ) self.session.add(access) else: access.is_deleted = False access.deleted_at = None if scopes: access.scopes = scopes await self.session.flush() if commit and self.session.in_transaction(): await self.session.commit() </syntaxhighlight> ์ข์ ์ : * soft-delete ๋ณต๊ตฌ + scopes ๊ฐฑ์ ํ๋ฆ์ด ๋ช ํํ๊ณ , ํ ์คํธ๋ก๋ ์ ๊ฒ์ฆ๋์ด ์์ต๋๋ค. * commit=False๋ก boundary์ ํจ๊ป ์ธ ์ ์๊ฒ ํ ํจํด๋ ๊น๋ํด์. ํ์ธ/๊ฐ์ ํฌ์ธํธ: # ํธ๋์ญ์ ์ฒ๋ฆฌ ํจํด ํต์ผ์ฑ - ์ฌ๊ธฐ์ if commit and self.session.in_transaction(): ํจํด์ ์ฐ๊ณ ์๋๋ฐ, - ๊ฐ์ ์๋น์ค ๋ด ๋ค๋ฅธ ๋ฉ์๋๋ค์ด ์ด๋ค ํจํด์ ์ฐ๋์ง์ ๋ฐ๋ผ: - commit/rollback ์ฑ ์์ด service์ ์๋์ง, - ์๋๋ฉด ํญ์ boundary์ ์๋์ง, ๋ฅผ ํต์ผํด ๋๋ ๊ฒ ์ดํดํ๊ธฐ ์ฌ์ธ ๊ฒ ๊ฐ์ต๋๋ค. - ์ด๋ฏธ ๋ค๋ฅธ ๋ฉ์๋๋ค๋ ๊ฐ์ ํจํด์ด๋ผ๋ฉด OK, ์๋๋ผ๋ฉด โservice๋ flush๊น์ง๋ง, commit/rollback์ boundary์์๋งโ ๊ท์น์ผ๋ก ์ ๋ฆฌํ๋ ๊ฒ๋ ๋ฐฉ๋ฒ. # ์ค๋ณต/๋ ์ด์ค ์ด์ - DB ๋ ๋ฒจ์์ (vehicle_id, organization_id)์ unique ์ธ๋ฑ์ค๊ฐ ์์ผ๋ฉด, - ์ด ํจ์๊ฐ ๋์์ ๋ ๋ฒ ํธ์ถ๋ ๋ ๋ ๋ค access is None์ด ๋์ด ์ค๋ณต insert ๊ฐ๋ฅ์ฑ์ด ์์ต๋๋ค. - ์ด๋ฏธ unique constraint๊ฐ ์๋ค๋ฉด OK๊ณ , ์๋ค๋ฉด: - ๋์ค์๋ผ๋ unique index + IntegrityError ์ฒ๋ฆฌ๋ก ๊ฐ์ธ๋ ์ ํ์ง๋ ๊ณ ๋ คํ ์ ์๊ฒ ์ต๋๋ค. # ์์ธ ํ์ - SQLAlchemyError๋ฅผ APIException(INTERNAL_ERROR)๋ก ๊ฐ์ธ๋ ๊ฑด API ๋ ์ด์ด ์ ์ฅ์์๋ ์ ์ ํฉ๋๋ค. - ๋ค๋ง ์ด ์๋น์ค๊ฐ ๋ด๋ถ์์๋ง ์ฐ์ด๋์ง, ๋ค๋ฅธ ์๋น์ค/๋ฐฐ์น์์๋ ํธ์ถ๋๋์ง์ ๋ฐ๋ผ: - ๋ด๋ถ์์๋ APIException๋ณด๋ค ๋ณ๋ domain-level ์์ธ๊ฐ ๋ ์์ฐ์ค๋ฌ์ธ ์๋ ์๊ณ , - ์ด๋ฏธ ์ด ์๋น์ค ์ ์ฒด๊ฐ โAPI์ฉโ์ด๋ผ๋ ์ปจ๋ฒค์ ์ด๋ฉด ์ง๊ธ์ฒ๋ผ ๋์ ๋ ๊ด์ฐฎ์ต๋๋ค. ==== <syntaxhighlight lang="python">return await run_with_session_boundary( ==== db, _operation, logger=logger, log_message="ํด๋ผ์ด์ธํธ ์ฐจ๋ ๋๋ฆฌ ๋ฑ๋ก ์คํจ", error_detail="๊ฑฐ๋์ฒ ์ฐจ๋ ๋ฑ๋ก ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.", log_extra={ "route": "/api/v1/admin/subscriber/client-vehicle/", "actor_id": str(current_user.id), "entity_id": str(payload.client_id), }, ) </syntaxhighlight> * ๋ฉ์์ง/ํ๊ธ ์๋ฌ/route/actor_id ๊ตฌ์กฐ ๋ชจ๋ ๊ธฐ์กด ์ ์ฑ ์ ์ ๋ฐ๋ผ๊ฐ๊ณ ์์ต๋๋ค. * entity_id๋ฅผ client_id๋ก ๋ ๊ฒ๋ โ์ด ์๋ํฌ์ธํธ์ ๋ ผ๋ฆฌ์ ๋์์ client์ vehicle์ ๊ด๊ณโ๋ผ์ ๋ฉ๋์ ๋ผ์. ์ถ๊ฐ๋ก ์กฐ๊ธ๋ง ์์ฌ์ ๋ด๋ณด์๋ฉด: * log_extra์ target_org_id ์ ๋๋ฅผ ๊ฐ์ด ๋ฃ์ด๋๋ฉด, - ๋์ค์ ์ฌ๊ณ ๋ถ์ํ ๋ โ์ด๋ org์ ๋ํด ์๋ํ๋๊ฐโ๊ฐ ๋ฐ๋ก ๋ณด์ฌ์ ๋๋ฒ๊น ์ด ๋ ํธํ ๊ฒ ๊ฐ์ต๋๋ค. - ์: </code>`<code>python "target_org_id": str(target_org_id), "vehicle_registration_source": "subscriber_proxy", </code>``
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)