-
Notifications
You must be signed in to change notification settings - Fork 4
fix: correct redemption API path and wallet query key #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Update redemptionService.ts to use /business/ instead of /redemption/ (backend mounts the router at /business prefix) - Fix query key mismatch in CheckInCalendar.tsx for wallet invalidation Co-Authored-By: Claude <noreply@anthropic.com>
审阅者指南(在较小 PR 上折叠)审阅者指南将与兑换相关的 API 端点从已弃用的 /redemption/ 命名空间调整为 /business/,并通过在签到操作后使用正确的钱包查询键来修复 React Query 的缓存失效问题。 使用已更正查询键的签到与钱包刷新时序图sequenceDiagram
actor User
participant CheckInCalendar
participant QueryClient
participant RedemptionService
participant BackendBusinessApi
User->>CheckInCalendar: clickCheckIn()
CheckInCalendar->>RedemptionService: redeemCode(code)
RedemptionService->>BackendBusinessApi: POST /xyzen/api/v1/business/redeem
BackendBusinessApi-->>RedemptionService: RedeemCodeResponse
RedemptionService-->>CheckInCalendar: RedeemCodeResponse
CheckInCalendar->>QueryClient: invalidateQueries([check-in])
CheckInCalendar->>QueryClient: invalidateQueries([userWallet])
QueryClient->>RedemptionService: getUserWallet()
RedemptionService->>BackendBusinessApi: GET /xyzen/api/v1/business/wallet
BackendBusinessApi-->>RedemptionService: UserWalletResponse
RedemptionService-->>QueryClient: UserWalletResponse
QueryClient-->>CheckInCalendar: updated userWallet data
CheckInCalendar-->>User: updated points display
更新后的 RedemptionService 业务端点类图classDiagram
class RedemptionService {
+redeemCode(code string) RedeemCodeResponse
+getUserWallet() UserWalletResponse
+getRedemptionHistory(limit number, offset number) RedemptionHistoryResponse[]
+getDailyTokenStats(date string, tz string) DailyTokenStatsResponse
+getTopUsers(limit number) UserConsumptionResponse[]
+getConsumeRecords(startDate string, endDate string, limit number, offset number) ConsumeRecordResponse[]
+getDailyUserActivity(startDate string, endDate string, limit number, offset number, tz string) DailyUserActivityResponse[]
}
class BackendBusinessApi {
+POST_xyzen_api_v1_business_redeem()
+GET_xyzen_api_v1_business_wallet()
+GET_xyzen_api_v1_business_history()
+GET_xyzen_api_v1_business_admin_stats_daily_tokens()
+GET_xyzen_api_v1_business_admin_stats_top_users()
+GET_xyzen_api_v1_business_admin_stats_consume_records()
+GET_xyzen_api_v1_business_admin_stats_user_activity()
}
RedemptionService --> BackendBusinessApi
文件级变更
技巧与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts redemption-related API endpoints from the deprecated /redemption/ namespace to /business/ and fixes React Query cache invalidation by using the correct wallet query key after check-in operations. Sequence diagram for check-in and wallet refresh with corrected query keysequenceDiagram
actor User
participant CheckInCalendar
participant QueryClient
participant RedemptionService
participant BackendBusinessApi
User->>CheckInCalendar: clickCheckIn()
CheckInCalendar->>RedemptionService: redeemCode(code)
RedemptionService->>BackendBusinessApi: POST /xyzen/api/v1/business/redeem
BackendBusinessApi-->>RedemptionService: RedeemCodeResponse
RedemptionService-->>CheckInCalendar: RedeemCodeResponse
CheckInCalendar->>QueryClient: invalidateQueries([check-in])
CheckInCalendar->>QueryClient: invalidateQueries([userWallet])
QueryClient->>RedemptionService: getUserWallet()
RedemptionService->>BackendBusinessApi: GET /xyzen/api/v1/business/wallet
BackendBusinessApi-->>RedemptionService: UserWalletResponse
RedemptionService-->>QueryClient: UserWalletResponse
QueryClient-->>CheckInCalendar: updated userWallet data
CheckInCalendar-->>User: updated points display
Updated class diagram for RedemptionService business endpointsclassDiagram
class RedemptionService {
+redeemCode(code string) RedeemCodeResponse
+getUserWallet() UserWalletResponse
+getRedemptionHistory(limit number, offset number) RedemptionHistoryResponse[]
+getDailyTokenStats(date string, tz string) DailyTokenStatsResponse
+getTopUsers(limit number) UserConsumptionResponse[]
+getConsumeRecords(startDate string, endDate string, limit number, offset number) ConsumeRecordResponse[]
+getDailyUserActivity(startDate string, endDate string, limit number, offset number, tz string) DailyUserActivityResponse[]
}
class BackendBusinessApi {
+POST_xyzen_api_v1_business_redeem()
+GET_xyzen_api_v1_business_wallet()
+GET_xyzen_api_v1_business_history()
+GET_xyzen_api_v1_business_admin_stats_daily_tokens()
+GET_xyzen_api_v1_business_admin_stats_top_users()
+GET_xyzen_api_v1_business_admin_stats_consume_records()
+GET_xyzen_api_v1_business_admin_stats_user_activity()
}
RedemptionService --> BackendBusinessApi
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - 我发现了 1 个问题,并给出了一些总体性反馈:
- 现在有多个方法使用
/xyzen/api/v1/business作为基础路径,建议把这段路径提取为一个共享常量或辅助方法,这样当端点再次变更时可以避免出现不一致。 - React Query 的 key
"userWallet"目前只是一个普通字符串;将其定义为一个共享常量(并在定义查询的地方重复使用)可以降低因为拼写错误或不一致而导致缓存失效问题的风险。
给 AI 智能体的提示
Please address the comments from this code review:
## Overall Comments
- 现在有多个方法使用 `/xyzen/api/v1/business` 作为基础路径,建议把这段路径提取为一个共享常量或辅助方法,这样当端点再次变更时可以避免出现不一致。
- React Query 的 key `"userWallet"` 目前只是一个普通字符串;将其定义为一个共享常量(并在定义查询的地方重复使用)可以降低因为拼写错误或不一致而导致缓存失效问题的风险。
## Individual Comments
### Comment 1
<location> `web/src/service/redemptionService.ts:98-101` </location>
<code_context>
async redeemCode(code: string): Promise<RedeemCodeResponse> {
const response = await fetch(
- `${this.getBackendUrl()}/xyzen/api/v1/redemption/redeem`,
+ `${this.getBackendUrl()}/xyzen/api/v1/business/redeem`,
{
method: "POST",
</code_context>
<issue_to_address>
**suggestion:** 建议为 `/xyzen/api/v1/business` 这个前缀提取一个共享的基础路径,以减少重复代码,并降低未来路由变更时的风险。
由于这些调用都使用相同的 `${this.getBackendUrl()}/xyzen/api/v1/business` 前缀(其中一些还会追加 `admin/stats`),可以考虑将这些片段统一定义一次(例如作为类属性或辅助方法)并复用。这样可以让后续的路由变更更加安全,避免遗漏单独的调用点。
建议实现方式:
```typescript
export class RedemptionService {
private getBusinessBaseUrl(): string {
return `${this.getBackendUrl()}/xyzen/api/v1/business`;
}
```
```typescript
async redeemCode(code: string): Promise<RedeemCodeResponse> {
const response = await fetch(
`${this.getBusinessBaseUrl()}/redeem`,
{
```
```typescript
async getUserWallet(): Promise<UserWalletResponse> {
const response = await fetch(
`${this.getBusinessBaseUrl()}/wallet`,
{
```
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- Now that multiple methods use the
/xyzen/api/v1/businessbase path, consider extracting this segment into a shared constant or helper to avoid future inconsistencies when endpoints change again. - The React Query key
"userWallet"is currently a bare string; defining it as a shared constant (and reusing it where the query is defined) would reduce the risk of subtle cache invalidation bugs from typos or mismatches.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Now that multiple methods use the `/xyzen/api/v1/business` base path, consider extracting this segment into a shared constant or helper to avoid future inconsistencies when endpoints change again.
- The React Query key `"userWallet"` is currently a bare string; defining it as a shared constant (and reusing it where the query is defined) would reduce the risk of subtle cache invalidation bugs from typos or mismatches.
## Individual Comments
### Comment 1
<location> `web/src/service/redemptionService.ts:98-101` </location>
<code_context>
async redeemCode(code: string): Promise<RedeemCodeResponse> {
const response = await fetch(
- `${this.getBackendUrl()}/xyzen/api/v1/redemption/redeem`,
+ `${this.getBackendUrl()}/xyzen/api/v1/business/redeem`,
{
method: "POST",
</code_context>
<issue_to_address>
**suggestion:** Consider extracting a shared base path for the `/xyzen/api/v1/business` prefix to reduce duplication and risk on future route changes.
Since all these calls use the same `${this.getBackendUrl()}/xyzen/api/v1/business` prefix (and some also add `admin/stats`), consider defining these segments once (e.g., as class properties or helper methods) and reusing them. This will make future route changes safer and avoid missing individual call sites.
Suggested implementation:
```typescript
export class RedemptionService {
private getBusinessBaseUrl(): string {
return `${this.getBackendUrl()}/xyzen/api/v1/business`;
}
```
```typescript
async redeemCode(code: string): Promise<RedeemCodeResponse> {
const response = await fetch(
`${this.getBusinessBaseUrl()}/redeem`,
{
```
```typescript
async getUserWallet(): Promise<UserWalletResponse> {
const response = await fetch(
`${this.getBusinessBaseUrl()}/wallet`,
{
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
## [1.0.5](v1.0.4...v1.0.5) (2026-01-21) ### 🐛 Bug Fixes * correct redemption API path and wallet query key ([#190](#190)) ([eae25d5](eae25d5))
|
🎉 This PR is included in version 1.0.5 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
/redemption/to/business/["userWallet"]instead of["wallet"]Test plan
🤖 Generated with Claude Code
Summary by Sourcery
更新与钱包相关的 API 端点以及查询缓存失效逻辑,以使用正确的业务路径和查询键。
Bug 修复:
/redemption更正为使用/business命名空间,以防止出现 404 错误。userWallet查询键进行失效处理。Original summary in English
Summary by Sourcery
Update wallet-related API endpoints and query cache invalidation to use the correct business paths and query key.
Bug Fixes: