mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
Add collection api.
This commit is contained in:
@@ -191,3 +191,11 @@ export interface Activity {
|
||||
comment?: Comment;
|
||||
file?: RFile;
|
||||
}
|
||||
|
||||
export interface Collection {
|
||||
id: number;
|
||||
title: string;
|
||||
article: string;
|
||||
user: User;
|
||||
images: Image[];
|
||||
}
|
@@ -19,6 +19,7 @@ import {
|
||||
TagWithCount,
|
||||
Activity,
|
||||
CommentWithRef,
|
||||
Collection,
|
||||
} from "./models.ts";
|
||||
|
||||
class Network {
|
||||
@@ -688,6 +689,99 @@ class Network {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async createCollection(
|
||||
title: string,
|
||||
article: string,
|
||||
): Promise<Response<Collection>> {
|
||||
return this._callApi(() =>
|
||||
axios.postForm(`${this.apiBaseUrl}/collection/create`, {
|
||||
title,
|
||||
article,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async updateCollection(
|
||||
id: number,
|
||||
title: string,
|
||||
article: string,
|
||||
): Promise<Response<any>> {
|
||||
return this._callApi(() =>
|
||||
axios.postForm(`${this.apiBaseUrl}/collection/update`, {
|
||||
id,
|
||||
title,
|
||||
article,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async deleteCollection(id: number): Promise<Response<any>> {
|
||||
return this._callApi(() =>
|
||||
axios.postForm(`${this.apiBaseUrl}/collection/delete`, {
|
||||
id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async getCollection(id: number): Promise<Response<Collection>> {
|
||||
return this._callApi(() =>
|
||||
axios.get(`${this.apiBaseUrl}/collection/${id}`),
|
||||
);
|
||||
}
|
||||
|
||||
async listUserCollections(page: number = 1): Promise<PageResponse<Collection>> {
|
||||
return this._callApi(() =>
|
||||
axios.get(`${this.apiBaseUrl}/collection/list`, {
|
||||
params: { page },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async listCollectionResources(
|
||||
collectionId: number,
|
||||
page: number = 1,
|
||||
): Promise<PageResponse<Resource>> {
|
||||
return this._callApi(() =>
|
||||
axios.get(`${this.apiBaseUrl}/collection/${collectionId}/resources`, {
|
||||
params: { page },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async addResourceToCollection(
|
||||
collectionId: number,
|
||||
resourceId: number,
|
||||
): Promise<Response<any>> {
|
||||
return this._callApi(() =>
|
||||
axios.postForm(`${this.apiBaseUrl}/collection/add_resource`, {
|
||||
collection_id: collectionId,
|
||||
resource_id: resourceId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async removeResourceFromCollection(
|
||||
collectionId: number,
|
||||
resourceId: number,
|
||||
): Promise<Response<any>> {
|
||||
return this._callApi(() =>
|
||||
axios.postForm(`${this.apiBaseUrl}/collection/remove_resource`, {
|
||||
collection_id: collectionId,
|
||||
resource_id: resourceId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async searchUserCollections(
|
||||
keyword: string,
|
||||
): Promise<Response<Collection[]>> {
|
||||
return this._callApi(() =>
|
||||
axios.get(`${this.apiBaseUrl}/collection/search`, {
|
||||
params: { keyword },
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const network = new Network();
|
||||
|
Reference in New Issue
Block a user