Merge branch '@feature/add-prisma' into develop

This commit is contained in:
Fergal Moran
2022-09-28 11:55:26 +01:00
28 changed files with 166 additions and 5 deletions

7
.env Normal file
View File

@@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="postgresql://postgres:hackme@localhost:5432/frasier-gifs?schema=public"

5
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

12
.idea/frasier-gifs.iml generated Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/frasier-gifs.iml" filepath="$PROJECT_DIR$/.idea/frasier-gifs.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

9
models/Gif.ts Normal file
View File

@@ -0,0 +1,9 @@
export interface Gif {
id: string;
title: string;
description: string;
fileName: string;
dateCreated: string;
upVotes: Number;
downVotes: Number;
}

3
models/index.ts Normal file
View File

@@ -0,0 +1,3 @@
import {Gif} from "./Gif";
export type {Gif}

View File

@@ -9,6 +9,7 @@
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"@prisma/client": "4.4.0",
"next": "12.3.1", "next": "12.3.1",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0"
@@ -21,6 +22,7 @@
"eslint": "8.24.0", "eslint": "8.24.0",
"eslint-config-next": "12.3.1", "eslint-config-next": "12.3.1",
"postcss": "^8.4.16", "postcss": "^8.4.16",
"prisma": "^4.4.0",
"tailwindcss": "^3.1.8", "tailwindcss": "^3.1.8",
"typescript": "4.8.4" "typescript": "4.8.4"
} }

View File

@@ -1,10 +1,38 @@
import type { NextPage } from "next"; import { PrismaClient } from "@prisma/client";
import Head from "next/head"; import type { GetServerSideProps, NextPage } from "next";
import { Gif } from "../models";
import Image from "next/image"; import Image from "next/image";
import styles from "../styles/Home.module.css";
const Home: NextPage = () => { interface IHomeProps {
return <h1 className="text-3xl text-red-700 font-bold underline">Hello world!</h1>; gifs: Gif[]
}
const Home: NextPage<IHomeProps> = ({ gifs }) => {
return (
<div>
<h1 className="text-3xl font-bold text-red-700 underline">
Frasier Gifs
</h1>
<div className="grid grid-cols-3">
{gifs.map((gif: Gif) => {
return (
<div key={gif.id}>
<h2>{gif.title}</h2>
<Image alt={gif.title} width={64} height={64} src={`/samples/${gif.fileName}.gif`} />
</div>
)
})}
</div>
</div>
);
}; };
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
const prisma = new PrismaClient();
const gifs = await prisma.gif.findMany({
take: 12, orderBy: { title: 'asc' },
});
return { props: { gifs: JSON.parse(JSON.stringify(gifs)) } };
};
export default Home; export default Home;

View File

@@ -0,0 +1,12 @@
-- CreateTable
CREATE TABLE "Gif" (
"id" TEXT NOT NULL,
"title" VARCHAR(100) NOT NULL,
"description" VARCHAR(2000) NOT NULL,
"searchTerms" VARCHAR(2000) NOT NULL,
"upVotes" INTEGER NOT NULL DEFAULT 0,
"downVotes" INTEGER NOT NULL DEFAULT 0,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Gif_pkey" PRIMARY KEY ("id")
);

View File

@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `fileName` to the `Gif` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Gif" ADD COLUMN "fileName" VARCHAR(100) NOT NULL;

View File

@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Gif" ALTER COLUMN "description" DROP NOT NULL,
ALTER COLUMN "searchTerms" DROP NOT NULL;

View 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 = "postgresql"

25
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,25 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Gif {
id String @id @default(uuid())
title String @db.VarChar(100)
description String? @db.VarChar(2000)
searchTerms String? @db.VarChar(2000)
//this is temporary, filenames should always match the GUID above
fileName String @db.VarChar(100)
upVotes Int @default(0)
downVotes Int @default(0)
createdAt DateTime @default(now())
}

BIN
public/samples/sample-1.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 KiB

BIN
public/samples/sample-2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
public/samples/sample-3.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

BIN
public/samples/sample-4.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

BIN
public/samples/sample-5.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

BIN
public/samples/sample-6.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

BIN
public/samples/sample-7.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

BIN
public/samples/sample-8.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

BIN
public/samples/sample-9.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 MiB

View File

@@ -154,6 +154,23 @@
"@nodelib/fs.scandir" "2.1.5" "@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0" fastq "^1.6.0"
"@prisma/client@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-4.4.0.tgz#45f59c172dd3621ecc92d7cf9bc765d85e6c7d56"
integrity sha512-ciKOP246x1xwr04G9ajHlJ4pkmtu9Q6esVyqVBO0QJihaKQIUvbPjClp17IsRJyxqNpFm4ScbOc/s9DUzKHINQ==
dependencies:
"@prisma/engines-version" "4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6"
"@prisma/engines-version@4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6":
version "4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6.tgz#00875863bb30b670a586a5b5794a000f7f3ad976"
integrity sha512-P5v/PuEIJLYXZUZBvOLPqoyCW+m6StNqHdiR6te++gYVODpPdLakks5HVx3JaZIY+LwR02juJWFlwpc9Eog/ug==
"@prisma/engines@4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-4.4.0.tgz#6ca7d3ce8eee08dcfa82311b0a02f5ccaac7dc0c"
integrity sha512-Fpykccxlt9MHrAs/QpPGpI2nOiRxuLA+LiApgA59ibbf24YICZIMWd3SI2YD+q0IAIso0jCGiHhirAIbxK3RyQ==
"@rushstack/eslint-patch@^1.1.3": "@rushstack/eslint-patch@^1.1.3":
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.2.0.tgz#8be36a1f66f3265389e90b5f9c9962146758f728" resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.2.0.tgz#8be36a1f66f3265389e90b5f9c9962146758f728"
@@ -1630,6 +1647,13 @@ prelude-ls@^1.2.1:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==
prisma@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-4.4.0.tgz#0c53324bf6a29474636b3e1964e0d72e0277bf8f"
integrity sha512-l/QKLmLcKJQFuc+X02LyICo0NWTUVaNNZ00jKJBqwDyhwMAhboD1FWwYV50rkH4Wls0RviAJSFzkC2ZrfawpfA==
dependencies:
"@prisma/engines" "4.4.0"
prop-types@^15.8.1: prop-types@^15.8.1:
version "15.8.1" version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"