Unnotified is better than unseen
This commit is contained in:
parent
b601a8fbe8
commit
bf08335382
2 changed files with 19 additions and 12 deletions
|
|
@ -22,8 +22,8 @@ if TYPE_CHECKING:
|
|||
class SubscriptionModel(Base):
|
||||
__tablename__ = 'subscription'
|
||||
__table_args__ = (
|
||||
# Don't allow any weird avlues for sequence_seen
|
||||
CheckConstraint('sequence_seen >= 1', name='sequence_seen_gte_1'),
|
||||
# Don't allow any weird avlues for sequence_notified
|
||||
CheckConstraint('sequence_notified >= 1', name='sequence_notified_gte_1'),
|
||||
# Ensure a user can't create multiple subscriptions to the same order
|
||||
UniqueConstraint('order_id', 'user_id'),
|
||||
)
|
||||
|
|
@ -39,7 +39,7 @@ class SubscriptionModel(Base):
|
|||
order: Mapped['PublicationOrderModel'] = relationship()
|
||||
|
||||
# Which position into the sequence is available to the user
|
||||
sequence_seen: Mapped[int] = mapped_column(server_default='1', default=1)
|
||||
sequence_notified: Mapped[int] = mapped_column(server_default='1', default=1)
|
||||
|
||||
# When the user's subscription began.
|
||||
start: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
|
@ -50,13 +50,16 @@ def model_to_subscription(db_sub: SubscriptionModel) -> Subscription:
|
|||
id=db_sub.id,
|
||||
user_id=db_sub.user_id,
|
||||
publication_order=model_to_order(db_sub.order).to_profile(),
|
||||
sequence_seen=db_sub.sequence_seen,
|
||||
sequence_notified=db_sub.sequence_notified,
|
||||
start=db_sub.start,
|
||||
)
|
||||
|
||||
|
||||
def mutate_subscription(db_sub: SubscriptionModel, sub: Subscription):
|
||||
pass
|
||||
db_sub.order_id = sub.publication_order.id
|
||||
db_sub.user_id = sub.user_id
|
||||
db_sub.start = sub.start
|
||||
db_sub.sequence_notified = sub.sequence_notified
|
||||
|
||||
|
||||
class SubscriptionRepoImpl(SubscriptionRepo, CRUDRepo[SubscriptionModel, Subscription, SubscriptionCreateParams]):
|
||||
|
|
@ -94,7 +97,11 @@ class SubscriptionRepoImpl(SubscriptionRepo, CRUDRepo[SubscriptionModel, Subscri
|
|||
return model_to_subscription(db_sub)
|
||||
|
||||
def get_available_entries(self, user_id: int) -> dict[SubscriptionId, list[AvailableSubscriptionEntry]]:
|
||||
# TODO: This needs to actually look at the sequence seen and the entry release times to work out which items
|
||||
# are available or not.
|
||||
return {}
|
||||
|
||||
def get_unseen_available_subscription_entries(self, user_id: int) -> list[AvailableSubscriptionEntry]:
|
||||
pass
|
||||
def get_unnotified_available_subscription_entries(self, user_id: int) -> list[AvailableSubscriptionEntry]:
|
||||
# TODO: This needs to look at the sequences to decide which items are available and then filter that to ones
|
||||
# that are newer than `sequence_notified`
|
||||
return []
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ class Subscription:
|
|||
id: SubscriptionId
|
||||
user_id: int
|
||||
publication_order: PublicationOrderProfile
|
||||
sequence_seen: int
|
||||
sequence_notified: int
|
||||
start: datetime
|
||||
|
||||
|
||||
@dataclass
|
||||
class UpdateSubscription:
|
||||
id: int
|
||||
sequence_seen: int | None = None
|
||||
sequence_notified: int | None = None
|
||||
start: datetime | None = None
|
||||
|
||||
|
||||
|
|
@ -51,10 +51,10 @@ class SubscriptionRepo(CRUD[Subscription, SubscriptionCreateParams]):
|
|||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_unseen_available_subscription_entries(self, user_id: int) -> list[AvailableSubscriptionEntry]:
|
||||
def get_unnotified_available_subscription_entries(self, user_id: int) -> list[AvailableSubscriptionEntry]:
|
||||
"""
|
||||
Get all publication entries that _should_ be available to the user given the timeline but are newer than the
|
||||
`sequence_seen` value from the subscription
|
||||
`sequence_notified` value from the subscription
|
||||
"""
|
||||
pass
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ class SubscriptionService:
|
|||
return self._repo.get_subscriptions_for_user(user_id)
|
||||
|
||||
def get_updates(self, user_id: int) -> list[AvailableSubscriptionEntry]:
|
||||
return self._repo.get_unseen_available_subscription_entries(user_id)
|
||||
return self._repo.get_unnotified_available_subscription_entries(user_id)
|
||||
|
||||
def get_all_available_entries(self, user_id: int) -> dict[SubscriptionId, list[AvailableSubscriptionEntry]]:
|
||||
return self._repo.get_available_entries(user_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue