108 lines
2.6 KiB
Python
108 lines
2.6 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from pydantic import Field
|
||
|
|
|
||
|
|
from .common import ApiEnvelope, EmptyRequest, JsonObject, JsonValue, RouteContract, SchemaModel
|
||
|
|
|
||
|
|
|
||
|
|
class PlantPayload(SchemaModel):
|
||
|
|
name: str
|
||
|
|
light: str | None = None
|
||
|
|
watering: str | None = None
|
||
|
|
soil: str | None = None
|
||
|
|
temperature: str | None = None
|
||
|
|
growth_stage: str | None = None
|
||
|
|
planting_season: str | None = None
|
||
|
|
harvest_time: str | None = None
|
||
|
|
spacing: str | None = None
|
||
|
|
fertilizer: str | None = None
|
||
|
|
|
||
|
|
|
||
|
|
class PlantPartialPayload(SchemaModel):
|
||
|
|
name: str | None = None
|
||
|
|
light: str | None = None
|
||
|
|
watering: str | None = None
|
||
|
|
soil: str | None = None
|
||
|
|
temperature: str | None = None
|
||
|
|
growth_stage: str | None = None
|
||
|
|
planting_season: str | None = None
|
||
|
|
harvest_time: str | None = None
|
||
|
|
spacing: str | None = None
|
||
|
|
fertilizer: str | None = None
|
||
|
|
|
||
|
|
|
||
|
|
class PlantRecord(PlantPayload):
|
||
|
|
id: int
|
||
|
|
created_at: str | None = None
|
||
|
|
updated_at: str | None = None
|
||
|
|
|
||
|
|
|
||
|
|
class PlantListResponse(ApiEnvelope[list[PlantRecord]]):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class PlantDetailResponse(ApiEnvelope[PlantRecord]):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class PlantDeleteResponse(ApiEnvelope[JsonValue | None]):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class PlantDetailRequest(SchemaModel):
|
||
|
|
pk: int
|
||
|
|
|
||
|
|
|
||
|
|
class PlantFetchInfoRequest(SchemaModel):
|
||
|
|
name: str
|
||
|
|
|
||
|
|
|
||
|
|
class PlantFetchInfoResponse(ApiEnvelope[JsonObject]):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
CONTRACTS = [
|
||
|
|
RouteContract(
|
||
|
|
method='GET',
|
||
|
|
path='/api/plants/',
|
||
|
|
request_model=EmptyRequest.__name__,
|
||
|
|
response_model=PlantListResponse.__name__,
|
||
|
|
),
|
||
|
|
RouteContract(
|
||
|
|
method='POST',
|
||
|
|
path='/api/plants/',
|
||
|
|
request_model=PlantPayload.__name__,
|
||
|
|
response_model=PlantDetailResponse.__name__,
|
||
|
|
),
|
||
|
|
RouteContract(
|
||
|
|
method='GET',
|
||
|
|
path='/api/plants/<pk>/',
|
||
|
|
request_model=PlantDetailRequest.__name__,
|
||
|
|
response_model=PlantDetailResponse.__name__,
|
||
|
|
),
|
||
|
|
RouteContract(
|
||
|
|
method='PUT',
|
||
|
|
path='/api/plants/<pk>/',
|
||
|
|
request_model=PlantPayload.__name__,
|
||
|
|
response_model=PlantDetailResponse.__name__,
|
||
|
|
),
|
||
|
|
RouteContract(
|
||
|
|
method='PATCH',
|
||
|
|
path='/api/plants/<pk>/',
|
||
|
|
request_model=PlantPartialPayload.__name__,
|
||
|
|
response_model=PlantDetailResponse.__name__,
|
||
|
|
),
|
||
|
|
RouteContract(
|
||
|
|
method='DELETE',
|
||
|
|
path='/api/plants/<pk>/',
|
||
|
|
request_model=PlantDetailRequest.__name__,
|
||
|
|
response_model=PlantDeleteResponse.__name__,
|
||
|
|
),
|
||
|
|
RouteContract(
|
||
|
|
method='POST',
|
||
|
|
path='/api/plants/fetch-info/',
|
||
|
|
request_model=PlantFetchInfoRequest.__name__,
|
||
|
|
response_model=PlantFetchInfoResponse.__name__,
|
||
|
|
),
|
||
|
|
]
|