feat(reset): 以构造器模式重构
- 加了大文件传输自定义分片协议 BREAKING CHANGES: 0.1.0(latest)
This commit is contained in:
122
api/post-api.ts
Normal file
122
api/post-api.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
import { GET, POST, ApiClientBound, Request } from '../decorators';
|
||||
import { API_ENDPOINTS } from './common';
|
||||
import type {
|
||||
CreatePostRequest,
|
||||
CreatePostResponse,
|
||||
GetPostsRequest,
|
||||
GetPostsResponse,
|
||||
LikePostRequest,
|
||||
LikePostResponse,
|
||||
BookmarkPostRequest,
|
||||
BookmarkPostResponse,
|
||||
CreateCommentRequest,
|
||||
CreateCommentResponse,
|
||||
GetCommentsRequest,
|
||||
GetCommentsResponse,
|
||||
GetHotPostsRequest,
|
||||
GetHotPostsResponse
|
||||
} from '../types';
|
||||
import type { AxiosHttpClient } from '../client';
|
||||
|
||||
/**
|
||||
* 帖子相关API服务类
|
||||
*/
|
||||
@ApiClientBound
|
||||
export class PostApiService {
|
||||
// 语法要求
|
||||
declare client: AxiosHttpClient;
|
||||
|
||||
/**
|
||||
* 创建新帖子
|
||||
* @param request 创建帖子请求参数
|
||||
* @returns 创建帖子响应
|
||||
* @throws ApiError 当请求失败时抛出
|
||||
*/
|
||||
@POST(API_ENDPOINTS.POSTS)
|
||||
@Request
|
||||
async createPost(_request: CreatePostRequest): Promise<CreatePostResponse> {
|
||||
// 实际请求逻辑由Request装饰器处理
|
||||
throw new Error('Decorated by @Request and should never be executed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取帖子列表
|
||||
* @param request 获取帖子列表请求参数
|
||||
* @returns 获取帖子列表响应
|
||||
* @throws ApiError 当请求失败时抛出
|
||||
*/
|
||||
@GET(API_ENDPOINTS.POSTS)
|
||||
@Request
|
||||
async getPosts(_request: GetPostsRequest): Promise<GetPostsResponse> {
|
||||
// 实际请求逻辑由Request装饰器处理
|
||||
throw new Error('Decorated by @Request and should never be executed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞帖子
|
||||
* @param request 点赞帖子请求参数
|
||||
* @returns 点赞帖子响应
|
||||
* @throws ApiError 当请求失败时抛出
|
||||
*/
|
||||
@POST(API_ENDPOINTS.POST_ONE_LIKES)
|
||||
@Request
|
||||
async likePost(_request: LikePostRequest): Promise<LikePostResponse> {
|
||||
// 实际请求逻辑由Request装饰器处理
|
||||
throw new Error('Decorated by @Request and should never be executed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏帖子
|
||||
* @param request 收藏帖子请求参数
|
||||
* @returns 收藏帖子响应
|
||||
* @throws ApiError 当请求失败时抛出
|
||||
*/
|
||||
@POST(API_ENDPOINTS.POST_ONE_STARS)
|
||||
@Request
|
||||
async bookmarkPost(_request: BookmarkPostRequest): Promise<BookmarkPostResponse> {
|
||||
// 实际请求逻辑由Request装饰器处理
|
||||
throw new Error('Decorated by @Request and should never be executed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建评论
|
||||
* @param request 创建评论请求参数
|
||||
* @returns 创建评论响应
|
||||
* @throws ApiError 当请求失败时抛出
|
||||
*/
|
||||
@POST(API_ENDPOINTS.POST_ONE_COMMENTS)
|
||||
@Request
|
||||
async createComment(_request: CreateCommentRequest): Promise<CreateCommentResponse> {
|
||||
// 实际请求逻辑由Request装饰器处理
|
||||
throw new Error('Decorated by @Request and should never be executed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论列表
|
||||
* @param request 获取评论列表请求参数
|
||||
* @returns 获取评论列表响应
|
||||
* @throws ApiError 当请求失败时抛出
|
||||
*/
|
||||
@GET(API_ENDPOINTS.POST_ONE_COMMENTS)
|
||||
@Request
|
||||
async getComments(_request: GetCommentsRequest): Promise<GetCommentsResponse> {
|
||||
// 实际请求逻辑由Request装饰器处理
|
||||
throw new Error('Decorated by @Request and should never be executed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门帖子
|
||||
* @param request 获取热门帖子请求参数
|
||||
* @returns 获取热门帖子响应
|
||||
* @throws ApiError 当请求失败时抛出
|
||||
*/
|
||||
@GET(API_ENDPOINTS.POSTS)
|
||||
@Request
|
||||
async getHotPosts(_request: GetHotPostsRequest): Promise<GetHotPostsResponse> {
|
||||
// 实际请求逻辑由Request装饰器处理
|
||||
throw new Error('Decorated by @Request and should never be executed.');
|
||||
}
|
||||
}
|
||||
|
||||
// 创建单例实例
|
||||
export const postApi = new PostApiService();
|
||||
Reference in New Issue
Block a user