Update app/models/recon_job.py
This commit is contained in:
+42
-14
@@ -1,24 +1,52 @@
|
|||||||
from datetime import date, datetime
|
|
||||||
from typing import Optional, Dict
|
from typing import Optional, Dict
|
||||||
|
from datetime import date, datetime
|
||||||
|
import json
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, Field, field_validator
|
||||||
|
|
||||||
from app.core.refdata import ReconJobStatus
|
from app.core.refdata import ReconJobStatus
|
||||||
|
# from app.models.recon_auth import UserResponse
|
||||||
|
|
||||||
|
|
||||||
class ReconJob(BaseModel):
|
class ReconJobRequest(BaseModel):
|
||||||
"""Pydantic representation of the `recon_jobs` row (see `app.db.schema.ReconJob`)."""
|
""" Contains all user settable attributes.
|
||||||
|
I.e. User cannot change id, user or status as this is updated internally.
|
||||||
model_config = ConfigDict(from_attributes=True, use_enum_values=True)
|
"""
|
||||||
|
|
||||||
id: int
|
|
||||||
name: str
|
name: str
|
||||||
|
as_at_date: date = Field(description="The date of the data - not a filename date. Each source and dest system in the config will use it's offset for filters and filenames.")
|
||||||
|
recon_config_reference: str = Field(description="User supplied reference of the config")
|
||||||
due_datetime: Optional[datetime] = None
|
due_datetime: Optional[datetime] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ReconJobResponse(ReconJobRequest):
|
||||||
|
""" Returns all recon job attributes including id and status fields.
|
||||||
|
"""
|
||||||
|
id: int
|
||||||
|
status: ReconJobStatus
|
||||||
|
status_reason: str
|
||||||
|
username: str
|
||||||
start_datetime: Optional[datetime] = None
|
start_datetime: Optional[datetime] = None
|
||||||
finish_datetime: Optional[datetime] = None
|
finish_datetime: Optional[datetime] = None
|
||||||
as_at_date: date
|
results: Optional[Dict] = Field(default=None)
|
||||||
status: ReconJobStatus
|
|
||||||
status_reason: str = ""
|
model_config = {
|
||||||
recon_config_reference: str
|
"from_attributes": True # Ability to load from ORM model
|
||||||
username: str
|
}
|
||||||
results: Optional[Dict] = None
|
|
||||||
|
@field_validator("results", mode="before")
|
||||||
|
def parse_json(cls, v):
|
||||||
|
if isinstance(v, str) and len(v) > 0:
|
||||||
|
try:
|
||||||
|
return json.loads(v)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
raise ValueError("Invalid JSON string")
|
||||||
|
return None
|
||||||
|
|
||||||
|
class ReconJob(ReconJobResponse):
|
||||||
|
"""
|
||||||
|
Internal representation of a recon job
|
||||||
|
"""
|
||||||
|
|
||||||
|
model_config = {
|
||||||
|
"from_attributes": True # Ability to load from ORM model
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user