~homeworkprod/byceps

f08dd40a01dab23603e1004a351303adeff45d3a — Jochen Kupperschmidt 2 years ago 1b4690d
Introduce update events for board topics and postings
M byceps/blueprints/board/signals.py => byceps/blueprints/board/signals.py +2 -0
@@ 15,6 15,7 @@ board_signals = Namespace()
# postings

posting_created = board_signals.signal('posting-created')
posting_updated = board_signals.signal('posting-updated')

posting_hidden = board_signals.signal('posting-hidden')
posting_unhidden = board_signals.signal('posting-unhidden')


@@ 23,6 24,7 @@ posting_unhidden = board_signals.signal('posting-unhidden')
# topics

topic_created = board_signals.signal('topic-created')
topic_updated = board_signals.signal('topic-updated')

topic_hidden = board_signals.signal('topic-hidden')
topic_unhidden = board_signals.signal('topic-unhidden')

M byceps/blueprints/board/views_posting.py => byceps/blueprints/board/views_posting.py +7 -1
@@ 195,11 195,17 @@ def posting_update(posting_id):
    if not form.validate():
        return posting_update_form(posting_id, form)

    board_posting_command_service.update_posting(
    event = board_posting_command_service.update_posting(
        posting, g.current_user.id, form.body.data
    )

    flash_success('Der Beitrag wurde aktualisiert.')

    event = dataclasses.replace(
        event, url=h.build_external_url_for_posting(posting.id)
    )
    signals.posting_updated.send(None, event=event)

    return redirect(url)



M byceps/events/board.py => byceps/events/board.py +10 -0
@@ 32,6 32,11 @@ class BoardTopicCreated(_BoardTopicEvent):


@dataclass(frozen=True)
class BoardTopicUpdated(_BoardTopicEvent):
    editor_id: UserID


@dataclass(frozen=True)
class BoardTopicHidden(_BoardTopicModerationEvent):
    pass



@@ 87,6 92,11 @@ class BoardPostingCreated(_BoardPostingEvent):


@dataclass(frozen=True)
class BoardPostingUpdated(_BoardPostingEvent):
    editor_id: UserID


@dataclass(frozen=True)
class BoardPostingHidden(_BoardPostingModerationEvent):
    pass


M byceps/services/board/posting_command_service.py => byceps/services/board/posting_command_service.py +6 -1
@@ 14,6 14,7 @@ from ...events.board import (
    BoardPostingCreated,
    BoardPostingHidden,
    BoardPostingUnhidden,
    BoardPostingUpdated,
)
from ...typing import UserID



@@ 39,7 40,7 @@ def create_posting(

def update_posting(
    posting: DbPosting, editor_id: UserID, body: str, *, commit: bool = True
) -> None:
) -> BoardPostingUpdated:
    """Update the posting."""
    posting.body = body.strip()
    posting.last_edited_at = datetime.utcnow()


@@ 49,6 50,10 @@ def update_posting(
    if commit:
        db.session.commit()

    return BoardPostingUpdated(
        posting_id=posting.id, editor_id=editor_id, url=None
    )


def hide_posting(
    posting: DbPosting, moderator_id: UserID

M byceps/services/board/topic_command_service.py => byceps/services/board/topic_command_service.py +4 -1
@@ 19,6 19,7 @@ from ...events.board import (
    BoardTopicUnhidden,
    BoardTopicUnlocked,
    BoardTopicUnpinned,
    BoardTopicUpdated,
)
from ...typing import UserID



@@ 54,7 55,7 @@ def create_topic(

def update_topic(
    topic: DbTopic, editor_id: UserID, title: str, body: str
) -> None:
) -> BoardTopicUpdated:
    """Update the topic (and its initial posting)."""
    topic.title = title.strip()



@@ 62,6 63,8 @@ def update_topic(

    db.session.commit()

    return BoardTopicUpdated(topic_id=topic.id, editor_id=editor_id, url=None)


def hide_topic(topic: DbTopic, moderator_id: UserID) -> BoardTopicHidden:
    """Hide the topic."""