diff --git a/server/planning/assignments/__init__.py b/server/planning/assignments/__init__.py index cc904eeae..8f2b4de8b 100644 --- a/server/planning/assignments/__init__.py +++ b/server/planning/assignments/__init__.py @@ -32,9 +32,10 @@ from .delivery import DeliveryResource from .service import AssignmentsAsyncService -from .module import assignments_resource_config +from .delivery_service import DeliveryAsyncService +from .module import assignments_resource_config, delivery_resource_config -__all__ = ["assignments_resource_config", "AssignmentsAsyncService"] +__all__ = ["assignments_resource_config", "AssignmentsAsyncService", "delivery_resource_config", "DeliveryAsyncService"] def init_app(app): diff --git a/server/planning/assignments/delivery_service.py b/server/planning/assignments/delivery_service.py new file mode 100644 index 000000000..9c11f061e --- /dev/null +++ b/server/planning/assignments/delivery_service.py @@ -0,0 +1,6 @@ +from planning.types import DeliveryResourceModel +from superdesk.core.resources import AsyncResourceService + + +class DeliveryAsyncService(AsyncResourceService[DeliveryResourceModel]): + pass diff --git a/server/planning/assignments/module.py b/server/planning/assignments/module.py index 54733f443..5964c6650 100644 --- a/server/planning/assignments/module.py +++ b/server/planning/assignments/module.py @@ -5,8 +5,9 @@ ElasticResourceConfig, ) -from planning.types import AssignmentResourceModel +from planning.types import AssignmentResourceModel, DeliveryResourceModel from .service import AssignmentsAsyncService +from .delivery_service import DeliveryAsyncService assignments_resource_config = ResourceConfig( name="assignments", @@ -34,3 +35,37 @@ ), elastic=ElasticResourceConfig(), ) + +delivery_resource_config = ResourceConfig( + name="delivery", + data_class=DeliveryResourceModel, + service=DeliveryAsyncService, + mongo=MongoResourceConfig( + indexes=[ + MongoIndexOptions( + name="planning_id_1", + keys=[("planning_id", 1)], + background=True, + unique=False, + ), + MongoIndexOptions( + name="assignment_id_1", + keys=[("assignment_id", 1)], + background=True, + unique=False, + ), + MongoIndexOptions( + name="coverage_id_1", + keys=[("coverage_id", 1)], + background=True, + unique=False, + ), + MongoIndexOptions( + name="item_id_1", + keys=[("item_id", 1)], + background=True, + unique=False, + ), + ], + ), +) diff --git a/server/planning/module.py b/server/planning/module.py index 669545522..3b6cdf924 100644 --- a/server/planning/module.py +++ b/server/planning/module.py @@ -1,7 +1,7 @@ from superdesk.core.module import Module from planning.events import events_resource_config from planning.planning import planning_resource_config -from planning.assignments import assignments_resource_config +from planning.assignments import assignments_resource_config, delivery_resource_config from planning.published import published_resource_config @@ -12,5 +12,6 @@ planning_resource_config, assignments_resource_config, published_resource_config, + delivery_resource_config, ], ) diff --git a/server/planning/types/__init__.py b/server/planning/types/__init__.py index 11e73fb32..56c4466f1 100644 --- a/server/planning/types/__init__.py +++ b/server/planning/types/__init__.py @@ -15,6 +15,7 @@ from .base import BasePlanningModel from .common import PlanningSchedule +from .delivery import DeliveryResourceModel from .event import EventResourceModel from .planning import PlanningResourceModel from .assignment import AssignmentResourceModel @@ -24,6 +25,7 @@ __all__ = [ "BasePlanningModel", + "DeliveryResourceModel", "EventResourceModel", "PlanningResourceModel", "AssignmentResourceModel", diff --git a/server/planning/types/delivery.py b/server/planning/types/delivery.py new file mode 100644 index 000000000..7ce8bde87 --- /dev/null +++ b/server/planning/types/delivery.py @@ -0,0 +1,17 @@ +from pydantic import Field +from typing import Annotated +from datetime import datetime + +from superdesk.core.resources import ResourceModelWithObjectId, fields +from superdesk.core.resources.validators import validate_data_relation_async + + +class DeliveryResourceModel(ResourceModelWithObjectId): + planning_id: Annotated[fields.Keyword, validate_data_relation_async("planning")] + coverage_id: str | None = None + assignment_id: Annotated[fields.ObjectId, validate_data_relation_async("assignments")] + item_id: str | None = None + item_state: str | None = None + sequence_no: int = Field(default=0) + publish_time: datetime | None = None + scheduled_update_id: str | None = None