diff --git a/databases/dev.db b/databases/dev.db deleted file mode 100644 index 04166d9..0000000 Binary files a/databases/dev.db and /dev/null differ diff --git a/prisma/migrations/20230217230230_created_at_for_the_review_model/migration.sql b/prisma/migrations/20230217230230_created_at_for_the_review_model/migration.sql new file mode 100644 index 0000000..163c2da --- /dev/null +++ b/prisma/migrations/20230217230230_created_at_for_the_review_model/migration.sql @@ -0,0 +1,17 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_review" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "authorId" INTEGER NOT NULL, + "hotelId" INTEGER NOT NULL, + "rating" INTEGER NOT NULL, + "text" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT "review_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "Users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "review_hotelId_fkey" FOREIGN KEY ("hotelId") REFERENCES "Hotels" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_review" ("authorId", "hotelId", "id", "rating", "text") SELECT "authorId", "hotelId", "id", "rating", "text" FROM "review"; +DROP TABLE "review"; +ALTER TABLE "new_review" RENAME TO "review"; +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20230218005318_make_review_unique_author_id_hotel_id/migration.sql b/prisma/migrations/20230218005318_make_review_unique_author_id_hotel_id/migration.sql new file mode 100644 index 0000000..517cc08 --- /dev/null +++ b/prisma/migrations/20230218005318_make_review_unique_author_id_hotel_id/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - A unique constraint covering the columns `[authorId,hotelId]` on the table `review` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateIndex +CREATE UNIQUE INDEX "review_authorId_hotelId_key" ON "review"("authorId", "hotelId"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e23a289..79f8a1d 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -78,4 +78,6 @@ model review { hotel hotel @relation(fields: [hotelId], references: [id]) rating Int text String + createdAt DateTime @default(now()) + // @@unique([authorId, hotelId]) it should be unique } diff --git a/public/auth/front.css b/public/auth/front.css new file mode 100644 index 0000000..92ab08a --- /dev/null +++ b/public/auth/front.css @@ -0,0 +1,106 @@ +/* Hero image */ +.hero-image { + background-image: url("https://source.unsplash.com/1600x900/?hotel"); + background-color: #000; + height: 50vh; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + position: relative; + } + + .hero-text { + text-align: center; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + color: white; + } + + /* Hotel cards */ + .card { + border: none; + margin: 20px; + } + + .card .card-img-top { + object-fit: cover; + height: 200px; + } + + .card-title { + font-size: 24px; + font-weight: 500; + } + + .card-text { + margin-top: 10px; + margin-bottom: 10px; + } + + + .rating { + color:red + } + + /* Star rating */ +.stars { + display: inline-block; + font-size: 18px; + color: #ffd700; + } + + .stars i { + margin-right: 5px; + } + + .half { + position: relative; + } + + .half::before { + content: "\f089"; + font-family: "Font Awesome 5 Free"; + font-weight: 900; + position: absolute; + left: 0; + color: #777; + } + + /* change color of the stars according to rating data */ + .stars-0, + .stars-1, + .stars-2, + .stars-3, + .stars-4, + .stars-5 { + color: #b3b3b3; + } + + .stars-1 i:nth-child(-n + 1), + .stars-2 i:nth-child(-n + 2), + .stars-3 i:nth-child(-n + 3), + .stars-4 i:nth-child(-n + 4), + .stars-5 i:nth-child(-n + 5) { + color: #ffd700; + } + + .stars-0.half, + .stars-1.half, + .stars-2.half, + .stars-3.half, + .stars-4.half, + .stars-5.half { + color: #ffd700; + } + + .stars-0.half::before, + .stars-1.half::before, + .stars-2.half::before, + .stars-3.half::before, + .stars-4.half::before, + .stars-5.half::before { + color: #b3b3b3; + } + diff --git a/public/auth/script/front.js b/public/auth/script/front.js new file mode 100644 index 0000000..bc13f99 --- /dev/null +++ b/public/auth/script/front.js @@ -0,0 +1,44 @@ +let hotelurl; +hotelurl = 'http://localhost:3000/upload/'; +JavaScript: + +$(document).ready(() => { + // fetch data from API and generate hotel cards + fetch("http://localhost:3000/review/a",{ + method:'Put' + }) + .then(response => response.json()) + .then(data => { + const hotelCards = data.map(hotel => { + // calculate star rating data + const rating = hotel.averageRating; + const fullStars = Math.floor(rating); + const hasHalfStar = rating % 1 >= 0.5; + const emptyStars = 5 - fullStars - (hasHalfStar ? 1 : 0); + // generate star rating HTML + const starRatingHtml = ` +
${hotel.user_name}
+ +