refactor(api): use resource-oriented endpoints in frontend#3181
Conversation
There was a problem hiding this comment.
Code Review
This pull request performs an extensive refactoring of the API client and endpoint definitions, primarily pluralizing resource paths (e.g., changing /project to /projects) and renaming functions for better clarity. It introduces more specific listing functions for assets, projects, and courses to replace generic ones, and migrates AI description generation to the AIGC module. Additionally, a new put method was added to the base Client class. Feedback was provided to default the payload in the put method to an empty object to ensure consistent Content-Type headers and prevent potential backend parsing errors.
This comment was marked as resolved.
This comment was marked as resolved.
Update frontend API clients and call sites to use the resource-oriented contract from `docs/openapi.yaml`. Split collection helpers by ownership scope, rename API modules around current resource names, and pass the `/ai-interaction` base endpoint to the runtime AI transport. Fixes goplus#3144 Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
| return client.get('/course-series', params, { signal }) as Promise<ByPage<CourseSeries>> | ||
| } | ||
|
|
||
| /** List all course series (owned by all users) by order. 100 items at most. */ | ||
| export async function listAllCourseSeriesByOrder(signal?: AbortSignal) { | ||
| const result = await listCourseSeries( | ||
| { owner: ownerAll, pageIndex: 1, pageSize: 100, orderBy: 'order', sortOrder: 'asc' }, | ||
| signal | ||
| ) | ||
| return result.data | ||
| export function listSignedInUserCourseSeries(params?: ListCourseSeriesParams, signal?: AbortSignal) { | ||
| return client.get('/user/course-series', params, { signal }) as Promise<ByPage<CourseSeries>> |
There was a problem hiding this comment.
NIP: 去掉 /list 后缀挺好的,但我个人感觉 restful 接口更常见的做法是对同一种资源的 path 用同一个,通过参数来区分 owner / visibility
There was a problem hiding this comment.
我们这次主要参考的是 GitHub REST API 的风格。比如 GitHub 是用 GET /user/repos 表示当前登录用户的仓库,用 GET /users/{username}/repos 表示某个用户的仓库,用 GET /repositories 表示全局公开仓库列表。
我们这里用 query 参数虽然也可以做,但会让一个 endpoint 承担太多语义,也比较容易重新引入类似 owner=me / owner=* 这种特殊约定,这也是这次想解决的问题之一。
现在这种 /course-series、/user/course-series、/users/{username}/course-series 的拆法,可以更明确地表达“当前用户的资源”、“某个用户的公开资源”、“全局可见资源”这几种不同上下文。
Update frontend API clients and call sites to use the resource-oriented contract from
docs/openapi.yaml.Split collection helpers by ownership scope, rename API modules around current resource names, and pass the
/ai-interactionbase endpoint to the runtime AI transport.Fixes #3144