Initial commit: Airbnb Finder & Compare - Full Feature MVP
This commit is contained in:
commit
8a0a28443b
43
.gitignore
vendored
Normal file
43
.gitignore
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
/src/generated/prisma
|
||||
36
README.md
Normal file
36
README.md
Normal file
@ -0,0 +1,36 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
# or
|
||||
bun dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||
18
eslint.config.mjs
Normal file
18
eslint.config.mjs
Normal file
@ -0,0 +1,18 @@
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTs from "eslint-config-next/typescript";
|
||||
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
]);
|
||||
|
||||
export default eslintConfig;
|
||||
7
next.config.ts
Normal file
7
next.config.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
8792
package-lock.json
generated
Normal file
8792
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
package.json
Normal file
48
package.json
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "airbnb-finder",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@auth/prisma-adapter": "^2.11.1",
|
||||
"@prisma/client": "^5.22.0",
|
||||
"@radix-ui/react-label": "^2.1.8",
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/leaflet": "^1.9.21",
|
||||
"bcryptjs": "^3.0.3",
|
||||
"cheerio": "^1.2.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"leaflet": "^1.9.4",
|
||||
"lucide-react": "^0.577.0",
|
||||
"next": "16.1.6",
|
||||
"next-auth": "^5.0.0-beta.30",
|
||||
"prisma": "^5.22.0",
|
||||
"puppeteer": "^24.39.0",
|
||||
"puppeteer-extra": "^3.3.6",
|
||||
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3",
|
||||
"react-leaflet": "^5.0.0",
|
||||
"tailwind-merge": "^3.5.0",
|
||||
"uuid": "^13.0.0",
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"dotenv": "^17.3.1",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.1.6",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
7
postcss.config.mjs
Normal file
7
postcss.config.mjs
Normal file
@ -0,0 +1,7 @@
|
||||
const config = {
|
||||
plugins: {
|
||||
"@tailwindcss/postcss": {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
131
prisma/migrations/20260310210937_init/migration.sql
Normal file
131
prisma/migrations/20260310210937_init/migration.sql
Normal file
@ -0,0 +1,131 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "listings" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"slug" TEXT NOT NULL,
|
||||
"airbnb_url" TEXT NOT NULL,
|
||||
"normalized_url" TEXT NOT NULL,
|
||||
"external_id" TEXT,
|
||||
"title" TEXT NOT NULL,
|
||||
"location_text" TEXT,
|
||||
"latitude" REAL,
|
||||
"longitude" REAL,
|
||||
"nightly_price" REAL,
|
||||
"total_price" REAL,
|
||||
"currency" TEXT DEFAULT 'EUR',
|
||||
"rating" REAL,
|
||||
"review_count" INTEGER,
|
||||
"guest_count" INTEGER,
|
||||
"official_guest_count" INTEGER,
|
||||
"max_sleeping_places" INTEGER,
|
||||
"suitable_for_4" BOOLEAN,
|
||||
"extra_mattresses_needed_for_4" INTEGER,
|
||||
"bed_types_summary" TEXT,
|
||||
"bedrooms" INTEGER,
|
||||
"beds" INTEGER,
|
||||
"bathrooms" REAL,
|
||||
"description" TEXT,
|
||||
"host_name" TEXT,
|
||||
"cancellation_policy" TEXT,
|
||||
"amenities" TEXT,
|
||||
"is_favorite" BOOLEAN NOT NULL DEFAULT false,
|
||||
"status" TEXT NOT NULL DEFAULT 'NEW',
|
||||
"cover_image" TEXT,
|
||||
"raw_source_data" TEXT,
|
||||
"imported_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "listing_images" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"listing_id" TEXT NOT NULL,
|
||||
"url" TEXT NOT NULL,
|
||||
"alt" TEXT,
|
||||
"sort_order" INTEGER NOT NULL DEFAULT 0,
|
||||
"is_external" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "listing_images_listing_id_fkey" FOREIGN KEY ("listing_id") REFERENCES "listings" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "admin_notes" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"listing_id" TEXT NOT NULL,
|
||||
"body" TEXT NOT NULL,
|
||||
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" DATETIME NOT NULL,
|
||||
CONSTRAINT "admin_notes_listing_id_fkey" FOREIGN KEY ("listing_id") REFERENCES "listings" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "tags" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"name" TEXT NOT NULL,
|
||||
"slug" TEXT NOT NULL,
|
||||
"color" TEXT DEFAULT '#6366f1'
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "listing_tags" (
|
||||
"listing_id" TEXT NOT NULL,
|
||||
"tag_id" TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY ("listing_id", "tag_id"),
|
||||
CONSTRAINT "listing_tags_listing_id_fkey" FOREIGN KEY ("listing_id") REFERENCES "listings" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "listing_tags_tag_id_fkey" FOREIGN KEY ("tag_id") REFERENCES "tags" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "listing_sleeping_options" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"listing_id" TEXT NOT NULL,
|
||||
"bed_type" TEXT NOT NULL,
|
||||
"quantity" INTEGER NOT NULL DEFAULT 1,
|
||||
"spots_per_unit" INTEGER NOT NULL DEFAULT 1,
|
||||
"quality" TEXT NOT NULL DEFAULT 'FULL',
|
||||
"label" TEXT,
|
||||
"notes" TEXT,
|
||||
CONSTRAINT "listing_sleeping_options_listing_id_fkey" FOREIGN KEY ("listing_id") REFERENCES "listings" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "listings_slug_key" ON "listings"("slug");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "listings_airbnb_url_key" ON "listings"("airbnb_url");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "listings_normalized_url_key" ON "listings"("normalized_url");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "listings_external_id_key" ON "listings"("external_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "listings_status_idx" ON "listings"("status");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "listings_is_favorite_idx" ON "listings"("is_favorite");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "listings_location_text_idx" ON "listings"("location_text");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "listings_nightly_price_idx" ON "listings"("nightly_price");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "listings_rating_idx" ON "listings"("rating");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "listing_images_listing_id_sort_order_idx" ON "listing_images"("listing_id", "sort_order");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "admin_notes_listing_id_created_at_idx" ON "admin_notes"("listing_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "tags_name_key" ON "tags"("name");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "tags_slug_key" ON "tags"("slug");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "listing_sleeping_options_listing_id_idx" ON "listing_sleeping_options"("listing_id");
|
||||
3
prisma/migrations/migration_lock.toml
Normal file
3
prisma/migrations/migration_lock.toml
Normal file
@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "sqlite"
|
||||
BIN
prisma/prisma/dev.db
Normal file
BIN
prisma/prisma/dev.db
Normal file
Binary file not shown.
152
prisma/schema.prisma
Normal file
152
prisma/schema.prisma
Normal file
@ -0,0 +1,152 @@
|
||||
// This is your Prisma schema file
|
||||
// Learn more: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// MODELS
|
||||
// ============================================
|
||||
|
||||
model Listing {
|
||||
id String @id @default(cuid())
|
||||
slug String @unique
|
||||
airbnbUrl String @unique @map("airbnb_url")
|
||||
normalizedUrl String @unique @map("normalized_url")
|
||||
externalId String? @unique @map("external_id")
|
||||
|
||||
// Basic Info
|
||||
title String
|
||||
locationText String? @map("location_text")
|
||||
latitude Float?
|
||||
longitude Float?
|
||||
|
||||
// Pricing
|
||||
nightlyPrice Float? @map("nightly_price")
|
||||
totalPrice Float? @map("total_price")
|
||||
currency String? @default("EUR")
|
||||
|
||||
// Rating
|
||||
rating Float?
|
||||
reviewCount Int? @map("review_count")
|
||||
|
||||
// Capacity
|
||||
guestCount Int? @map("guest_count")
|
||||
officialGuestCount Int? @map("official_guest_count")
|
||||
maxSleepingPlaces Int? @map("max_sleeping_places")
|
||||
suitableFor4 Boolean? @map("suitable_for_4")
|
||||
extraMattressesNeededFor4 Int? @map("extra_mattresses_needed_for_4")
|
||||
bedTypesSummary String? @map("bed_types_summary")
|
||||
|
||||
// Room Details
|
||||
bedrooms Int?
|
||||
beds Int?
|
||||
bathrooms Float?
|
||||
|
||||
// Description
|
||||
description String?
|
||||
hostName String? @map("host_name")
|
||||
cancellationPolicy String? @map("cancellation_policy")
|
||||
|
||||
// Amenities (stored as JSON string)
|
||||
amenities String? @map("amenities")
|
||||
|
||||
// Status & Flags (using String instead of Enum for SQLite)
|
||||
isFavorite Boolean @default(false) @map("is_favorite")
|
||||
status String @default("NEW") // NEW, INTERESTING, SHORTLIST, BOOKED, REJECTED
|
||||
|
||||
// Images
|
||||
coverImage String? @map("cover_image")
|
||||
|
||||
// Raw Data
|
||||
rawSourceData String? @map("raw_source_data")
|
||||
|
||||
// Timestamps
|
||||
importedAt DateTime @default(now()) @map("imported_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
// Relations
|
||||
images ListingImage[]
|
||||
notes AdminNote[]
|
||||
sleepingOptions ListingSleepingOption[]
|
||||
tags ListingTag[]
|
||||
|
||||
// Indexes
|
||||
@@index([status])
|
||||
@@index([isFavorite])
|
||||
@@index([locationText])
|
||||
@@index([nightlyPrice])
|
||||
@@index([rating])
|
||||
@@map("listings")
|
||||
}
|
||||
|
||||
model ListingImage {
|
||||
id String @id @default(cuid())
|
||||
listingId String @map("listing_id")
|
||||
url String
|
||||
alt String?
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
isExternal Boolean @default(true) @map("is_external")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
listing Listing @relation(fields: [listingId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([listingId, sortOrder])
|
||||
@@map("listing_images")
|
||||
}
|
||||
|
||||
model AdminNote {
|
||||
id String @id @default(cuid())
|
||||
listingId String @map("listing_id")
|
||||
body String
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
listing Listing @relation(fields: [listingId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([listingId, createdAt])
|
||||
@@map("admin_notes")
|
||||
}
|
||||
|
||||
model Tag {
|
||||
id String @id @default(cuid())
|
||||
name String @unique
|
||||
slug String @unique
|
||||
color String? @default("#6366f1")
|
||||
listings ListingTag[]
|
||||
|
||||
@@map("tags")
|
||||
}
|
||||
|
||||
model ListingTag {
|
||||
listingId String @map("listing_id")
|
||||
tagId String @map("tag_id")
|
||||
|
||||
listing Listing @relation(fields: [listingId], references: [id], onDelete: Cascade)
|
||||
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([listingId, tagId])
|
||||
@@map("listing_tags")
|
||||
}
|
||||
|
||||
model ListingSleepingOption {
|
||||
id String @id @default(cuid())
|
||||
listingId String @map("listing_id")
|
||||
bedType String @map("bed_type") // DOUBLE, SINGLE, SOFA_BED, etc.
|
||||
quantity Int @default(1)
|
||||
spotsPerUnit Int @default(1) @map("spots_per_unit")
|
||||
quality String @default("FULL") // FULL, AUXILIARY
|
||||
label String?
|
||||
notes String?
|
||||
|
||||
listing Listing @relation(fields: [listingId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([listingId])
|
||||
@@map("listing_sleeping_options")
|
||||
}
|
||||
224
prisma/seed.ts
Normal file
224
prisma/seed.ts
Normal file
@ -0,0 +1,224 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log("🌱 Seeding database...");
|
||||
|
||||
// Create tags
|
||||
const tagCheap = await prisma.tag.upsert({
|
||||
where: { slug: "guenstig" },
|
||||
update: {},
|
||||
create: {
|
||||
name: "Günstig",
|
||||
slug: "guenstig",
|
||||
color: "#22c55e",
|
||||
},
|
||||
});
|
||||
|
||||
const tagFavorite = await prisma.tag.upsert({
|
||||
where: { slug: "favorit" },
|
||||
update: {},
|
||||
create: {
|
||||
name: "Favorit",
|
||||
slug: "favorit",
|
||||
color: "#eab308",
|
||||
},
|
||||
});
|
||||
|
||||
const tagGroup = await prisma.tag.upsert({
|
||||
where: { slug: "gruppe" },
|
||||
update: {},
|
||||
create: {
|
||||
name: "Für Gruppen",
|
||||
slug: "gruppe",
|
||||
color: "#8b5cf6",
|
||||
},
|
||||
});
|
||||
|
||||
// Create sample listings
|
||||
const listing1 = await prisma.listing.upsert({
|
||||
where: { slug: "loft-mit-elbblick-12345678" },
|
||||
update: {},
|
||||
create: {
|
||||
title: "Loft mit Elbblick",
|
||||
slug: "loft-mit-elbblick-12345678",
|
||||
airbnbUrl: "https://www.airbnb.com/rooms/12345678",
|
||||
normalizedUrl: "https://airbnb.com/rooms/12345678",
|
||||
externalId: "12345678",
|
||||
locationText: "Dresden, Sachsen",
|
||||
latitude: 51.0504,
|
||||
longitude: 13.7373,
|
||||
nightlyPrice: 129.00,
|
||||
rating: 4.91,
|
||||
reviewCount: 87,
|
||||
officialGuestCount: 4,
|
||||
maxSleepingPlaces: 4,
|
||||
suitableFor4: true,
|
||||
extraMattressesNeededFor4: 0,
|
||||
bedTypesSummary: "1× Doppelbett, 1× Schlafsofa",
|
||||
bedrooms: 2,
|
||||
beds: 2,
|
||||
bathrooms: 1.0,
|
||||
description: "Wunderschönes Loft mit Blick auf die Elbe. Perfekt für Paare oder kleine Gruppen.",
|
||||
hostName: "Anna",
|
||||
isFavorite: true,
|
||||
status: "SHORTLIST",
|
||||
coverImage: "https://images.unsplash.com/photo-1502672260266-1c1ef2d93688?w=800",
|
||||
},
|
||||
});
|
||||
|
||||
// Add sleeping options
|
||||
await prisma.listingSleepingOption.createMany({
|
||||
data: [
|
||||
{
|
||||
listingId: listing1.id,
|
||||
bedType: "DOUBLE",
|
||||
quantity: 1,
|
||||
spotsPerUnit: 2,
|
||||
quality: "FULL",
|
||||
},
|
||||
{
|
||||
listingId: listing1.id,
|
||||
bedType: "SOFA_BED",
|
||||
quantity: 1,
|
||||
spotsPerUnit: 2,
|
||||
quality: "FULL",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Add tags
|
||||
await prisma.listingTag.createMany({
|
||||
data: [
|
||||
{ listingId: listing1.id, tagId: tagFavorite.id },
|
||||
{ listingId: listing1.id, tagId: tagGroup.id },
|
||||
],
|
||||
});
|
||||
|
||||
// Second listing
|
||||
const listing2 = await prisma.listing.upsert({
|
||||
where: { slug: "moderne-wohnung-zentrum-87654321" },
|
||||
update: {},
|
||||
create: {
|
||||
title: "Moderne Wohnung im Zentrum",
|
||||
slug: "moderne-wohnung-zentrum-87654321",
|
||||
airbnbUrl: "https://www.airbnb.com/rooms/87654321",
|
||||
normalizedUrl: "https://airbnb.com/rooms/87654321",
|
||||
externalId: "87654321",
|
||||
locationText: "Leipzig, Sachsen",
|
||||
latitude: 51.3397,
|
||||
longitude: 12.3731,
|
||||
nightlyPrice: 89.00,
|
||||
rating: 4.78,
|
||||
reviewCount: 42,
|
||||
officialGuestCount: 3,
|
||||
maxSleepingPlaces: 3,
|
||||
suitableFor4: false,
|
||||
extraMattressesNeededFor4: 1,
|
||||
bedTypesSummary: "1× Doppelbett, 1× Einzelbett",
|
||||
bedrooms: 1,
|
||||
beds: 2,
|
||||
bathrooms: 1.0,
|
||||
description: "Zentral gelegene Wohnung mit modernem Komfort.",
|
||||
hostName: "Thomas",
|
||||
isFavorite: false,
|
||||
status: "INTERESTING",
|
||||
coverImage: "https://images.unsplash.com/photo-1560448204-e02f11c3d0e2?w=800",
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.listingSleepingOption.createMany({
|
||||
data: [
|
||||
{
|
||||
listingId: listing2.id,
|
||||
bedType: "DOUBLE",
|
||||
quantity: 1,
|
||||
spotsPerUnit: 2,
|
||||
quality: "FULL",
|
||||
},
|
||||
{
|
||||
listingId: listing2.id,
|
||||
bedType: "SINGLE",
|
||||
quantity: 1,
|
||||
spotsPerUnit: 1,
|
||||
quality: "FULL",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await prisma.listingTag.create({
|
||||
data: { listingId: listing2.id, tagId: tagCheap.id },
|
||||
});
|
||||
|
||||
// Third listing
|
||||
const listing3 = await prisma.listing.upsert({
|
||||
where: { slug: "luxus-penthouse-berlin-55555555" },
|
||||
update: {},
|
||||
create: {
|
||||
title: "Luxus-Penthouse am Alexanderplatz",
|
||||
slug: "luxus-penthouse-berlin-55555555",
|
||||
airbnbUrl: "https://www.airbnb.com/rooms/55555555",
|
||||
normalizedUrl: "https://airbnb.com/rooms/55555555",
|
||||
externalId: "55555555",
|
||||
locationText: "Berlin, Mitte",
|
||||
latitude: 52.5200,
|
||||
longitude: 13.4050,
|
||||
nightlyPrice: 299.00,
|
||||
rating: 4.95,
|
||||
reviewCount: 156,
|
||||
officialGuestCount: 6,
|
||||
maxSleepingPlaces: 6,
|
||||
suitableFor4: true,
|
||||
extraMattressesNeededFor4: 0,
|
||||
bedTypesSummary: "2× Doppelbett, 1× Schlafsofa",
|
||||
bedrooms: 3,
|
||||
beds: 3,
|
||||
bathrooms: 2.0,
|
||||
description: "Luxuriöses Penthouse mit 360° Aussicht über Berlin. Perfekt für besondere Anlässe.",
|
||||
hostName: "Sophie",
|
||||
isFavorite: true,
|
||||
status: "SHORTLIST",
|
||||
coverImage: "https://images.unsplash.com/photo-1600596542815-ffad4c1539a9?w=800",
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.listingSleepingOption.createMany({
|
||||
data: [
|
||||
{
|
||||
listingId: listing3.id,
|
||||
bedType: "DOUBLE",
|
||||
quantity: 2,
|
||||
spotsPerUnit: 2,
|
||||
quality: "FULL",
|
||||
},
|
||||
{
|
||||
listingId: listing3.id,
|
||||
bedType: "SOFA_BED",
|
||||
quantity: 1,
|
||||
spotsPerUnit: 2,
|
||||
quality: "FULL",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await prisma.listingTag.createMany({
|
||||
data: [
|
||||
{ listingId: listing3.id, tagId: tagFavorite.id },
|
||||
{ listingId: listing3.id, tagId: tagGroup.id },
|
||||
],
|
||||
});
|
||||
|
||||
console.log("✅ Database seeded successfully!");
|
||||
console.log(` - ${3} listings created`);
|
||||
console.log(` - ${3} tags created`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
1
public/file.svg
Normal file
1
public/file.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
1
public/globe.svg
Normal file
1
public/globe.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
1
public/next.svg
Normal file
1
public/next.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
1
public/vercel.svg
Normal file
1
public/vercel.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 128 B |
1
public/window.svg
Normal file
1
public/window.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
90
src/actions/import-listing.ts
Normal file
90
src/actions/import-listing.ts
Normal file
@ -0,0 +1,90 @@
|
||||
"use server";
|
||||
|
||||
import { z } from "zod";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { scrapeAirbnbListing, extractAirbnbExternalId, normalizeAirbnbUrl } from "@/lib/airbnb-scraper";
|
||||
import { slugify } from "@/lib/utils";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
const schema = z.object({
|
||||
airbnbUrl: z.string().url("Ungültige URL"),
|
||||
});
|
||||
|
||||
export async function importListingAction(formData: FormData) {
|
||||
const parsed = schema.safeParse({
|
||||
airbnbUrl: formData.get("airbnbUrl"),
|
||||
});
|
||||
|
||||
if (!parsed.success) {
|
||||
return { ok: false, error: "Ungültiger Airbnb-Link." };
|
||||
}
|
||||
|
||||
const normalizedUrl = normalizeAirbnbUrl(parsed.data.airbnbUrl);
|
||||
const externalId = extractAirbnbExternalId(normalizedUrl);
|
||||
|
||||
const duplicate = await prisma.listing.findFirst({
|
||||
where: {
|
||||
OR: [
|
||||
{ normalizedUrl },
|
||||
...(externalId ? [{ externalId }] : []),
|
||||
],
|
||||
},
|
||||
select: { id: true, slug: true, title: true },
|
||||
});
|
||||
|
||||
if (duplicate) {
|
||||
return {
|
||||
ok: false,
|
||||
duplicate: true,
|
||||
listingId: duplicate.id,
|
||||
slug: duplicate.slug,
|
||||
error: `Bereits vorhanden: ${duplicate.title}`,
|
||||
};
|
||||
}
|
||||
|
||||
const scrapedData = await scrapeAirbnbListing(parsed.data.airbnbUrl);
|
||||
const title = scrapedData?.title || "Neues Airbnb";
|
||||
const slug = `${slugify(title)}-${Date.now()}`;
|
||||
|
||||
const listing = await prisma.listing.create({
|
||||
data: {
|
||||
title,
|
||||
slug,
|
||||
airbnbUrl: parsed.data.airbnbUrl,
|
||||
normalizedUrl,
|
||||
externalId,
|
||||
...(scrapedData?.pricePerNight && { nightlyPrice: scrapedData.pricePerNight }),
|
||||
...(scrapedData?.rating && { rating: scrapedData.rating }),
|
||||
...(scrapedData?.reviewCount && { reviewCount: scrapedData.reviewCount }),
|
||||
...(scrapedData?.guestCount && { guestCount: scrapedData.guestCount }),
|
||||
...(scrapedData?.bedrooms && { bedrooms: scrapedData.bedrooms }),
|
||||
...(scrapedData?.beds && { beds: scrapedData.beds }),
|
||||
...(scrapedData?.bathrooms && { bathrooms: scrapedData.bathrooms }),
|
||||
...(scrapedData?.description && { description: scrapedData.description }),
|
||||
...(scrapedData?.hostName && { hostName: scrapedData.hostName }),
|
||||
...(scrapedData?.location && { locationText: scrapedData.location }),
|
||||
...(scrapedData?.latitude && { latitude: scrapedData.latitude }),
|
||||
...(scrapedData?.longitude && { longitude: scrapedData.longitude }),
|
||||
...(scrapedData?.cancellationPolicy && { cancellationPolicy: scrapedData.cancellationPolicy }),
|
||||
...(scrapedData?.images?.length && { coverImage: scrapedData.images[0] }),
|
||||
...(scrapedData?.amenities?.length && { amenities: JSON.stringify(scrapedData.amenities) }),
|
||||
rawSourceData: scrapedData ? JSON.stringify(scrapedData) : null,
|
||||
},
|
||||
select: { id: true, slug: true },
|
||||
});
|
||||
|
||||
if (scrapedData?.images?.length) {
|
||||
await prisma.listingImage.createMany({
|
||||
data: scrapedData.images.map((url, index) => ({
|
||||
listingId: listing.id,
|
||||
url,
|
||||
sortOrder: index,
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
||||
revalidatePath("/dashboard");
|
||||
revalidatePath("/listings");
|
||||
|
||||
return { ok: true, listingId: listing.id, slug: listing.slug };
|
||||
}
|
||||
57
src/app/(protected)/admin/import/import-form.tsx
Normal file
57
src/app/(protected)/admin/import/import-form.tsx
Normal file
@ -0,0 +1,57 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { importListingAction } from "@/actions/import-listing";
|
||||
|
||||
export function ImportForm() {
|
||||
const [url, setUrl] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [success, setSuccess] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError("");
|
||||
setSuccess(false);
|
||||
setIsLoading(true);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("airbnbUrl", url);
|
||||
|
||||
const result = await importListingAction(formData);
|
||||
|
||||
if (result.ok) {
|
||||
setSuccess(true);
|
||||
setUrl("");
|
||||
} else if (result.error) {
|
||||
setError(result.error);
|
||||
}
|
||||
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="airbnb-url">Airbnb Link</Label>
|
||||
<Input
|
||||
id="airbnb-url"
|
||||
type="url"
|
||||
placeholder="https://www.airbnb.com/rooms/..."
|
||||
value={url}
|
||||
onChange={(e) => setUrl(e.target.value)}
|
||||
required
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
{error && <div className="text-red-500 text-sm">{error}</div>}
|
||||
{success && <div className="text-green-500 text-sm">✓ Erfolgreich importiert!</div>}
|
||||
<Button type="submit" className="w-full" disabled={isLoading || !url}>
|
||||
{isLoading ? "Wird importiert..." : "Importieren"}
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
14
src/app/(protected)/admin/import/page.tsx
Normal file
14
src/app/(protected)/admin/import/page.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
import { ImportForm } from "./import-form";
|
||||
import { RecentImports } from "./recent-imports";
|
||||
|
||||
export default function ImportPage() {
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50 p-8">
|
||||
<div className="container mx-auto max-w-2xl">
|
||||
<h1 className="text-3xl font-bold mb-8">Airbnb importieren</h1>
|
||||
<ImportForm />
|
||||
<RecentImports />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
35
src/app/(protected)/admin/import/recent-imports.tsx
Normal file
35
src/app/(protected)/admin/import/recent-imports.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
|
||||
export async function RecentImports() {
|
||||
const listings = await prisma.listing.findMany({
|
||||
take: 10,
|
||||
orderBy: { importedAt: "desc" },
|
||||
});
|
||||
|
||||
if (listings.length === 0) {
|
||||
return <p className="text-slate-500">Noch keine Listings importiert.</p>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-8">
|
||||
<h2 className="text-xl font-semibold mb-4">Zuletzt importiert</h2>
|
||||
<div className="space-y-2">
|
||||
{listings.map((listing) => (
|
||||
<Card key={listing.id}>
|
||||
<CardContent className="p-4 flex justify-between items-center">
|
||||
<div>
|
||||
<h3 className="font-medium">{listing.title}</h3>
|
||||
<p className="text-sm text-slate-500">{listing.locationText || "Kein Ort"}</p>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="font-medium">€{listing.nightlyPrice || "—"}</div>
|
||||
<div className="text-sm text-slate-500">⭐ {listing.rating || "—"}</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
169
src/app/(protected)/compare/page.tsx
Normal file
169
src/app/(protected)/compare/page.tsx
Normal file
@ -0,0 +1,169 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import Link from "next/link";
|
||||
|
||||
export default async function ComparePage() {
|
||||
const listings = await prisma.listing.findMany({
|
||||
where: {
|
||||
OR: [{ status: "SHORTLIST" }, { isFavorite: true }],
|
||||
},
|
||||
orderBy: { rating: "desc" },
|
||||
include: {
|
||||
sleepingOptions: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (listings.length === 0) {
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50 p-8">
|
||||
<div className="container mx-auto text-center py-16">
|
||||
<h1 className="text-3xl font-bold mb-4">📊 Vergleich</h1>
|
||||
<p className="text-slate-500 mb-4">
|
||||
Markiere Listings als Favorit oder setze Status auf "Shortlist" für
|
||||
den Vergleich
|
||||
</p>
|
||||
<Link href="/listings" className="text-blue-600 hover:underline">
|
||||
← Zu allen Listings
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50 p-8">
|
||||
<div className="container mx-auto">
|
||||
<div className="flex justify-between items-center mb-8">
|
||||
<h1 className="text-3xl font-bold">📊 Vergleich ({listings.length})</h1>
|
||||
<Link href="/listings" className="text-blue-600 hover:underline">
|
||||
← Zu allen Listings
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full border-collapse bg-white rounded-lg overflow-hidden shadow-lg">
|
||||
<thead className="bg-slate-800 text-white">
|
||||
<tr>
|
||||
<th className="p-4 text-left">Listing</th>
|
||||
<th className="p-4 text-center">€/Nacht</th>
|
||||
<th className="p-4 text-center">⭐ Rating</th>
|
||||
<th className="p-4 text-center">📍 Ort</th>
|
||||
<th className="p-4 text-center">🛏️ Schlafz.</th>
|
||||
<th className="p-4 text-center">🛏 Betten</th>
|
||||
<th className="p-4 text-center">👥 Max</th>
|
||||
<th className="p-4 text-center">4er-tauglich</th>
|
||||
<th className="p-4 text-center">Extra Matratzen</th>
|
||||
<th className="p-4 text-center">Schlafplätze</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{listings.map((listing, idx) => {
|
||||
const isBestPrice =
|
||||
listing.nightlyPrice ===
|
||||
Math.min(...listings.map((l) => l.nightlyPrice || Infinity));
|
||||
const isBestRating =
|
||||
listing.rating ===
|
||||
Math.max(...listings.map((l) => l.rating || 0));
|
||||
|
||||
return (
|
||||
<tr
|
||||
key={listing.id}
|
||||
className={
|
||||
idx % 2 === 0 ? "bg-white" : "bg-slate-50"
|
||||
}
|
||||
>
|
||||
<td className="p-4">
|
||||
<Link
|
||||
href={`/listings/${listing.slug}`}
|
||||
className="hover:text-blue-600"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
{listing.coverImage && (
|
||||
<img
|
||||
src={listing.coverImage}
|
||||
alt={listing.title}
|
||||
className="w-16 h-12 object-cover rounded"
|
||||
/>
|
||||
)}
|
||||
<div>
|
||||
<p className="font-medium truncate max-w-xs">
|
||||
{listing.title}
|
||||
</p>
|
||||
{listing.isFavorite && <span>❤️</span>}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</td>
|
||||
<td
|
||||
className={`p-4 text-center font-bold ${
|
||||
isBestPrice ? "text-green-600 bg-green-50" : ""
|
||||
}`}
|
||||
>
|
||||
€{listing.nightlyPrice?.toFixed(2) || "—"}
|
||||
{isBestPrice && (
|
||||
<Badge className="ml-2 bg-green-600">Beste</Badge>
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
className={`p-4 text-center ${
|
||||
isBestRating ? "text-green-600 bg-green-50 font-bold" : ""
|
||||
}`}
|
||||
>
|
||||
{listing.rating?.toFixed(2) || "—"}
|
||||
{isBestRating && (
|
||||
<Badge className="ml-2 bg-green-600">Top</Badge>
|
||||
)}
|
||||
</td>
|
||||
<td className="p-4 text-center text-sm">
|
||||
{listing.locationText || "—"}
|
||||
</td>
|
||||
<td className="p-4 text-center">{listing.bedrooms || "—"}</td>
|
||||
<td className="p-4 text-center">{listing.beds || "—"}</td>
|
||||
<td className="p-4 text-center font-medium">
|
||||
{listing.maxSleepingPlaces || "—"}
|
||||
</td>
|
||||
<td className="p-4 text-center">
|
||||
{listing.suitableFor4 ? (
|
||||
<span className="text-green-600 font-bold">✅ Ja</span>
|
||||
) : (
|
||||
<span className="text-red-500">❌ Nein</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="p-4 text-center">
|
||||
{listing.extraMattressesNeededFor4 !== null ? (
|
||||
listing.extraMattressesNeededFor4 === 0 ? (
|
||||
<span className="text-green-600 font-bold">0 ✅</span>
|
||||
) : (
|
||||
<span className="text-amber-600 font-bold">
|
||||
{listing.extraMattressesNeededFor4}
|
||||
</span>
|
||||
)
|
||||
) : (
|
||||
"—"
|
||||
)}
|
||||
</td>
|
||||
<td className="p-4 text-center text-xs">
|
||||
{listing.bedTypesSummary || "—"}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div className="mt-8 p-4 bg-blue-50 rounded-lg">
|
||||
<h3 className="font-semibold mb-2">💡 Schlafplatz-Analyse</h3>
|
||||
<p className="text-sm text-slate-600">
|
||||
<strong>4er-tauglich:</strong> Mindestens 4 vollwertige Schlafplätze
|
||||
verfügbar
|
||||
<br />
|
||||
<strong>Extra Matratzen:</strong> Anzahl zusätzlicher Matratzen,
|
||||
die für 4 Personen benötigt werden
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
133
src/app/(protected)/dashboard/page.tsx
Normal file
133
src/app/(protected)/dashboard/page.tsx
Normal file
@ -0,0 +1,133 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { auth } from "@/lib/auth";
|
||||
import Link from "next/link";
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const session = await auth();
|
||||
|
||||
if (!session) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const [totalCount, stats, favoriteCount] = await Promise.all([
|
||||
prisma.listing.count(),
|
||||
prisma.listing.aggregate({
|
||||
_avg: {
|
||||
nightlyPrice: true,
|
||||
rating: true,
|
||||
},
|
||||
}),
|
||||
prisma.listing.count({ where: { isFavorite: true } }),
|
||||
]);
|
||||
|
||||
const recentListings = await prisma.listing.findMany({
|
||||
take: 5,
|
||||
orderBy: { importedAt: "desc" },
|
||||
});
|
||||
|
||||
const favoriteListings = await prisma.listing.findMany({
|
||||
take: 3,
|
||||
where: { isFavorite: true },
|
||||
orderBy: { rating: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50">
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<div className="flex justify-between items-center mb-8">
|
||||
<h1 className="text-3xl font-bold">🏠 Airbnb Finder</h1>
|
||||
<Link href="/admin/import">
|
||||
<Button>➕ Neues Airbnb importieren</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm text-slate-600">Gesamt</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-3xl font-bold">{totalCount}</p>
|
||||
<p className="text-sm text-slate-500">Listings</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm text-slate-600">⌀ Durchschnittspreis</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-3xl font-bold">
|
||||
€{stats._avg.nightlyPrice?.toFixed(2) || "—"}
|
||||
</p>
|
||||
<p className="text-sm text-slate-500">pro Nacht</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm text-slate-600">⭐ Durchschnittsbewertung</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-3xl font-bold">
|
||||
{stats._avg.rating?.toFixed(2) || "—"}
|
||||
</p>
|
||||
<p className="text-sm text-slate-500">von 5.00</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm text-slate-600">❤️ Favoriten</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-3xl font-bold">{favoriteCount}</p>
|
||||
<p className="text-sm text-slate-500">Listings</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div className="mb-8">
|
||||
<h2 className="text-xl font-semibold mb-4">Zuletzt importiert</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{recentListings.map((listing) => (
|
||||
<Card key={listing.id} className="hover:shadow-lg transition-shadow">
|
||||
<CardContent className="p-4">
|
||||
<h3 className="font-medium truncate">{listing.title}</h3>
|
||||
<p className="text-sm text-slate-500">{listing.locationText}</p>
|
||||
<div className="flex justify-between mt-2">
|
||||
<span>€{listing.nightlyPrice?.toFixed(2) || "—"}</span>
|
||||
<span>⭐ {listing.rating?.toFixed(2) || "—"}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{favoriteListings.length > 0 && (
|
||||
<div>
|
||||
<h2 className="text-xl font-semibold mb-4">❤️ Favoriten</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{favoriteListings.map((listing) => (
|
||||
<Card key={listing.id} className="hover:shadow-lg transition-shadow">
|
||||
<CardContent className="p-4">
|
||||
<h3 className="font-medium truncate">{listing.title}</h3>
|
||||
<p className="text-sm text-slate-500">{listing.locationText}</p>
|
||||
<div className="flex justify-between mt-2">
|
||||
<span>€{listing.nightlyPrice?.toFixed(2) || "—"}</span>
|
||||
<span>⭐ {listing.rating?.toFixed(2) || "—"}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
234
src/app/(protected)/listings/[slug]/page.tsx
Normal file
234
src/app/(protected)/listings/[slug]/page.tsx
Normal file
@ -0,0 +1,234 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { redirect } from "next/navigation";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import Link from "next/link";
|
||||
|
||||
export default async function ListingDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: { slug: string };
|
||||
}) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const listing = await prisma.listing.findUnique({
|
||||
where: { slug: params.slug },
|
||||
include: {
|
||||
images: true,
|
||||
notes: true,
|
||||
sleepingOptions: true,
|
||||
tags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!listing) {
|
||||
redirect("/listings");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50 p-8">
|
||||
<div className="container mx-auto max-w-6xl">
|
||||
<Link
|
||||
href="/listings"
|
||||
className="text-blue-600 hover:underline mb-6 inline-block"
|
||||
>
|
||||
← Zurück zur Übersicht
|
||||
</Link>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
{/* Main Content */}
|
||||
<div className="lg:col-span-2 space-y-6">
|
||||
{/* Images */}
|
||||
<Card>
|
||||
<CardContent className="p-0 overflow-hidden">
|
||||
{listing.coverImage ? (
|
||||
<img
|
||||
src={listing.coverImage}
|
||||
alt={listing.title}
|
||||
className="w-full h-96 object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-96 bg-slate-200 flex items-center justify-center">
|
||||
Kein Bild
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Details */}
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<h2 className="text-xl font-semibold mb-4">📋 Details</h2>
|
||||
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
||||
<div>
|
||||
<p className="text-sm text-slate-500">Schlafzimmer</p>
|
||||
<p className="text-xl font-bold">{listing.bedrooms || "—"}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-slate-500">Betten</p>
|
||||
<p className="text-xl font-bold">{listing.beds || "—"}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-slate-500">Badezimmer</p>
|
||||
<p className="text-xl font-bold">{listing.bathrooms || "—"}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-slate-500">Max Gäste</p>
|
||||
<p className="text-xl font-bold">{listing.maxSleepingPlaces || "—"}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{listing.description && (
|
||||
<div>
|
||||
<h3 className="font-medium mb-2">Beschreibung</h3>
|
||||
<p className="text-slate-600">{listing.description}</p>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Sleep Analysis */}
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<h2 className="text-xl font-semibold mb-4">🛏️ Schlafplatz-Analyse</h2>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4 mb-4">
|
||||
<div className="p-4 bg-slate-50 rounded">
|
||||
<p className="text-sm text-slate-500">4 Personen geeignet</p>
|
||||
<p className={`text-2xl font-bold ${listing.suitableFor4 ? "text-green-600" : "text-red-500"}`}>
|
||||
{listing.suitableFor4 ? "✅ Ja" : "❌ Nein"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="p-4 bg-slate-50 rounded">
|
||||
<p className="text-sm text-slate-500">Extra Matratzen für 4</p>
|
||||
<p className={`text-2xl font-bold ${listing.extraMattressesNeededFor4 === 0 ? "text-green-600" : "text-amber-600"}`}>
|
||||
{listing.extraMattressesNeededFor4 ?? "—"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{listing.sleepingOptions.length > 0 && (
|
||||
<div>
|
||||
<h3 className="font-medium mb-2">Schlafmöglichkeiten</h3>
|
||||
<div className="space-y-2">
|
||||
{listing.sleepingOptions.map((opt) => (
|
||||
<div key={opt.id} className="flex justify-between p-2 bg-slate-50 rounded">
|
||||
<span>{opt.label || opt.bedType}</span>
|
||||
<span className="font-medium">
|
||||
{opt.quantity}× ({opt.spotsPerUnit} Plätze)
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Notes */}
|
||||
{listing.notes.length > 0 && (
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<h2 className="text-xl font-semibold mb-4">📝 Notizen</h2>
|
||||
<div className="space-y-3">
|
||||
{listing.notes.map((note) => (
|
||||
<div key={note.id} className="p-3 bg-slate-50 rounded">
|
||||
<p className="text-sm">{note.body}</p>
|
||||
<p className="text-xs text-slate-400 mt-1">
|
||||
{new Date(note.createdAt).toLocaleDateString("de-DE")}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sidebar */}
|
||||
<div className="space-y-6">
|
||||
{/* Price Card */}
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<h1 className="text-2xl font-bold mb-2">{listing.title}</h1>
|
||||
<p className="text-slate-500 mb-4">📍 {listing.locationText || "Kein Ort"}</p>
|
||||
|
||||
<div className="flex items-baseline gap-2 mb-4">
|
||||
<span className="text-4xl font-bold">
|
||||
€{listing.nightlyPrice?.toFixed(2) || "—"}
|
||||
</span>
|
||||
<span className="text-slate-500">/ Nacht</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 mb-4">
|
||||
<span className="text-xl">⭐</span>
|
||||
<span className="font-semibold">{listing.rating?.toFixed(2) || "—"}</span>
|
||||
{listing.reviewCount && (
|
||||
<span className="text-slate-500">
|
||||
({listing.reviewCount} Bewertungen)
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{listing.hostName && (
|
||||
<p className="text-sm text-slate-500 mb-4">
|
||||
👤 Host: {listing.hostName}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap gap-2 mb-4">
|
||||
{listing.tags.map((lt) => (
|
||||
<Badge
|
||||
key={lt.tag.id}
|
||||
style={{ backgroundColor: lt.tag.color || "#6366f1" }}
|
||||
className="text-white"
|
||||
>
|
||||
{lt.tag.name}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<a
|
||||
href={listing.airbnbUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block w-full bg-red-500 text-white text-center py-3 rounded-lg hover:bg-red-600 transition"
|
||||
>
|
||||
🔗 Auf Airbnb ansehen
|
||||
</a>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Status */}
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<h3 className="font-semibold mb-2">Status</h3>
|
||||
<Badge
|
||||
className={
|
||||
listing.status === "SHORTLIST"
|
||||
? "bg-green-500"
|
||||
: listing.status === "REJECTED"
|
||||
? "bg-red-500"
|
||||
: "bg-slate-500"
|
||||
}
|
||||
>
|
||||
{listing.status}
|
||||
</Badge>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
116
src/app/(protected)/listings/page.tsx
Normal file
116
src/app/(protected)/listings/page.tsx
Normal file
@ -0,0 +1,116 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import Link from "next/link";
|
||||
|
||||
export default async function ListingsPage() {
|
||||
const listings = await prisma.listing.findMany({
|
||||
orderBy: { importedAt: "desc" },
|
||||
include: {
|
||||
tags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50 p-8">
|
||||
<div className="container mx-auto">
|
||||
<div className="flex justify-between items-center mb-8">
|
||||
<h1 className="text-3xl font-bold">🏠 Alle Listings</h1>
|
||||
<Link href="/admin/import" className="text-blue-600 hover:underline">
|
||||
➕ Neu importieren
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
{listings.map((listing) => (
|
||||
<Link key={listing.id} href={`/listings/${listing.slug}`}>
|
||||
<Card className="hover:shadow-xl transition-all hover:-translate-y-1 overflow-hidden">
|
||||
{listing.coverImage && (
|
||||
<div className="h-48 bg-slate-200 relative">
|
||||
<img
|
||||
src={listing.coverImage}
|
||||
alt={listing.title}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
{listing.isFavorite && (
|
||||
<div className="absolute top-2 right-2">
|
||||
<span className="text-2xl">❤️</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<CardContent className="p-4">
|
||||
<h3 className="font-semibold text-lg mb-1 truncate">
|
||||
{listing.title}
|
||||
</h3>
|
||||
<p className="text-sm text-slate-500 mb-2">
|
||||
📍 {listing.locationText || "Kein Ort"}
|
||||
</p>
|
||||
|
||||
<div className="flex justify-between items-center mb-3">
|
||||
<span className="text-xl font-bold">
|
||||
€{listing.nightlyPrice?.toFixed(2) || "—"}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
⭐ {listing.rating?.toFixed(2) || "—"}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-1 mb-2">
|
||||
{listing.bedrooms && (
|
||||
<Badge variant="secondary">🛏️ {listing.bedrooms}</Badge>
|
||||
)}
|
||||
{listing.beds && (
|
||||
<Badge variant="secondary">🛏 {listing.beds}</Badge>
|
||||
)}
|
||||
{listing.bathrooms && (
|
||||
<Badge variant="secondary">🚿 {listing.bathrooms}</Badge>
|
||||
)}
|
||||
{listing.maxSleepingPlaces && (
|
||||
<Badge variant="secondary">
|
||||
👥 {listing.maxSleepingPlaces}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{listing.tags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{listing.tags.slice(0, 3).map((lt) => (
|
||||
<Badge
|
||||
key={lt.tag.id}
|
||||
style={{ backgroundColor: lt.tag.color || "#6366f1" }}
|
||||
className="text-white text-xs"
|
||||
>
|
||||
{lt.tag.name}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{listing.suitableFor4 && (
|
||||
<div className="mt-2 text-xs text-green-600 font-medium">
|
||||
✅ Geeignet für 4 Personen
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{listings.length === 0 && (
|
||||
<div className="text-center py-16 text-slate-500">
|
||||
<p className="text-xl mb-4">Keine Listings vorhanden</p>
|
||||
<Link href="/admin/import" className="text-blue-600 hover:underline">
|
||||
➕ Erstes Listing importieren
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
144
src/app/(protected)/map/page.tsx
Normal file
144
src/app/(protected)/map/page.tsx
Normal file
@ -0,0 +1,144 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
// Dynamically import Leaflet (SSR=false)
|
||||
const MapContainer = dynamic(
|
||||
() => import("react-leaflet").then((mod) => mod.MapContainer),
|
||||
{ ssr: false }
|
||||
);
|
||||
const TileLayer = dynamic(
|
||||
() => import("react-leaflet").then((mod) => mod.TileLayer),
|
||||
{ ssr: false }
|
||||
);
|
||||
const Marker = dynamic(
|
||||
() => import("react-leaflet").then((mod) => mod.Marker),
|
||||
{ ssr: false }
|
||||
);
|
||||
const Popup = dynamic(
|
||||
() => import("react-leaflet").then((mod) => mod.Popup),
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
interface Listing {
|
||||
id: string;
|
||||
slug: string;
|
||||
title: string;
|
||||
locationText: string | null;
|
||||
latitude: number | null;
|
||||
longitude: number | null;
|
||||
nightlyPrice: number | null;
|
||||
rating: number | null;
|
||||
coverImage: string | null;
|
||||
isFavorite: boolean;
|
||||
}
|
||||
|
||||
export default function MapPage() {
|
||||
const [listings, setListings] = useState<Listing[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/listings")
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setListings(data.listings || []);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50 flex items-center justify-center">
|
||||
<div className="text-xl">Lade Karte...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const listingsWithCoords = listings.filter(
|
||||
(l) => l.latitude && l.longitude
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50">
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<h1 className="text-3xl font-bold mb-6">🗺️ Kartenansicht</h1>
|
||||
|
||||
<Card>
|
||||
<CardContent className="p-0">
|
||||
<div className="h-[70vh] rounded-lg overflow-hidden">
|
||||
{typeof window !== "undefined" && (
|
||||
<MapContainer
|
||||
center={
|
||||
listingsWithCoords.length > 0
|
||||
? [
|
||||
listingsWithCoords[0].latitude!,
|
||||
listingsWithCoords[0].longitude!,
|
||||
]
|
||||
: [51.0504, 13.7373]
|
||||
}
|
||||
zoom={11}
|
||||
className="h-full w-full"
|
||||
>
|
||||
<TileLayer
|
||||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
/>
|
||||
{listingsWithCoords.map((listing) => (
|
||||
<Marker
|
||||
key={listing.id}
|
||||
position={[listing.latitude!, listing.longitude!]}
|
||||
>
|
||||
<Popup>
|
||||
<div className="w-56">
|
||||
{listing.coverImage && (
|
||||
<img
|
||||
src={listing.coverImage}
|
||||
alt={listing.title}
|
||||
className="w-full h-24 object-cover rounded mb-2"
|
||||
/>
|
||||
)}
|
||||
<h3 className="font-semibold text-sm mb-1">
|
||||
{listing.title}
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500 mb-2">
|
||||
{listing.locationText}
|
||||
</p>
|
||||
<div className="flex justify-between text-sm mb-2">
|
||||
<span className="font-bold">
|
||||
€{listing.nightlyPrice?.toFixed(2)}
|
||||
</span>
|
||||
<span>⭐ {listing.rating?.toFixed(2)}</span>
|
||||
</div>
|
||||
<a
|
||||
href={`/listings/${listing.slug}`}
|
||||
className="text-blue-600 text-xs hover:underline"
|
||||
>
|
||||
→ Details
|
||||
</a>
|
||||
</div>
|
||||
</Popup>
|
||||
</Marker>
|
||||
))}
|
||||
</MapContainer>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{listingsWithCoords.length === 0 && (
|
||||
<div className="text-center py-8 text-slate-500">
|
||||
Keine Listings mit Koordinaten vorhanden
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-4 text-sm text-slate-500">
|
||||
{listingsWithCoords.length} von {listings.length} Listings auf der
|
||||
Karte sichtbar
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
30
src/app/api/listings/route.ts
Normal file
30
src/app/api/listings/route.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const listings = await prisma.listing.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
title: true,
|
||||
locationText: true,
|
||||
latitude: true,
|
||||
longitude: true,
|
||||
nightlyPrice: true,
|
||||
rating: true,
|
||||
coverImage: true,
|
||||
isFavorite: true,
|
||||
},
|
||||
orderBy: { importedAt: "desc" },
|
||||
});
|
||||
|
||||
return NextResponse.json({ listings });
|
||||
} catch (error) {
|
||||
console.error("Error fetching listings:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch listings" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
BIN
src/app/favicon.ico
Normal file
BIN
src/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
77
src/app/globals.css
Normal file
77
src/app/globals.css
Normal file
@ -0,0 +1,77 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: 0 0% 100%;
|
||||
--foreground: 0 0% 3.9%;
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 0 0% 3.9%;
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 0 0% 3.9%;
|
||||
--primary: 0 0% 9%;
|
||||
--primary-foreground: 0 0% 98%;
|
||||
--secondary: 0 0% 96.1%;
|
||||
--secondary-foreground: 0 0% 9%;
|
||||
--muted: 0 0% 96.1%;
|
||||
--muted-foreground: 0 0% 45.1%;
|
||||
--accent: 0 0% 96.1%;
|
||||
--accent-foreground: 0 0% 9%;
|
||||
--destructive: 0 84.2% 60.2%;
|
||||
--destructive-foreground: 0 0% 98%;
|
||||
--border: 0 0% 89.8%;
|
||||
--input: 0 0% 89.8%;
|
||||
--ring: 0 0% 3.9%;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: hsl(var(--background));
|
||||
--color-foreground: hsl(var(--foreground));
|
||||
--color-card: hsl(var(--card));
|
||||
--color-card-foreground: hsl(var(--card-foreground));
|
||||
--color-popover: hsl(var(--popover));
|
||||
--color-popover-foreground: hsl(var(--popover-foreground));
|
||||
--color-primary: hsl(var(--primary));
|
||||
--color-primary-foreground: hsl(var(--primary-foreground));
|
||||
--color-secondary: hsl(var(--secondary));
|
||||
--color-secondary-foreground: hsl(var(--secondary-foreground));
|
||||
--color-muted: hsl(var(--muted));
|
||||
--color-muted-foreground: hsl(var(--muted-foreground));
|
||||
--color-accent: hsl(var(--accent));
|
||||
--color-accent-foreground: hsl(var(--accent-foreground));
|
||||
--color-destructive: hsl(var(--destructive));
|
||||
--color-destructive-foreground: hsl(var(--destructive-foreground));
|
||||
--color-border: hsl(var(--border));
|
||||
--color-input: hsl(var(--input));
|
||||
--color-ring: hsl(var(--ring));
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: 0 0% 3.9%;
|
||||
--foreground: 0 0% 98%;
|
||||
--card: 0 0% 3.9%;
|
||||
--card-foreground: 0 0% 98%;
|
||||
--popover: 0 0% 3.9%;
|
||||
--popover-foreground: 0 0% 98%;
|
||||
--primary: 0 0% 98%;
|
||||
--primary-foreground: 0 0% 9%;
|
||||
--secondary: 0 0% 14.9%;
|
||||
--secondary-foreground: 0 0% 98%;
|
||||
--muted: 0 0% 14.9%;
|
||||
--muted-foreground: 0 0% 63.9%;
|
||||
--accent: 0 0% 14.9%;
|
||||
--accent-foreground: 0 0% 98%;
|
||||
--destructive: 0 62.8% 30.6%;
|
||||
--destructive-foreground: 0 0% 98%;
|
||||
--border: 0 0% 14.9%;
|
||||
--input: 0 0% 14.9%;
|
||||
--ring: 0 0% 83.1%;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
34
src/app/layout.tsx
Normal file
34
src/app/layout.tsx
Normal file
@ -0,0 +1,34 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
65
src/app/page.tsx
Normal file
65
src/app/page.tsx
Normal file
@ -0,0 +1,65 @@
|
||||
import Image from "next/image";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/next.svg"
|
||||
alt="Next.js logo"
|
||||
width={100}
|
||||
height={20}
|
||||
priority
|
||||
/>
|
||||
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
|
||||
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
|
||||
To get started, edit the page.tsx file.
|
||||
</h1>
|
||||
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
||||
Looking for a starting point or more instructions? Head over to{" "}
|
||||
<a
|
||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Templates
|
||||
</a>{" "}
|
||||
or the{" "}
|
||||
<a
|
||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Learning
|
||||
</a>{" "}
|
||||
center.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/vercel.svg"
|
||||
alt="Vercel logomark"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Deploy Now
|
||||
</a>
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Documentation
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
36
src/components/ui/badge.tsx
Normal file
36
src/components/ui/badge.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
import * as React from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
|
||||
secondary:
|
||||
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
destructive:
|
||||
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
||||
outline: "text-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export interface BadgeProps
|
||||
extends React.HTMLAttributes<HTMLDivElement>,
|
||||
VariantProps<typeof badgeVariants> {}
|
||||
|
||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
||||
return (
|
||||
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants };
|
||||
57
src/components/ui/button.tsx
Normal file
57
src/components/ui/button.tsx
Normal file
@ -0,0 +1,57 @@
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
||||
destructive:
|
||||
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
||||
outline:
|
||||
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2",
|
||||
sm: "h-8 rounded-md px-3 text-xs",
|
||||
lg: "h-10 rounded-md px-8",
|
||||
icon: "h-9 w-9",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
return (
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button, buttonVariants };
|
||||
76
src/components/ui/card.tsx
Normal file
76
src/components/ui/card.tsx
Normal file
@ -0,0 +1,76 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Card = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"rounded-xl border bg-card text-card-foreground shadow",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
Card.displayName = "Card";
|
||||
|
||||
const CardHeader = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardHeader.displayName = "CardHeader";
|
||||
|
||||
const CardTitle = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("font-semibold leading-none tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardTitle.displayName = "CardTitle";
|
||||
|
||||
const CardDescription = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardDescription.displayName = "CardDescription";
|
||||
|
||||
const CardContent = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
||||
));
|
||||
CardContent.displayName = "CardContent";
|
||||
|
||||
const CardFooter = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex items-center p-6 pt-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardFooter.displayName = "CardFooter";
|
||||
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
||||
22
src/components/ui/input.tsx
Normal file
22
src/components/ui/input.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
Input.displayName = "Input";
|
||||
|
||||
export { Input };
|
||||
26
src/components/ui/label.tsx
Normal file
26
src/components/ui/label.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as LabelPrimitive from "@radix-ui/react-label";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const labelVariants = cva(
|
||||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||
);
|
||||
|
||||
const Label = React.forwardRef<
|
||||
React.ComponentRef<typeof LabelPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
||||
VariantProps<typeof labelVariants>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<LabelPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(labelVariants(), className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
Label.displayName = LabelPrimitive.Root.displayName;
|
||||
|
||||
export { Label };
|
||||
120
src/lib/airbnb-scraper.ts
Normal file
120
src/lib/airbnb-scraper.ts
Normal file
@ -0,0 +1,120 @@
|
||||
import * as cheerio from "cheerio";
|
||||
|
||||
export interface ScrapedListing {
|
||||
title: string | null;
|
||||
pricePerNight: number | null;
|
||||
totalPrice: number | null;
|
||||
rating: number | null;
|
||||
reviewCount: number | null;
|
||||
guestCount: number | null;
|
||||
bedrooms: number | null;
|
||||
beds: number | null;
|
||||
bathrooms: number | null;
|
||||
description: string | null;
|
||||
hostName: string | null;
|
||||
location: string | null;
|
||||
latitude: number | null;
|
||||
longitude: number | null;
|
||||
images: string[];
|
||||
amenities: string[];
|
||||
cancellationPolicy: string | null;
|
||||
}
|
||||
|
||||
export async function scrapeAirbnbListing(url: string): Promise<ScrapedListing | null> {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
|
||||
"Accept": "text/html,application/xhtml+xml",
|
||||
"Accept-Language": "de-DE,en-US;q=0.9",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`HTTP ${response.status} for ${url}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
const jsonLdScript = $('script[type="application/ld+json"]').html();
|
||||
let listingData: Partial<ScrapedListing> = {};
|
||||
|
||||
if (jsonLdScript) {
|
||||
try {
|
||||
const jsonData = JSON.parse(jsonLdScript);
|
||||
|
||||
if (jsonData["@type"] === "LodgingBusiness" || jsonData["@type"] === "Room") {
|
||||
listingData.title = jsonData.name || null;
|
||||
listingData.description = jsonData.description || null;
|
||||
listingData.location = jsonData.address?.addressLocality || null;
|
||||
|
||||
if (jsonData.geo) {
|
||||
listingData.latitude = jsonData.geo.latitude || null;
|
||||
listingData.longitude = jsonData.geo.longitude || null;
|
||||
}
|
||||
|
||||
if (jsonData.makesOffer?.offers) {
|
||||
const offer = jsonData.makesOffer.offers[0];
|
||||
if (offer.price) {
|
||||
listingData.pricePerNight = parseFloat(offer.price) || null;
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonData.aggregateRating) {
|
||||
listingData.rating = jsonData.aggregateRating.ratingValue || null;
|
||||
listingData.reviewCount = jsonData.aggregateRating.reviewCount || null;
|
||||
}
|
||||
|
||||
if (jsonData.image) {
|
||||
const images = Array.isArray(jsonData.image)
|
||||
? jsonData.image.map((img: any) => img.url || img)
|
||||
: [jsonData.image.url || jsonData.image];
|
||||
listingData.images = images.filter(Boolean);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to parse JSON-LD:", e);
|
||||
}
|
||||
}
|
||||
|
||||
const getMeta = (name: string) => {
|
||||
return $(`meta[property="${name}"]`).attr("content") ||
|
||||
$(`meta[name="${name}"]`).attr("content") || null;
|
||||
};
|
||||
|
||||
if (!listingData.title) {
|
||||
listingData.title = getMeta("og:title") || getMeta("twitter:title");
|
||||
}
|
||||
if (!listingData.description) {
|
||||
listingData.description = getMeta("og:description") || getMeta("twitter:description");
|
||||
}
|
||||
if (!listingData.images?.length) {
|
||||
const ogImage = getMeta("og:image");
|
||||
if (ogImage) listingData.images = [ogImage];
|
||||
}
|
||||
|
||||
return listingData as ScrapedListing;
|
||||
} catch (error) {
|
||||
console.error("Scraping failed:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function extractAirbnbExternalId(url: string): string | null {
|
||||
const match = url.match(/\/rooms\/(\d+)/);
|
||||
return match?.[1] || null;
|
||||
}
|
||||
|
||||
export function normalizeAirbnbUrl(url: string): string {
|
||||
try {
|
||||
const urlObj = new URL(url.trim());
|
||||
urlObj.hash = "";
|
||||
urlObj.search = "";
|
||||
urlObj.pathname = urlObj.pathname.replace(/\/+$/, "");
|
||||
urlObj.hostname = urlObj.hostname.replace(/^www\./, "").toLowerCase();
|
||||
return urlObj.toString();
|
||||
} catch {
|
||||
return url.trim();
|
||||
}
|
||||
}
|
||||
47
src/lib/auth.ts
Normal file
47
src/lib/auth.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import NextAuth from "next-auth";
|
||||
import Credentials from "next-auth/providers/credentials";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
export const { handlers, auth, signIn, signOut } = NextAuth({
|
||||
session: { strategy: "jwt" },
|
||||
providers: [
|
||||
Credentials({
|
||||
credentials: {
|
||||
username: { label: "Username", type: "text" },
|
||||
password: { label: "Password", type: "password" },
|
||||
},
|
||||
authorize: async (credentials) => {
|
||||
const username = credentials.username as string;
|
||||
const password = credentials.password as string;
|
||||
|
||||
const validUser = username === process.env.ADMIN_USERNAME;
|
||||
const validPass = await bcrypt.compare(
|
||||
password,
|
||||
process.env.ADMIN_PASSWORD_HASH!
|
||||
);
|
||||
|
||||
if (!validUser || !validPass) return null;
|
||||
|
||||
return {
|
||||
id: "admin",
|
||||
name: "Admin",
|
||||
email: "admin@localhost",
|
||||
role: "admin",
|
||||
};
|
||||
},
|
||||
}),
|
||||
],
|
||||
callbacks: {
|
||||
jwt({ token, user }) {
|
||||
if (user) token.role = (user as any).role;
|
||||
return token;
|
||||
},
|
||||
session({ session, token }) {
|
||||
(session.user as any).role = token.role;
|
||||
return session;
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
signIn: "/login",
|
||||
},
|
||||
});
|
||||
9
src/lib/prisma.ts
Normal file
9
src/lib/prisma.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ||
|
||||
new PrismaClient();
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
|
||||
30
src/lib/utils.ts
Normal file
30
src/lib/utils.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { type ClassValue, clsx } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
export function slugify(text: string) {
|
||||
return text
|
||||
.toLowerCase()
|
||||
.normalize("NFKD")
|
||||
.replace(/[^\w\s-]/g, "")
|
||||
.trim()
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/-+/g, "-")
|
||||
.slice(0, 80);
|
||||
}
|
||||
|
||||
export function formatPrice(price: number | null | undefined, currency = "EUR") {
|
||||
if (price === null || price === undefined) return "—";
|
||||
return new Intl.NumberFormat("de-DE", {
|
||||
style: "currency",
|
||||
currency,
|
||||
}).format(price);
|
||||
}
|
||||
|
||||
export function formatRating(rating: number | null | undefined) {
|
||||
if (rating === null || rating === undefined) return "—";
|
||||
return rating.toFixed(2);
|
||||
}
|
||||
34
tsconfig.json
Normal file
34
tsconfig.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts",
|
||||
"**/*.mts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user