Skip to content

refactor: collection api routes #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions src/app/api/collection/all/route.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@ import prisma from "@/lib/prisma";
import { currentUser } from "@clerk/nextjs/server";
import { NextRequest, NextResponse } from "next/server";

export const dynamic = "force-dynamic";

export async function GET() {
try {
const user = await currentUser();

if (!user) {
return NextResponse.json(
{
message: "User not authenticated",
},
{ status: 401 },
);
}

const collections = await prisma.collection.findMany({
where: {
madeById: user.id,
},
});

return NextResponse.json(
{
message: "Fetched collections successfully",
data: collections,
},
{
status: 200,
},
);
} catch (err: any) {
console.error(err);
return NextResponse.json(
{
message: "Internal Server error",
},
{
status: 500,
},
);
}
}

export async function POST(req: NextRequest) {
try {
const user = await currentUser();
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/collections/useDeleteCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useDeleteCollection() {
async (id: string) => {
try {
setLoading(true);
const res = await fetch("/api/collection", {
const res = await fetch("/api/collections", {
method: "DELETE",
body: JSON.stringify({
collectionId: id,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/collections/useFetchCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useFetchCollection(id: string) {
async (id: string) => {
try {
setLoading(true);
const req = await fetch(`/api/collection/${id}`);
const req = await fetch(`/api/collections/${id}`);
const res = await req.json();
if (req.status === 200) {
setCollectionWithMemes(res.data);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/collections/useFetchCollectionWithMemes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useFetchCollectionWithMemes() {
async (collectionId: string) => {
try {
setLoading(true);
const req = await fetch(`/api/collection/${collectionId}`);
const req = await fetch(`/api/collections/${collectionId}`);
const res = await req.json();
if (req.status === 200) {
setCollectionWithMemes(res.data);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/collections/useFetchCollections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useFetchCollections() {
const fetchCollections = useCallback(async () => {
setLoading(true);
try {
const req = await fetch("/api/collection/all");
const req = await fetch("/api/collections");
const res = await req.json();
if (req.status === 200) {
setCollections(res.data);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/collections/usePostCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function usePostCollection() {
const postCollection = useCallback(async (name: string) => {
setLoading(true);
try {
const req = await fetch("/api/collection/", {
const req = await fetch("/api/collections", {
method: "POST",
body: JSON.stringify({
collectionName: name,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/collections/useUpdateCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function useUpdateCollection() {
async (collectionId: string, payload: { collectionName: string }) => {
setLoading(true);
try {
const req = await fetch(`/api/collection/${collectionId}`, {
const req = await fetch(`/api/collections/${collectionId}`, {
method: "PATCH",
body: JSON.stringify(payload),
});
Expand Down
Loading