-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
visits, buttons, experiments, profil
- Loading branch information
Showing
15 changed files
with
2,878 additions
and
15 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
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
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,31 @@ | ||
import { db } from "@/app/firebase"; | ||
import { doc, serverTimestamp, setDoc } from "firebase/firestore"; | ||
import { NextResponse } from "next/server"; | ||
|
||
type Params = { | ||
towerID: string; | ||
userID: string; | ||
text: string; | ||
date: Date; | ||
} | ||
|
||
export async function POST(request: Request) { | ||
const params : Params = await request.json() as Params; | ||
|
||
if (!params.towerID || !params.userID || !params.date) return NextResponse.json({ | ||
status: 400, | ||
message: "Wrong parameters provided." | ||
}) | ||
|
||
await setDoc(doc(db, "visits", `${params.userID}_${params.towerID}`), { | ||
created: serverTimestamp(), | ||
user_id: params.userID, | ||
tower_id: params.towerID, | ||
text: params.text, | ||
date: params.date | ||
}); | ||
|
||
return NextResponse.json({ | ||
status: 201 | ||
}); | ||
} |
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,20 @@ | ||
import { db } from "@/app/firebase"; | ||
import { deleteDoc, doc } from "firebase/firestore"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function POST(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
|
||
const userID = searchParams.get("user_id"); | ||
const towerID = searchParams.get("tower_id"); | ||
if (!towerID || !userID) return NextResponse.json({ | ||
status: 400, | ||
message: "Wrong parameters provided." | ||
}) | ||
|
||
await deleteDoc(doc(db, "visits", `${userID}_${towerID}`)); | ||
|
||
return NextResponse.json({ | ||
status: 200 | ||
}); | ||
} |
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,54 @@ | ||
import { db } from "@/app/firebase"; | ||
import { collection, doc, getDoc, getDocs, query, where } from "firebase/firestore"; | ||
import { NextResponse } from "next/server"; | ||
|
||
const DB_COL_NAME = "visits" | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const userID = searchParams.get("user_id"); | ||
const towerID = searchParams.get("tower_id"); | ||
|
||
if (userID && towerID) { | ||
const snap = await getDoc(doc(db, DB_COL_NAME, `${userID}_${towerID}`)); | ||
if (!snap.exists()) return NextResponse.json({status: 404}); | ||
const obj: any = snap.data(); | ||
obj.date = new Date(Date.parse(obj.date)); | ||
obj.created = obj.created.toDate(); | ||
obj.id = snap.id; | ||
return NextResponse.json({status: 200, message: obj}); | ||
} | ||
|
||
if (towerID) { | ||
const q = query(collection(db, DB_COL_NAME), where("tower_id", "==", towerID)); | ||
const querySnapshot = await getDocs(q); | ||
const reviews : any[] = []; | ||
querySnapshot.forEach((doc) => { | ||
const obj: any = doc.data(); | ||
obj.date = new Date(Date.parse(obj.date)); | ||
obj.created = obj.created.toDate(); | ||
obj.id = doc.id; | ||
reviews.push(obj) | ||
}); | ||
return NextResponse.json({status: 200, message: reviews}); | ||
} | ||
|
||
if (userID) { | ||
const q = query(collection(db, DB_COL_NAME), where("user_id", "==", userID)); | ||
const querySnapshot = await getDocs(q); | ||
const reviews : any[] = []; | ||
querySnapshot.forEach((doc) => { | ||
const obj: any = doc.data(); | ||
obj.date = new Date(Date.parse(obj.date)); | ||
obj.created = obj.created.toDate(); | ||
obj.id = doc.id; | ||
reviews.push(obj) | ||
}); | ||
return NextResponse.json({status: 200, message: reviews}); | ||
} | ||
|
||
return NextResponse.json({ | ||
status: 400, | ||
message: "Wrong parametres provided." | ||
}); | ||
} |
Oops, something went wrong.
f72da39
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
lookout-towers-v2 – ./
lookout-towers-v2-dp9898cz.vercel.app
www.rozhlednovysvet.cz
lookout-towers-v2-git-main-dp9898cz.vercel.app
lookout-towers-v2.vercel.app
rozhlednovysvet.cz