Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FylypekUNO committed Nov 25, 2024
1 parent befcafc commit 8470bc9
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 148 deletions.
15 changes: 11 additions & 4 deletions app/api/recipes/[id]/nutrition/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ import { NextResponse } from "next/server";
import dbConnect from "@/lib/connectToDatabase";
import Recipe from "@/models/Recipe";

export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
export type GETParams = {
params: {
id: string;
};
};

export async function GET({ params }: GETParams) {
try {
await dbConnect();

const recipe = await Recipe.findById(params.id);

if (!recipe) {
return NextResponse.json({ error: "Recipe not found" }, { status: 404 });
}

const nutrition = await recipe.calculateNutrition();

return NextResponse.json(nutrition);
} catch (error) {
return NextResponse.json({ error: "Server error" }, { status: 500 });
Expand Down
13 changes: 8 additions & 5 deletions app/api/recipes/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { isValidObjectId } from "mongoose";
import connectDB from "@/lib/connectToDatabase";
import Recipe from "@/models/Recipe";

export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
export type GETParams = {
params: {
id: string;
};
};

export async function GET({ params }: GETParams) {
try {
const { id } = params;

Expand All @@ -29,7 +32,7 @@ export async function GET(
} catch (error) {
console.error("Error fetching recipe:", error);
return NextResponse.json(
{ error: "Internal server error" },
{ error: "Server error occurred" },
{ status: 500 }
);
}
Expand Down
4 changes: 3 additions & 1 deletion app/api/recipes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import Recipe from "@/models/Recipe";
export async function GET(req: NextRequest) {
try {
await connectMongo();

const recipes = await Recipe.find({}).populate("ingredients.ingredient");

return NextResponse.json({ recipes }, { status: 200 });
} catch (error) {
console.error("Error:", error);
return NextResponse.json(
{ error: "Wystąpił błąd serwera" },
{ error: "Server error occurred" },
{ status: 500 }
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/api/test-auth/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import { NextResponse } from "next/server";
import { getServerSession, Session } from "next-auth";
import authOptions from "@/lib/nextauth";

export async function GET(req: NextRequest) {
export async function GET() {
const session: Session | null = await getServerSession(authOptions);

if (!session) {
Expand Down
56 changes: 0 additions & 56 deletions app/api/test-db/route.ts

This file was deleted.

1 change: 0 additions & 1 deletion app/recipes/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";

import { useState, useEffect } from "react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Navbar } from "@/components/Navbar";
Expand Down
12 changes: 7 additions & 5 deletions app/recipes/favorite/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// route.ts
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import connectDB from "@/lib/connectToDatabase";
Expand Down Expand Up @@ -27,11 +26,14 @@ export async function GET() {
}
}

export type POSTParams = {
params: {
recipeId: string;
};
};

// Add to favorites
export async function POST(
request: Request,
{ params }: { params: { recipeId: string } }
) {
export async function POST({ params }: POSTParams) {
try {
const session = await getServerSession(authOptions);

Expand Down
6 changes: 1 addition & 5 deletions app/recipes/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { RecipesList } from "@/components/RecipesList";
import connectDB from "@/lib/connectToDatabase";
import Recipe, { RecipeType } from "@/models/Recipe";
import Recipe from "@/models/Recipe";
import { Navbar } from "@/components/Navbar";

type RecipesPageProps = {
recipes: RecipeType[];
};

const RecipesPage = async () => {
await connectDB();
const recipes = await Recipe.find({})
Expand Down
1 change: 0 additions & 1 deletion app/user/status/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";

import { Logo } from "@/components/Logo";
import { useSession, signIn, signOut } from "next-auth/react";
import { useState } from "react";
Expand Down
1 change: 0 additions & 1 deletion components/CustomSessionProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";

import { SessionProvider } from "next-auth/react";
import { ReactNode } from "react";

Expand Down
1 change: 0 additions & 1 deletion components/RecipesList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";

import { FC, useState } from "react";
import Link from "next/link";
import {
Expand Down
66 changes: 0 additions & 66 deletions lib/validation.ts

This file was deleted.

0 comments on commit 8470bc9

Please sign in to comment.