refactored api routes
This commit is contained in:
parent
b0e92c6253
commit
8dfd1598f3
|
@ -33,7 +33,7 @@ export default function useLinks(
|
||||||
const encodedData = encodeURIComponent(JSON.stringify(requestBody));
|
const encodedData = encodeURIComponent(JSON.stringify(requestBody));
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/routes/links?body=${encodeURIComponent(encodedData)}`
|
`/api/links?body=${encodeURIComponent(encodedData)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
|
@ -17,7 +17,7 @@ const getPublicCollectionData = async (
|
||||||
const encodedData = encodeURIComponent(JSON.stringify(requestBody));
|
const encodedData = encodeURIComponent(JSON.stringify(requestBody));
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
"/api/public/routes/collections?body=" + encodeURIComponent(encodedData)
|
"/api/public/collections?body=" + encodeURIComponent(encodedData)
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
|
@ -8,7 +8,7 @@ export default async function getPublicUserData({
|
||||||
id?: number;
|
id?: number;
|
||||||
}) {
|
}) {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/routes/users?id=${id}&${
|
`/api/users?id=${id}&${
|
||||||
username ? `username=${username?.toLowerCase()}` : undefined
|
username ? `username=${username?.toLowerCase()}` : undefined
|
||||||
}`
|
}`
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,7 +15,7 @@ type AccountStore = {
|
||||||
const useAccountStore = create<AccountStore>()((set) => ({
|
const useAccountStore = create<AccountStore>()((set) => ({
|
||||||
account: {} as AccountSettings,
|
account: {} as AccountSettings,
|
||||||
setAccount: async (id) => {
|
setAccount: async (id) => {
|
||||||
const response = await fetch(`/api/routes/users?id=${id}`);
|
const response = await fetch(`/api/users?id=${id}`);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ const useAccountStore = create<AccountStore>()((set) => ({
|
||||||
if (response.ok) set({ account: { ...data.response, profilePic } });
|
if (response.ok) set({ account: { ...data.response, profilePic } });
|
||||||
},
|
},
|
||||||
updateAccount: async (user) => {
|
updateAccount: async (user) => {
|
||||||
const response = await fetch("/api/routes/users", {
|
const response = await fetch("/api/users", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
body: JSON.stringify(user),
|
body: JSON.stringify(user),
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
@ -22,14 +22,14 @@ type CollectionStore = {
|
||||||
const useCollectionStore = create<CollectionStore>()((set) => ({
|
const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||||
collections: [],
|
collections: [],
|
||||||
setCollections: async () => {
|
setCollections: async () => {
|
||||||
const response = await fetch("/api/routes/collections");
|
const response = await fetch("/api/collections");
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (response.ok) set({ collections: data.response });
|
if (response.ok) set({ collections: data.response });
|
||||||
},
|
},
|
||||||
addCollection: async (body) => {
|
addCollection: async (body) => {
|
||||||
const response = await fetch("/api/routes/collections", {
|
const response = await fetch("/api/collections", {
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -47,7 +47,7 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||||
return { ok: response.ok, data: data.response };
|
return { ok: response.ok, data: data.response };
|
||||||
},
|
},
|
||||||
updateCollection: async (collection) => {
|
updateCollection: async (collection) => {
|
||||||
const response = await fetch("/api/routes/collections", {
|
const response = await fetch("/api/collections", {
|
||||||
body: JSON.stringify(collection),
|
body: JSON.stringify(collection),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -67,7 +67,7 @@ const useCollectionStore = create<CollectionStore>()((set) => ({
|
||||||
return { ok: response.ok, data: data.response };
|
return { ok: response.ok, data: data.response };
|
||||||
},
|
},
|
||||||
removeCollection: async (id) => {
|
removeCollection: async (id) => {
|
||||||
const response = await fetch("/api/routes/collections", {
|
const response = await fetch("/api/collections", {
|
||||||
body: JSON.stringify({ id }),
|
body: JSON.stringify({ id }),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
|
@ -38,7 +38,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
addLink: async (body) => {
|
addLink: async (body) => {
|
||||||
const response = await fetch("/api/routes/links", {
|
const response = await fetch("/api/links", {
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -59,7 +59,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||||
return { ok: response.ok, data: data.response };
|
return { ok: response.ok, data: data.response };
|
||||||
},
|
},
|
||||||
updateLink: async (link) => {
|
updateLink: async (link) => {
|
||||||
const response = await fetch("/api/routes/links", {
|
const response = await fetch("/api/links", {
|
||||||
body: JSON.stringify(link),
|
body: JSON.stringify(link),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -82,7 +82,7 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||||
return { ok: response.ok, data: data.response };
|
return { ok: response.ok, data: data.response };
|
||||||
},
|
},
|
||||||
removeLink: async (link) => {
|
removeLink: async (link) => {
|
||||||
const response = await fetch("/api/routes/links", {
|
const response = await fetch("/api/links", {
|
||||||
body: JSON.stringify(link),
|
body: JSON.stringify(link),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
|
@ -9,7 +9,7 @@ type TagStore = {
|
||||||
const useTagStore = create<TagStore>()((set) => ({
|
const useTagStore = create<TagStore>()((set) => ({
|
||||||
tags: [],
|
tags: [],
|
||||||
setTags: async () => {
|
setTags: async () => {
|
||||||
const response = await fetch("/api/routes/tags");
|
const response = await fetch("/api/tags");
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue