feat: add favorites page

This commit is contained in:
Kentai Radiquum 2024-07-16 13:08:43 +05:00
parent 484148ada6
commit 28efc5a98c
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
10 changed files with 177 additions and 36 deletions

View file

@ -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
View 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,
};

View file

@ -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`,

View 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);
}

View file