Skip to content

Commit

Permalink
[SDESK-7461] - Assignment Delivery async resource & service (#2157)
Browse files Browse the repository at this point in the history
* Created assignment delivery async resource and service

* Suggested fixes
  • Loading branch information
BrianMwangi21 authored Dec 16, 2024
1 parent 3bfad45 commit fcbea1f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
5 changes: 3 additions & 2 deletions server/planning/assignments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions server/planning/assignments/delivery_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from planning.types import DeliveryResourceModel
from superdesk.core.resources import AsyncResourceService


class DeliveryAsyncService(AsyncResourceService[DeliveryResourceModel]):
pass
37 changes: 36 additions & 1 deletion server/planning/assignments/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
),
],
),
)
3 changes: 2 additions & 1 deletion server/planning/module.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -12,5 +12,6 @@
planning_resource_config,
assignments_resource_config,
published_resource_config,
delivery_resource_config,
],
)
2 changes: 2 additions & 0 deletions server/planning/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +25,7 @@

__all__ = [
"BasePlanningModel",
"DeliveryResourceModel",
"EventResourceModel",
"PlanningResourceModel",
"AssignmentResourceModel",
Expand Down
17 changes: 17 additions & 0 deletions server/planning/types/delivery.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fcbea1f

Please sign in to comment.