mirror of
https://github.com/mblanke/holiday-travel-app.git
synced 2026-03-01 13:30:20 -05:00
Initial commit: Holiday Travel App with resort comparison, trip management, and multi-provider search
This commit is contained in:
63
app/api/trips/route.ts
Normal file
63
app/api/trips/route.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { getAllTrips, getTripById, getTripsByStatus, getTripsByRegion } from "@/lib/trips";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
const status = searchParams.get("status");
|
||||
const region = searchParams.get("region");
|
||||
|
||||
// Get specific trip by ID
|
||||
if (id) {
|
||||
const trip = getTripById(id);
|
||||
if (!trip) {
|
||||
return new Response(JSON.stringify({ error: "Trip not found" }), {
|
||||
status: 404,
|
||||
headers: { "content-type": "application/json" }
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify({ trip }), {
|
||||
headers: { "content-type": "application/json" }
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by status
|
||||
if (status) {
|
||||
const trips = getTripsByStatus(status as any);
|
||||
return new Response(JSON.stringify({ trips, count: trips.length }), {
|
||||
headers: { "content-type": "application/json" }
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by region
|
||||
if (region) {
|
||||
const trips = getTripsByRegion(region);
|
||||
return new Response(JSON.stringify({ trips, count: trips.length }), {
|
||||
headers: { "content-type": "application/json" }
|
||||
});
|
||||
}
|
||||
|
||||
// Get all trips
|
||||
const trips = getAllTrips();
|
||||
return new Response(JSON.stringify({
|
||||
trips,
|
||||
count: trips.length,
|
||||
byStatus: {
|
||||
planning: getTripsByStatus("planning").length,
|
||||
booked: getTripsByStatus("booked").length,
|
||||
completed: getTripsByStatus("completed").length
|
||||
}
|
||||
}), {
|
||||
headers: { "content-type": "application/json" }
|
||||
});
|
||||
|
||||
} catch (e: any) {
|
||||
return new Response(JSON.stringify({
|
||||
error: e?.message || "Failed to retrieve trips"
|
||||
}), {
|
||||
status: 500,
|
||||
headers: { "content-type": "application/json" }
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user