Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
自分の投稿したレビューを一覧で確認する機能を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroki SAKABE committed Jan 24, 2023
1 parent 204491e commit b725afd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
12 changes: 12 additions & 0 deletions lambda/app/bee_slack_app/view/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def home( # pylint: disable=too-many-locals
post_review_action_id: str,
list_user_posted_review_action_id: str,
user_info_action_id: str,
list_posted_review_action_id: str,
total_review_count: int,
user_name: str,
recommend_timestamp: str,
Expand All @@ -30,6 +31,7 @@ def home( # pylint: disable=too-many-locals
post_review_action_id: 「レビューを投稿する」ボタンのaction_id
list_user_posted_review_action_id: 「レビューを投稿したユーザ」ボタンのaction_id
user_info_action_id: 「プロフィール」ボタンのaction_id
list_posted_review_action_id: 「投稿したレビュー」ボタンのaction_id
total_review_count: 表示する「レビュー投稿数」
user_name:表示する「ユーザ名」
recommend_timestamp:MLのjsonファイルを作成した日時
Expand Down Expand Up @@ -172,6 +174,16 @@ def home( # pylint: disable=too-many-locals
"value": "dummy_value",
"action_id": user_info_action_id,
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "投稿したレビュー",
"emoji": True,
},
"value": "dummy_value",
"action_id": list_posted_review_action_id,
},
],
},
{"type": "divider"},
Expand Down
4 changes: 4 additions & 0 deletions lambda/app/bee_slack_app/view_controller/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def update_home_view(ack, event, client):
recommended_books=recommended_result["recommended_books"],
list_user_posted_review_action_id="list_user_posted_review_action",
user_info_action_id="user_info_action",
list_posted_review_action_id="list_posted_review_action",
total_review_count=total_review_count,
user_name=user_name,
recommend_timestamp=parse(recommended_result["created_at"]),
Expand Down Expand Up @@ -126,6 +127,7 @@ def home_move_to_next_action(ack, client, body): # pylint: disable=too-many-loc
recommended_books=recommended_result["recommended_books"],
list_user_posted_review_action_id="list_user_posted_review_action",
user_info_action_id="user_info_action",
list_posted_review_action_id="list_posted_review_action",
total_review_count=total_review_count,
user_name=user_name,
recommend_timestamp=parse(recommended_result["created_at"]),
Expand Down Expand Up @@ -187,6 +189,7 @@ def home_move_to_back_action(ack, client, body): # pylint: disable=too-many-loc
recommended_books=recommended_result["recommended_books"],
list_user_posted_review_action_id="list_user_posted_review_action",
user_info_action_id="user_info_action",
list_posted_review_action_id="list_posted_review_action",
total_review_count=total_review_count,
user_name=user_name,
recommend_timestamp=parse(recommended_result["created_at"]),
Expand Down Expand Up @@ -269,6 +272,7 @@ def handle_update_button_action(
recommended_books=recommended_books,
list_user_posted_review_action_id="list_user_posted_review_action",
user_info_action_id="user_info_action",
list_posted_review_action_id="list_posted_review_action",
total_review_count=total_review_count,
user_name=user_name,
recommend_timestamp=parse(recommended_result["created_at"]),
Expand Down
77 changes: 74 additions & 3 deletions lambda/app/bee_slack_app/view_controller/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from slack_bolt import App

from bee_slack_app.model import User
from bee_slack_app.service import user_action_service, user_service
from bee_slack_app.view import user_profile_modal
from bee_slack_app.model import Review, ReviewPagination, User
from bee_slack_app.service import review_service, user_action_service, user_service
from bee_slack_app.view import review_of_user_modal, simple_modal, user_profile_modal

BOOK_NUMBER_PER_PAGE = 20


def user_controller(app: App) -> None:
Expand Down Expand Up @@ -94,6 +96,75 @@ def handle_submission(ack, body, _, view):
payload={"user": user},
)

@app.action("list_posted_review_action")
def list_posted_review_action(ack, body, client):
ack()
user_id = body["user"]["id"]

review_items = review_service.get_next_reviews_by_user_id(
user_id=user_id, limit=BOOK_NUMBER_PER_PAGE, keys=[]
)

reviews = []

if review_items:
reviews = review_items["items"]
reviews = _make_review_contents_list_comment_short(reviews)

reviews_param: ReviewPagination = {
"reviews": reviews,
"show_move_to_back": False,
"show_move_to_next": review_items["has_next"],
}
# メタデータに変換する
metadata_str = _PrivateMetadataConvertor.to_private_metadata(
keys=review_items["keys"],
)

user_action_service.record_user_action(
user_id=user_id,
action_name="list_posted_review_action",
payload={"reviews": reviews},
)

if not reviews:
client.views_open(
trigger_id=body["trigger_id"],
view=simple_modal(title="エラー", text="レビュー取得でエラーが発生しました"),
)
return

client.views_open(
trigger_id=body["trigger_id"],
view=review_of_user_modal(
callback_id="review_of_user_modal",
reviews_param=reviews_param,
private_metadata=metadata_str,
),
)


def _make_review_contents_list_comment_short(
review_contents_list: list[Review],
) -> list[Review]:
"""
レビューのコメントを、一覧表示用に短くする
"""
comment_len = 20

for review_contents in review_contents_list:
review_comment = review_contents["review_comment"]
if review_comment:
review_contents["review_comment"] = (
review_comment[0:comment_len] + "..."
if len(review_comment) > comment_len
else review_comment
)
else:
review_contents["review_comment"] = "-"

return review_contents_list


class _PrivateMetadataConvertor:
class _MetadataDict(TypedDict):
Expand Down

0 comments on commit b725afd

Please sign in to comment.