fix: align favorites page with post adapter
Some checks failed
Deploy Staging (terry-wallet-login) / deploy (push) Failing after 28s
Some checks failed
Deploy Staging (terry-wallet-login) / deploy (push) Failing after 28s
This commit is contained in:
@@ -187,7 +187,13 @@ If backend decides to keep the simplified `{ address }` login, please explicitly
|
||||
|
||||
## Priority 2 — Normalize favorites response contract
|
||||
|
||||
Frontend currently supports the staging response shape, but the response should be made explicit.
|
||||
Frontend currently supports the staging response shape, but the response must be made explicit and self-sufficient. The frontend renders favorites as plain strings and does not perform per-resource translation, slug-to-name lookup, category fetching, or localization fallback.
|
||||
|
||||
### `lang` semantics
|
||||
|
||||
`?lang=<ui-lang>` on `GET /api/favorites` is a **display resolution hint**, not a filter. It must NOT filter favorites by post language. A user who favorited Chinese and English posts must see both regardless of `lang`. `lang` only tells the backend which language to resolve display strings into.
|
||||
|
||||
**Current staging behavior is wrong**: sending `?lang=en` on staging returns zero items for users whose favorites are Chinese posts, and vice versa. Because of this, the frontend currently does NOT send `lang` on `GET /api/favorites`. Once the backend treats `lang` as a resolve hint instead of a filter, the frontend will send `lang` again so resolved strings come back in the user's UI language.
|
||||
|
||||
### Favorites list
|
||||
|
||||
@@ -196,36 +202,50 @@ GET /api/favorites?lang=&limit=&page=&sort=&category=&q=
|
||||
Authorization: Bearer <token>
|
||||
```
|
||||
|
||||
Current staging response observed:
|
||||
Required production response:
|
||||
|
||||
```json
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"id": "...",
|
||||
"postType": "image",
|
||||
"title": "...",
|
||||
"description": "...",
|
||||
"type": "...",
|
||||
"categoryId": 11,
|
||||
"categorySlug": "official-assets",
|
||||
"language": "zh",
|
||||
"title": "..."
|
||||
"categoryName": "...",
|
||||
"language": "...",
|
||||
"sourceLanguage": "...",
|
||||
"coverImage": "...",
|
||||
"updatedAt": "...",
|
||||
"publishedAt": "...",
|
||||
"favoriteCount": 0,
|
||||
"availability": "available"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Recommended production response:
|
||||
|
||||
```json
|
||||
{
|
||||
"items": [],
|
||||
],
|
||||
"page": 1,
|
||||
"limit": 24,
|
||||
"total": 0
|
||||
}
|
||||
```
|
||||
|
||||
Fields that must be present and pre-resolved by the backend when `lang` is supplied:
|
||||
|
||||
- `title` — already in `lang`. If a translation does not exist, fall back to the post's source language.
|
||||
- `description` — same rule as `title`.
|
||||
- `categoryName` — localized category name for `lang`. Frontend must not look up categories by slug.
|
||||
- `type` — a string the frontend can display directly. If you need both a raw type code and a label, add `typeLabel` and use that for display.
|
||||
- `language` — a human-readable label for the post's source language, in `lang`. e.g. for `lang=zh-CN` a Chinese post returns `language: "中文"`. If you prefer to keep `language` as a code, add `languageLabel` and use it for display.
|
||||
- `coverImage` — a usable image URL. The frontend will not fall back to attachment arrays.
|
||||
- `updatedAt`, `publishedAt` — ISO timestamps.
|
||||
- `favoriteCount` — optional but recommended.
|
||||
- `availability` — `"available" | "unavailable"`.
|
||||
|
||||
`page`, `limit`, and `total` are needed for correct pagination.
|
||||
|
||||
The frontend must never need to: load `/api/categories`, parse `localizations` maps, walk `attachments`, or translate `type` / `language` codes for this page.
|
||||
|
||||
### Favorite status by ids
|
||||
|
||||
```http
|
||||
|
||||
Reference in New Issue
Block a user