Skip to content

feat(subscription): add skill subscription notification feature#356

Open
dongmucat wants to merge 33 commits intomainfrom
feature/skill-subscription-notification
Open

feat(subscription): add skill subscription notification feature#356
dongmucat wants to merge 33 commits intomainfrom
feature/skill-subscription-notification

Conversation

@dongmucat
Copy link
Copy Markdown
Collaborator

概述

实现技能订阅通知功能。用户可手动订阅技能,当技能发布新版本或版本被撤回时,系统通过现有通知中心向订阅者推送通知。

Closes #307

变更内容

后端实现

  • 新增 skill_subscription 表(Flyway V40 migration),包含 skill_iduser_idcreated_at 字段
  • 新增 SkillSubscription 领域实体、SkillSubscriptionRepository 接口及 JPA 实现
  • 新增 SkillSubscriptionService 领域服务,支持幂等订阅/取消订阅
  • 新增 SkillSubscriptionController REST 控制器,提供订阅/取消订阅/查询状态接口
  • Skill 实体新增 subscriptionCount 字段,订阅/取消时原子更新
  • MeController 新增 /me/subscriptions 端点,支持分页查询用户订阅列表
  • 新增 SkillVersionYankedEvent 领域事件,在版本撤回时发布
  • NotificationEventListener 新增两个监听方法:
    • SkillPublishedEvent → 通知订阅者(排除发布者自己)
    • SkillVersionYankedEvent → 通知订阅者(排除操作者自己)
  • 通知使用现有 PUBLISH 分类,event_type 为 SUBSCRIPTION_NEW_VERSION / SUBSCRIPTION_VERSION_YANKED

前端实现

  • 新增 use-subscription.ts — 订阅状态查询和切换的 TanStack Query hooks
  • 新增 subscribe-button.tsx — 订阅按钮组件(Bell 图标,显示订阅计数)
  • 技能详情页 Star 按钮旁新增 Subscribe 按钮
  • 新增 /dashboard/subscriptions 路由和 MySubscriptionsPage 页面
  • 用户菜单和 Dashboard 首页新增"我的订阅"入口
  • notification-content.ts 新增 SUBSCRIPTION_NEW_VERSIONSUBSCRIPTION_VERSION_YANKED 事件的中英文渲染
  • meApi 新增 getSubscriptionsPage / getSubscriptions 方法
  • 中英文 i18n 完整覆盖

测试覆盖

  • 后端单测:SkillSubscriptionServiceTest(6 个用例 — 订阅/取消/幂等/状态查询)
  • 后端集成测试:SkillSubscriptionControllerTest(7 个用例 — 三个端点的正常和异常场景)
  • 前端单测:use-subscription.test.ts(hook 导出契约验证)
  • E2E 测试:skill-subscription.spec.ts(订阅/取消订阅流程、订阅列表页)

API 端点

方法 路径 说明
PUT /api/web/skills/{skillId}/subscription 订阅技能
DELETE /api/web/skills/{skillId}/subscription 取消订阅
GET /api/web/skills/{skillId}/subscription 查询当前用户是否已订阅
GET /api/web/me/subscriptions?page=0&size=12 获取当前用户的订阅列表(分页)

质量门禁

  • make typecheck-web 通过(0 errors)
  • make lint-web 通过(0 errors, 0 warnings)
  • make test-frontend 通过(550 tests passed)
  • make test-backend-app 通过(427 tests passed)
  • make generate-api 已执行且 schema.d.ts 已提交

安全考虑

  • 订阅/取消订阅端点需要登录认证
  • 未认证用户查询订阅状态返回 false(不暴露信息)
  • subscriptionCount 通过 JPQL 原子更新,防止并发问题
  • 通知发送排除操作者自己,避免自我通知

本地验证步骤

  1. make dev-all 启动本地环境
  2. 登录后进入任意技能详情页,点击"订阅"按钮
  3. 验证按钮状态变为"已订阅",订阅计数 +1
  4. 访问 /dashboard/subscriptions 查看已订阅技能列表
  5. 返回详情页点击"已订阅"取消订阅,验证计数 -1
  6. 发布技能新版本,验证订阅者收到通知

@dongmucat dongmucat force-pushed the feature/skill-subscription-notification branch from 150e399 to 284b099 Compare April 29, 2026 01:54
Use .first() for h1 heading locator since skill detail page
renders two h1 elements (page title + README heading).
Add page-ready wait in second test before locating Subscribe button.
Published skills start in PENDING_REVIEW status with canInteract=false,
so the SubscribeButton is not rendered. Use admin user to approve the
review first, following the same pattern as search-seed and review-seed.
Include subscriptionCount in SkillDetailDTO and SkillDetailResponse
so the frontend SubscribeButton receives the updated count after
subscribe/unsubscribe mutations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 支持订阅通知的功能,订阅了该技能后,技能更新能通知使用者

1 participant