feat: enhance import functionality with commit results and summary models for projects and scenarios
This commit is contained in:
@@ -2,11 +2,14 @@ from __future__ import annotations
|
||||
|
||||
from datetime import date, datetime
|
||||
from typing import Any, Mapping
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_validator, model_validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||
|
||||
from models import MiningOperationType, ResourceType, ScenarioStatus
|
||||
|
||||
PreviewStateLiteral = Literal["new", "update", "skip", "error"]
|
||||
|
||||
|
||||
def _normalise_string(value: Any) -> str:
|
||||
if value is None:
|
||||
@@ -170,3 +173,120 @@ class ScenarioImportRow(BaseModel):
|
||||
if self.start_date and self.end_date and self.start_date > self.end_date:
|
||||
raise ValueError("End date must be on or after start date")
|
||||
return self
|
||||
|
||||
|
||||
class ImportRowErrorModel(BaseModel):
|
||||
row_number: int
|
||||
field: str | None = None
|
||||
message: str
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ImportPreviewRowIssueModel(BaseModel):
|
||||
message: str
|
||||
field: str | None = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ImportPreviewRowIssuesModel(BaseModel):
|
||||
row_number: int
|
||||
state: PreviewStateLiteral | None = None
|
||||
issues: list[ImportPreviewRowIssueModel] = Field(default_factory=list)
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ImportPreviewSummaryModel(BaseModel):
|
||||
total_rows: int
|
||||
accepted: int
|
||||
skipped: int
|
||||
errored: int
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ProjectImportPreviewRow(BaseModel):
|
||||
row_number: int
|
||||
data: ProjectImportRow
|
||||
state: PreviewStateLiteral
|
||||
issues: list[str] = Field(default_factory=list)
|
||||
context: dict[str, Any] | None = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ScenarioImportPreviewRow(BaseModel):
|
||||
row_number: int
|
||||
data: ScenarioImportRow
|
||||
state: PreviewStateLiteral
|
||||
issues: list[str] = Field(default_factory=list)
|
||||
context: dict[str, Any] | None = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ProjectImportPreviewResponse(BaseModel):
|
||||
rows: list[ProjectImportPreviewRow]
|
||||
summary: ImportPreviewSummaryModel
|
||||
row_issues: list[ImportPreviewRowIssuesModel] = Field(default_factory=list)
|
||||
parser_errors: list[ImportRowErrorModel] = Field(default_factory=list)
|
||||
stage_token: str | None = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ScenarioImportPreviewResponse(BaseModel):
|
||||
rows: list[ScenarioImportPreviewRow]
|
||||
summary: ImportPreviewSummaryModel
|
||||
row_issues: list[ImportPreviewRowIssuesModel] = Field(default_factory=list)
|
||||
parser_errors: list[ImportRowErrorModel] = Field(default_factory=list)
|
||||
stage_token: str | None = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ImportCommitSummaryModel(BaseModel):
|
||||
created: int
|
||||
updated: int
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ProjectImportCommitRow(BaseModel):
|
||||
row_number: int
|
||||
data: ProjectImportRow
|
||||
context: dict[str, Any]
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ScenarioImportCommitRow(BaseModel):
|
||||
row_number: int
|
||||
data: ScenarioImportRow
|
||||
context: dict[str, Any]
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ProjectImportCommitResponse(BaseModel):
|
||||
token: str
|
||||
rows: list[ProjectImportCommitRow]
|
||||
summary: ImportCommitSummaryModel
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ScenarioImportCommitResponse(BaseModel):
|
||||
token: str
|
||||
rows: list[ScenarioImportCommitRow]
|
||||
summary: ImportCommitSummaryModel
|
||||
|
||||
model_config = ConfigDict(from_attributes=True, extra="forbid")
|
||||
|
||||
|
||||
class ImportCommitRequest(BaseModel):
|
||||
token: str
|
||||
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
Reference in New Issue
Block a user