mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-29 01:19:41 +05:00
feat: add favorites page
This commit is contained in:
parent
484148ada6
commit
28efc5a98c
10 changed files with 177 additions and 36 deletions
|
@ -1,6 +1,7 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { fetchDataViaGet } from "../utils";
|
||||
import { ENDPOINTS } from "../config";
|
||||
import { sort } from "../common";
|
||||
|
||||
const list = {
|
||||
watching: 1,
|
||||
|
@ -10,20 +11,12 @@ const list = {
|
|||
abandoned: 5,
|
||||
};
|
||||
|
||||
const sort = {
|
||||
adding_descending: 1,
|
||||
adding_ascending: 2,
|
||||
// year_descending: 3,
|
||||
// year_ascending: 4,
|
||||
alphabet_descending: 5,
|
||||
alphabet_ascending: 6,
|
||||
};
|
||||
|
||||
export async function GET(request) {
|
||||
const page = parseInt(request.nextUrl.searchParams.get(["page"])) || 0;
|
||||
const listName = request.nextUrl.searchParams.get(["list"]) || null;
|
||||
const token = request.nextUrl.searchParams.get(["token"]) || null;
|
||||
const sortName = request.nextUrl.searchParams.get(["sort"]) || "adding_descending";
|
||||
const sortName =
|
||||
request.nextUrl.searchParams.get(["sort"]) || "adding_descending";
|
||||
|
||||
if (!token || token == "null") {
|
||||
return NextResponse.json({ message: "No token provided" }, { status: 403 });
|
||||
|
|
8
app/api/common.js
Normal file
8
app/api/common.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
export const sort = {
|
||||
adding_descending: 1,
|
||||
adding_ascending: 2,
|
||||
// year_descending: 3,
|
||||
// year_ascending: 4,
|
||||
alphabet_descending: 5,
|
||||
alphabet_ascending: 6,
|
||||
};
|
|
@ -11,7 +11,7 @@ export const ENDPOINTS = {
|
|||
profile: `${API_URL}/profile`,
|
||||
bookmark: `${API_URL}/profile/list/all`,
|
||||
history: `${API_URL}/history`,
|
||||
favorite: `${API_URL}/favorite`,
|
||||
favorite: `${API_URL}/favorite/all`,
|
||||
},
|
||||
filter: `${API_URL}/filter`,
|
||||
auth: `${API_URL}/auth/signIn`,
|
||||
|
|
26
app/api/favorites/route.js
Normal file
26
app/api/favorites/route.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { fetchDataViaGet } from "../utils";
|
||||
import { ENDPOINTS } from "../config";
|
||||
import { sort } from "../common";
|
||||
|
||||
|
||||
export async function GET(request) {
|
||||
const page = parseInt(request.nextUrl.searchParams.get(["page"])) || 0;
|
||||
const token = request.nextUrl.searchParams.get(["token"]) || null;
|
||||
const sortName = request.nextUrl.searchParams.get(["sort"]) || "adding_descending";
|
||||
|
||||
if (!token || token == "null") {
|
||||
return NextResponse.json({ message: "No token provided" }, { status: 403 });
|
||||
}
|
||||
|
||||
if (!sort[sortName]) {
|
||||
return NextResponse.json({ message: "Unknown sort" }, { status: 400 });
|
||||
}
|
||||
|
||||
let url = new URL(`${ENDPOINTS.user.favorite}/${page}`);
|
||||
url.searchParams.set("token", token);
|
||||
url.searchParams.set("sort", sort[sortName]);
|
||||
|
||||
const response = await fetchDataViaGet(url.toString());
|
||||
return NextResponse.json(response);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue