~homeworkprod/byceps

9f39127651bce3797d874c44c8a1209e50e007df — Jochen Kupperschmidt 2 years ago 983f664
Only pass board posting's ID to services
M byceps/blueprints/board/views_posting.py => byceps/blueprints/board/views_posting.py +5 -3
@@ 196,7 196,7 @@ def posting_update(posting_id):
        return posting_update_form(posting_id, form)

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

    flash_success('Der Beitrag wurde aktualisiert.')


@@ 231,7 231,7 @@ def posting_hide(posting_id):
    posting = h.get_posting_or_404(posting_id)
    moderator_id = g.current_user.id

    event = board_posting_command_service.hide_posting(posting, moderator_id)
    event = board_posting_command_service.hide_posting(posting.id, moderator_id)

    page = service.calculate_posting_page_number(posting, g.current_user)



@@ 253,7 253,9 @@ def posting_unhide(posting_id):
    posting = h.get_posting_or_404(posting_id)
    moderator_id = g.current_user.id

    event = board_posting_command_service.unhide_posting(posting, moderator_id)
    event = board_posting_command_service.unhide_posting(
        posting.id, moderator_id
    )

    page = service.calculate_posting_page_number(posting, g.current_user)


M byceps/services/board/posting_command_service.py => byceps/services/board/posting_command_service.py +15 -4
@@ 21,8 21,9 @@ from ...typing import UserID
from .aggregation_service import aggregate_topic
from .models.posting import Posting as DbPosting
from .models.topic import Topic as DbTopic
from . import posting_query_service
from . import topic_query_service
from .transfer.models import TopicID
from .transfer.models import PostingID, TopicID


def create_posting(


@@ 45,9 46,11 @@ def create_posting(


def update_posting(
    posting: DbPosting, editor_id: UserID, body: str, *, commit: bool = True
    posting_id: PostingID, editor_id: UserID, body: str, *, commit: bool = True
) -> BoardPostingUpdated:
    """Update the posting."""
    posting = _get_posting(posting_id)

    now = datetime.utcnow()

    posting.body = body.strip()


@@ 64,9 67,11 @@ def update_posting(


def hide_posting(
    posting: DbPosting, moderator_id: UserID
    posting_id: PostingID, moderator_id: UserID
) -> BoardPostingHidden:
    """Hide the posting."""
    posting = _get_posting(posting_id)

    now = datetime.utcnow()

    posting.hidden = True


@@ 87,9 92,11 @@ def hide_posting(


def unhide_posting(
    posting: DbPosting, moderator_id: UserID
    posting_id: PostingID, moderator_id: UserID
) -> BoardPostingUnhidden:
    """Un-hide the posting."""
    posting = _get_posting(posting_id)

    now = datetime.utcnow()

    # TODO: Store who un-hid the posting.


@@ 108,3 115,7 @@ def unhide_posting(
    )

    return event


def _get_posting(posting_id: PostingID) -> DbPosting:
    return posting_query_service.get_posting(posting_id)

M byceps/services/board/posting_query_service.py => byceps/services/board/posting_query_service.py +10 -0
@@ 34,6 34,16 @@ def find_posting_by_id(posting_id: PostingID) -> Optional[DbPosting]:
    return DbPosting.query.get(posting_id)


def get_posting(posting_id: PostingID) -> DbPosting:
    """Return the posting with that id."""
    posting = find_posting_by_id(posting_id)

    if posting is None:
        raise ValueError(f'Unknown posting ID "{posting_id}"')

    return posting


def paginate_postings(
    topic_id: TopicID,
    user: CurrentUser,

M byceps/services/board/topic_command_service.py => byceps/services/board/topic_command_service.py +1 -1
@@ 65,7 65,7 @@ def update_topic(
    topic.title = title.strip()

    posting_event = update_posting(
        topic.initial_posting, editor_id, body, commit=False
        topic.initial_posting.id, editor_id, body, commit=False
    )

    db.session.commit()