-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code and remove unused files
- Loading branch information
Showing
24 changed files
with
12,917 additions
and
11,999 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.