Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 29 additions & 57 deletions app/slack/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ async def handle_mention(self, text: str) -> dict[str, Any]:
args = " ".join(parts[1:]) if len(parts) > 1 else ""

match action:
case "list":
return await self.handle_list_blocks()
case "pending":
return await self.handle_pending_blocks()
case "status":
return await self.handle_status_blocks(args)
case "rename":
return await self.handle_rename(args)
case "help":
return self._help_blocks()
case _:
Expand All @@ -44,60 +44,6 @@ async def handle_mention(self, text: str) -> dict[str, Any]:
"blocks": self._help_blocks()["blocks"],
}

async def handle_list_blocks(self) -> dict[str, Any]:
"""전체 학과 목록과 승인 여부를 Block Kit 형식으로 반환합니다."""
grads = await self.grad_repository.list_all_univ_majors()

if not grads:
return {"text": "📚 등록된 학과가 없습니다."}

approved_count = sum(
1 for g in grads if g.review_status == ReviewStatus.APPROVED
)
total_count = len(grads)

blocks: list[dict[str, Any]] = [
{
"type": "header",
"text": {
"type": "plain_text",
"text": f"📚 학과 목록 ({approved_count}/{total_count} 승인됨)",
},
},
{"type": "divider"},
]

for grad in grads:
if grad.review_status == ReviewStatus.APPROVED:
blocks.append(
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"✅ *{grad.name}*",
},
}
)
else:
blocks.append(
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"⏳ *{grad.name}* _(대기중)_",
},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "승인"},
"style": "primary",
"action_id": f"approve_grad_{grad.id}",
"value": str(grad.id),
},
}
)

return {"text": "학과 목록", "blocks": blocks}

async def handle_pending_blocks(self) -> dict[str, Any]:
"""대기중인 학과만 버튼과 함께 반환합니다."""
grads = await self.grad_repository.list_all_univ_majors()
Expand Down Expand Up @@ -170,6 +116,32 @@ async def handle_status_blocks(self, name: str) -> dict[str, Any]:
]
return {"text": f"{grad.name} 상태", "blocks": blocks}

async def handle_rename(self, args: str) -> dict[str, Any]:
"""학과 이름을 변경합니다. 사용법: @bot rename 기존이름 -> 새이름"""
if "->" not in args:
return {
"text": "❌ 사용법: `@bot rename 기존이름 -> 새이름`\n예: `@bot rename 홍익대 시각디자인 -> 홍익대학교 시각디자인과`"
}

parts = args.split("->")
if len(parts) != 2:
return {
"text": "❌ 사용법: `@bot rename 기존이름 -> 새이름`\n예: `@bot rename 홍익대 시각디자인 -> 홍익대학교 시각디자인과`"
}

old_name = parts[0].strip()
new_name = parts[1].strip()

if not old_name or not new_name:
return {"text": "❌ 기존 이름과 새 이름을 모두 입력해주세요."}

grad = await self.grad_repository.find_by_name(old_name)
if not grad:
return {"text": f"❌ `{old_name}` 학과를 찾을 수 없습니다."}

await self.grad_repository.update_name(grad.id, new_name)
return {"text": f"✏️ 이름이 변경되었습니다.\n`{old_name}` → `{new_name}`"}

async def handle_approve_button(self, grad_id: int, user_id: str) -> dict[str, Any]:
"""버튼 클릭으로 학과를 승인 처리합니다."""
grad = await self.grad_repository.find_by_id(grad_id)
Expand Down Expand Up @@ -198,9 +170,9 @@ def _help_blocks(self) -> dict[str, Any]:
"text": {
"type": "mrkdwn",
"text": (
"• `@bot list` - 전체 학과 목록과 승인 여부\n"
"• `@bot pending` - 대기중 학과 (승인 버튼 포함)\n"
"• `@bot status 학과명` - 특정 학과의 승인 여부\n"
"• `@bot rename 기존 -> 새이름` - 학과 이름 변경\n"
"• `@bot help` - 이 도움말 보기"
),
},
Expand Down
Loading