mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: frontend create & delete collections
This commit is contained in:
parent
bca6c3000a
commit
ce785fd078
6 changed files with 255 additions and 9 deletions
73
front/services/collections.ts
Normal file
73
front/services/collections.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { getAPIUrl } from "./config";
|
||||
|
||||
export async function getOrgCollections(org_slug: any) {
|
||||
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
|
||||
const requestOptions: any = {
|
||||
method: "GET",
|
||||
headers: HeadersConfig,
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
};
|
||||
|
||||
return fetch(`${getAPIUrl()}collections/page/1/limit/10`, requestOptions)
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
}
|
||||
|
||||
export async function getCollection(collection_slug: any) {
|
||||
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
|
||||
const requestOptions: any = {
|
||||
method: "GET",
|
||||
headers: HeadersConfig,
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
};
|
||||
|
||||
return fetch(
|
||||
`${getAPIUrl()}collections/${collection_slug}`,
|
||||
requestOptions
|
||||
)
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export async function deleteCollection(collection_id: any) {
|
||||
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
|
||||
const requestOptions: any = {
|
||||
method: "DELETE",
|
||||
headers: HeadersConfig,
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
};
|
||||
|
||||
return fetch(
|
||||
`${getAPIUrl()}collections/${collection_id}`,
|
||||
requestOptions
|
||||
)
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
}
|
||||
|
||||
// Create a new collection
|
||||
export async function createCollection(collection: any) {
|
||||
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||
|
||||
const requestOptions: any = {
|
||||
method: "POST",
|
||||
headers: HeadersConfig,
|
||||
redirect: "follow",
|
||||
credentials: "include",
|
||||
body: JSON.stringify(collection),
|
||||
};
|
||||
|
||||
return fetch(`${getAPIUrl()}collections/`, requestOptions)
|
||||
.then((result) => result.json())
|
||||
.catch((error) => console.log("error", error));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue