Added tag support + Post link and many more changes and optimizations.
This commit is contained in:
@@ -12,7 +12,7 @@ interface User {
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default async function handler(
|
||||
export default async function (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
|
||||
@@ -2,13 +2,13 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "pages/api/auth/[...nextauth]";
|
||||
import getCollections from "@/lib/api/controllers/collections/getCollections";
|
||||
import postCollections from "@/lib/api/controllers/collections/postCollection";
|
||||
import postCollection from "@/lib/api/controllers/collections/postCollection";
|
||||
|
||||
type Data = {
|
||||
response: object[] | string;
|
||||
};
|
||||
|
||||
export default async function handler(
|
||||
export default async function (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
@@ -20,5 +20,5 @@ export default async function handler(
|
||||
|
||||
if (req.method === "GET") return await getCollections(req, res, session);
|
||||
|
||||
if (req.method === "POST") return await postCollections(req, res, session);
|
||||
if (req.method === "POST") return await postCollection(req, res, session);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "pages/api/auth/[...nextauth]";
|
||||
import postLink from "@/lib/api/controllers/links/postLink";
|
||||
|
||||
type Data = {
|
||||
response: object[] | string;
|
||||
};
|
||||
|
||||
export default async function (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
const session = await getServerSession(req, res, authOptions);
|
||||
|
||||
if (!session?.user?.email) {
|
||||
return res.status(401).json({ response: "You must be logged in." });
|
||||
}
|
||||
|
||||
// Check if user is unauthorized to the collection (If isn't owner or doesn't has the required permission...)
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
if (req.method === "POST") return await postLink(req, res, session);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "pages/api/auth/[...nextauth]";
|
||||
import getTags from "@/lib/api/controllers/tags/getTags";
|
||||
|
||||
type Data = {
|
||||
response: object[] | string;
|
||||
};
|
||||
|
||||
export default async function (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
const session = await getServerSession(req, res, authOptions);
|
||||
|
||||
if (!session?.user?.email) {
|
||||
return res.status(401).json({ response: "You must be logged in." });
|
||||
}
|
||||
|
||||
if (req.method === "GET") return await getTags(req, res, session);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
export default function () {
|
||||
const router = useRouter();
|
||||
|
||||
const collectionId = Number(router.query.id);
|
||||
|
||||
console.log(collectionId);
|
||||
|
||||
return <div>{"HI"}</div>;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { useSession } from "next-auth/react";
|
||||
import useCollectionSlice from "@/store/collection";
|
||||
|
||||
import CollectionCard from "@/components/CollectionCard";
|
||||
|
||||
export default function () {
|
||||
const { collections } = useCollectionSlice();
|
||||
const { data: session, status } = useSession();
|
||||
|
||||
const user = session?.user;
|
||||
|
||||
return (
|
||||
// ml-80
|
||||
<div className="flex flex-wrap p-5">
|
||||
{collections.map((e, i) => {
|
||||
return <CollectionCard key={i} collection={e} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { useSession } from "next-auth/react";
|
||||
import CollectionCards from "@/components/CollectionCards";
|
||||
|
||||
export default function Dashboard() {
|
||||
const { data: session, status } = useSession();
|
||||
|
||||
const user = session?.user;
|
||||
|
||||
return (
|
||||
// ml-80
|
||||
<div className="p-5">
|
||||
<CollectionCards />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ export default function Home() {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
router.push("/dashboard");
|
||||
router.push("/collections");
|
||||
}, []);
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ interface FormData {
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default function Login() {
|
||||
export default function () {
|
||||
const [form, setForm] = useState<FormData>({
|
||||
email: "",
|
||||
password: "",
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ interface FormData {
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default function Register() {
|
||||
export default function () {
|
||||
const router = useRouter();
|
||||
|
||||
const [form, setForm] = useState<FormData>({
|
||||
|
||||
Reference in New Issue
Block a user