Download apps/organization/api/lawfirm_api.py from jun2024/fc: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/organization/api/lawfirm_api.py
- Command line
-
hf download hf://spaces/jun2024/fc/apps/organization/api/lawfirm_api.py
-
curl -L -o lawfirm_api.py https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/organization/api/lawfirm_api.py
2.21 kB
| """ | |
| 律所 API | |
| 只负责请求/响应处理,业务逻辑在 Service 层 | |
| """ | |
| from __future__ import annotations | |
| from django.http import HttpRequest | |
| from ninja import Router | |
| from apps.core.security.auth import JWTOrSessionAuth | |
| from apps.organization.api.utils_api import get_request_user | |
| from apps.organization.dtos import LawFirmCreateDTO, LawFirmUpdateDTO | |
| from apps.organization.schemas import LawFirmIn, LawFirmOut, LawFirmUpdateIn | |
| from apps.organization.services import LawFirmService | |
| router = Router(auth=JWTOrSessionAuth()) | |
| def _get_lawfirm_service() -> LawFirmService: | |
| """工厂函数:获取律所服务实例""" | |
| return LawFirmService() | |
| _lawfirm_service = _get_lawfirm_service() | |
| def list_lawfirms(request: HttpRequest, name: str | None = None) -> list[LawFirmOut]: | |
| return list(_lawfirm_service.list_lawfirms(name=name, user=get_request_user(request))) | |
| def get_lawfirm(request: HttpRequest, law_firm_id: int) -> LawFirmOut: | |
| return _lawfirm_service.get_lawfirm(law_firm_id, get_request_user(request)) | |
| def create_lawfirm(request: HttpRequest, payload: LawFirmIn) -> LawFirmOut: | |
| dto = LawFirmCreateDTO( | |
| name=payload.name, | |
| address=payload.address, | |
| phone=payload.phone, | |
| social_credit_code=payload.social_credit_code, | |
| ) | |
| return _lawfirm_service.create_lawfirm(data=dto, user=get_request_user(request)) | |
| def update_lawfirm(request: HttpRequest, law_firm_id: int, payload: LawFirmUpdateIn) -> LawFirmOut: | |
| dto = LawFirmUpdateDTO( | |
| name=payload.name, | |
| address=payload.address, | |
| phone=payload.phone, | |
| social_credit_code=payload.social_credit_code, | |
| ) | |
| return _lawfirm_service.update_lawfirm(lawfirm_id=law_firm_id, data=dto, user=get_request_user(request)) | |
| def delete_lawfirm(request: HttpRequest, law_firm_id: int) -> dict[str, bool]: | |
| _lawfirm_service.delete_lawfirm(law_firm_id, get_request_user(request)) | |
| return {"success": True} | |