Skip to content

Commit

Permalink
Refactor code and remove unused files
Browse files Browse the repository at this point in the history
  • Loading branch information
JHM69 committed Oct 24, 2024
1 parent 359c44d commit b42fc9a
Show file tree
Hide file tree
Showing 24 changed files with 12,917 additions and 11,999 deletions.
42 changes: 42 additions & 0 deletions app/api/add-member/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { NextResponse } from 'next/server';
import prisma from "@/prisma/prisma-client";
export async function GET() {
return NextResponse.json({ message: 'Hello, World!' });
}

export async function POST(request: Request) {
const body = await request.json();
const { user_email, tripPlanId } = body;

if (!user_email) {
return NextResponse.json({ error: 'Email is required' }, { status: 400 });
}

if (tripPlanId) {
// If email is not null and tripPlan is not null:
// Insert the tripPlan to the database with email and return the tripPlanId
try {
const newTripPlan = await prisma.tripPlan.update({
data: {
members: {
connect: {
email: user_email
}
},
},
where: {
id : tripPlanId
}
});
return NextResponse.json({
message: 'User added to trip plan',
tripPlanId: newTripPlan.id,
});
} catch (error) {
console.error('Error saving trip plan:', error);
return NextResponse.json({ error: 'Error saving trip plan' }, { status: 500 });
}
}
}


40 changes: 0 additions & 40 deletions app/api/asfi/hotels/route.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions app/api/asfi/restaurants/route.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions app/api/asfi/route/route.tsx

This file was deleted.

19 changes: 18 additions & 1 deletion app/api/blog/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as lancedb from "@lancedb/lancedb";
import * as arrow from "apache-arrow";
import { feature } from "@turf/turf";
import { title } from "process";
import { stat } from "fs";

// Initialize OpenAI client
const openai = new OpenAI({
Expand Down Expand Up @@ -75,7 +76,7 @@ export async function POST(request: NextRequest) {

try {
const body = await request.json();
const { email, tripPlanId, name, content } = body;
const { email, tripPlanId, name, content, title } = body;

if ( !tripPlanId) {
return NextResponse.json(
Expand Down Expand Up @@ -116,6 +117,22 @@ export async function POST(request: NextRequest) {
},
});

await prisma.notification.create({
data: {
content: `New blog post created by ${name} for trip: ${tripPlan?.data?.name} : ${title}`,
tripPlan:{
connect: {
id: tripPlanId,
},
}
},
});


return NextResponse.json(
{ status: "success" },
{ status: 200 },
);

}

Expand Down
11 changes: 11 additions & 0 deletions app/api/image/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ export async function POST(request: NextRequest) {
console.log("Table created and data added");
}

await prisma.notification.create({
data: {
content: `New Photo added by ${name}`,
tripPlan:{
connect: {
id: tripPlanId,
},
}
},
});

return NextResponse.json(
{ message: "Image processed successfully", id: tripPlanId },
{ status: 201 },
Expand Down
141 changes: 141 additions & 0 deletions app/api/trip/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { NextResponse } from 'next/server';
import prisma from "@/prisma/prisma-client";

export async function GET() {
return NextResponse.json({ message: 'Hello, World!' });
}

export async function POST(request: Request) {
const body = await request.json();
const { email, tripPlan } = body;

if (!email) {
return NextResponse.json({ error: 'Email is required' }, { status: 400 });
}

if (tripPlan) {
// If email is not null and tripPlan is not null:
// Insert the tripPlan to the database with email and return the tripPlanId
try {
const newTripPlan = await prisma.tripPlan.create({
data: {
author : {
connect : {
email : email
}
},
members : {
connect : {
email : email
}
},
data: tripPlan,
},
});
return NextResponse.json({
message: 'Trip plan saved',
tripPlanId: newTripPlan.id,
});
} catch (error) {
console.error('Error saving trip plan:', error);
return NextResponse.json({ error: 'Error saving trip plan' }, { status: 500 });
}
} else {
// If email is not null and tripPlan is null:
// Return the tripPlanId from the database with email
try {
const existingTripPlan = await prisma.tripPlan.findFirst({
where: { email },
});

if (existingTripPlan) {
return NextResponse.json({
message: 'Trip plan found',
tripPlanId: existingTripPlan.id,
});
} else {
// Create a new trip plan if none exists
const newTripPlan = await prisma.tripPlan.create({
data: {
email,
tripData: {}, // Initialize with empty data if needed
},
});
return NextResponse.json({
message: 'New trip plan created',
tripPlanId: newTripPlan.id,
});
}
} catch (error) {
console.error('Error retrieving trip plan:', error);
return NextResponse.json({ error: 'Error retrieving trip plan' }, { status: 500 });
}
}
}


export async function PUT(request: Request) {
const body = await request.json();
const { email, tripPlan, tripPlanId } = body;

if (!email) {
return NextResponse.json({ error: 'Email is required' }, { status: 400 });
}

if (tripPlan) {
// If email is not null and tripPlan is not null:
// Insert the tripPlan to the database with email and return the tripPlanId
try {
const newTripPlan = await prisma.tripPlan.update({
where:{
id : tripPlanId
},
data: {
members : {
connect : {
email : email
}
},
data: tripPlan,
},
});
return NextResponse.json({
message: 'Trip plan Updated',
tripPlanId: newTripPlan.id,
});
} catch (error) {
console.error('Error saving trip plan:', error);
return NextResponse.json({ error: 'Error saving trip plan' }, { status: 500 });
}
} else {
// If email is not null and tripPlan is null:
// Return the tripPlanId from the database with email
try {
const existingTripPlan = await prisma.tripPlan.findFirst({
where: { email },
});

if (existingTripPlan) {
return NextResponse.json({
message: 'Trip plan found',
tripPlanId: existingTripPlan.id,
});
} else {
// Create a new trip plan if none exists
const newTripPlan = await prisma.tripPlan.create({
data: {
email,
tripData: {}, // Initialize with empty data if needed
},
});
return NextResponse.json({
message: 'New trip plan created',
tripPlanId: newTripPlan.id,
});
}
} catch (error) {
console.error('Error retrieving trip plan:', error);
return NextResponse.json({ error: 'Error retrieving trip plan' }, { status: 500 });
}
}
}
6 changes: 2 additions & 4 deletions app/api/trpc/trpc-router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable import/no-unresolved */
import tripRouter from '@/server/trip-route';
import notificationRouter from '@/server/notification-route';
import orderRouter from '@/server/order-route';



import { t } from '@/utils/trpc-server';
import { createServerSideHelpers } from '@trpc/react-query/server';
import SuperJSON from 'superjson';
Expand All @@ -17,7 +15,7 @@ const healthCheckerRouter = t.router({
}),
});

export const appRouter = t.mergeRouters(orderRouter, healthCheckerRouter, tripRouter, notificationRouter);
export const appRouter = t.mergeRouters( healthCheckerRouter, tripRouter, notificationRouter);

export const createSSRHelper = () =>
createServerSideHelpers({
Expand Down
6 changes: 3 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const TravelPlanner = () => {
budget: formData.budget,
people: formData.people,
preferences: formData.preferences,
tripType: formData.tripType,
tripType: formData?.tripType,
journeyDate: formData.journeyDate,
travelClass: formData.travelClass
});
Expand Down Expand Up @@ -125,7 +125,7 @@ const TravelPlanner = () => {

<div className="space-y-6">
<RadioGroup
value={formData.tripType}
value={formData?.tripType}
onValueChange={(value) => setFormData({ ...formData, tripType: value })}
className="flex gap-4"
>
Expand All @@ -147,7 +147,7 @@ const TravelPlanner = () => {
<div className="space-y-2">
<Label>Origin</Label>
<Input
value={formData.origin}
value={formData?.origin}
onChange={(e) => setFormData({ ...formData, origin: e.target.value })}
placeholder="Enter origin city"
/>
Expand Down
Loading

0 comments on commit b42fc9a

Please sign in to comment.