minor: service schema nomenclature

This commit is contained in:
Chris Milne 2026-05-28 14:27:14 +01:00
parent 33e78d4a9b
commit 00dcf7ce35
2 changed files with 8 additions and 8 deletions

View file

@ -17,7 +17,7 @@ from src.service.models import Service
from src.service.utils import generate_api_key from src.service.utils import generate_api_key
from src.service.dependencies import service_model_body_dependency from src.service.dependencies import service_model_body_dependency
from src.service.schemas import ServiceGetServiceResponse, ServicePostServiceRequest, ServicePostServiceResponse, \ from src.service.schemas import ServiceGetServiceResponse, ServicePostServiceRequest, ServicePostServiceResponse, \
ServiceWithKeyResponse, ServicePatchKeyResponse, ServicePatchKeyRequest, ServiceDeleteServiceRequest ServiceWithKeySchema, ServicePatchKeyResponse, ServicePatchKeyRequest, ServiceDeleteServiceRequest
router = APIRouter( router = APIRouter(
tags=["Service"], tags=["Service"],
@ -42,7 +42,7 @@ async def register_service(db: db_dependency, su: super_admin_dependency, servic
if isinstance(e.orig, UniqueViolation): if isinstance(e.orig, UniqueViolation):
raise Conflict(message="Service with this name already exists") raise Conflict(message="Service with this name already exists")
db.commit() db.commit()
response = ServiceWithKeyResponse(**service_model.__dict__) response = ServiceWithKeySchema(**service_model.__dict__)
db.commit() db.commit()
return {"service": response} return {"service": response}
@ -52,7 +52,7 @@ async def regenerate_api_key(db: db_dependency, su: super_admin_dependency, serv
service_model.api_key = key service_model.api_key = key
db.flush() db.flush()
response = ServiceWithKeyResponse(**service_model.__dict__) response = ServiceWithKeySchema(**service_model.__dict__)
db.commit() db.commit()
return {"service": response} return {"service": response}

View file

@ -12,29 +12,29 @@ from src.schemas import CustomBaseModel
class ServiceIDMixin(CustomBaseModel): class ServiceIDMixin(CustomBaseModel):
service_id: int service_id: int
class ServiceResponse(CustomBaseModel): class ServiceSchema(CustomBaseModel):
model_config = ConfigDict(from_attributes=True, extra="ignore") model_config = ConfigDict(from_attributes=True, extra="ignore")
id: int id: int
name: str name: str
class ServiceWithKeyResponse(ServiceResponse): class ServiceWithKeySchema(ServiceSchema):
api_key: str api_key: str
class ServiceGetServiceResponse(CustomBaseModel): class ServiceGetServiceResponse(CustomBaseModel):
services: list[ServiceResponse] services: list[ServiceSchema]
class ServicePostServiceRequest(CustomBaseModel): class ServicePostServiceRequest(CustomBaseModel):
name: str name: str
class ServicePostServiceResponse(CustomBaseModel): class ServicePostServiceResponse(CustomBaseModel):
service: ServiceWithKeyResponse service: ServiceWithKeySchema
class ServicePatchKeyRequest(ServiceIDMixin): class ServicePatchKeyRequest(ServiceIDMixin):
pass pass
class ServicePatchKeyResponse(CustomBaseModel): class ServicePatchKeyResponse(CustomBaseModel):
service: ServiceWithKeyResponse service: ServiceWithKeySchema
class ServiceDeleteServiceRequest(ServiceIDMixin): class ServiceDeleteServiceRequest(ServiceIDMixin):
pass pass