diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..41583e3 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@jsr:registry=https://npm.jsr.io diff --git a/app/entry.server.tsx b/app/entry.server.tsx index e25cfe4..e03a461 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -18,8 +18,7 @@ export default async function handleRequest( remixContext: EntryContext, // This is ignored so we can keep it in the template for visibility. Feel // free to delete this parameter in your app if you're not using it! - // eslint-disable-next-line @typescript-eslint/no-unused-vars - loadContext: AppLoadContext, + _loadContext: AppLoadContext, ) { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), ABORT_DELAY); @@ -37,6 +36,7 @@ export default async function handleRequest( // Log streaming rendering errors from inside the shell console.error(error); } + // biome-ignore lint/style/noParameterAssign: フレームワークの既存コードのため responseStatusCode = 500; }, }, diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index a724f4d..230f969 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -1,7 +1,7 @@ import type { MetaFunction } from "@remix-run/cloudflare"; -import type { AppType } from "../../server"; -import {hc} from 'hono/client'; import { useLoaderData } from "@remix-run/react"; +import { hc } from "hono/client"; +import type { AppType } from "../../server"; export const meta: MetaFunction = () => { return [ @@ -11,14 +11,28 @@ export const meta: MetaFunction = () => { }; export const loader = async () => { - const client = hc('http://localhost:5173'); - const res = await client.api.movie.$get(); - const movies = await res.json(); - return movies; -} + const client = hc("http://localhost:5173"); + const moviesResponse = await client.api.movies.$get(); + const movies = await moviesResponse.json(); + const theatersResponse = await client.api.theaters.$get(); + const theaters = await theatersResponse.json(); + const creatersCountriesResponse = await client.api.creaters_countries.$get(); + const creatersCountries = await creatersCountriesResponse.json(); + const screeningFormatsResponse = await client.api.screening_formats.$get(); + const screeningFormats = await screeningFormatsResponse.json(); + const movieFormatsResponse = await client.api.movie_formats.$get(); + const movieFormats = await movieFormatsResponse.json(); + return { + movies, + theaters, + creatersCountries, + screeningFormats, + movieFormats, + }; +}; export default function Index() { - const movies = useLoaderData(); + const data = useLoaderData(); return ( @@ -28,9 +42,60 @@ export default function Index() {

Hello World

-
    - {movies.map((movie) => (
  • {movie.title}
  • ))} -
+
+

Movies

+
    + {data.movies.map((movie) => ( +
  • + {movie.title}({movie.id})、{movie.theater.name}( + {movie.theaterId})、{movie.createrCountry.name}( + {movie.createrCountryId})、{movie.screeningFormat.name}( + {movie.screeningFormatId})、{movie.movieFormat.name}( + {movie.movieFormatId}) +
  • + ))} +
+
+
+

Theaters

+
    + {data.theaters.map((theater) => ( +
  • + {theater.name}({theater.id}) +
  • + ))} +
+
+
+

Creaters Countries

+
    + {data.creatersCountries.map((createrCountry) => ( +
  • + {createrCountry.name}({createrCountry.id}) +
  • + ))} +
+
+
+

Screening Formats

+
    + {data.screeningFormats.map((screeningFormat) => ( +
  • + {screeningFormat.name}({screeningFormat.id}) +
  • + ))} +
+
+
+

Movie Formats

+
    + {data.movieFormats.map((movieFormat) => ( +
  • + {movieFormat.name}({movieFormat.id}) +
  • + ))} +
+
); diff --git a/functions/[[path]].ts b/functions/[[path]].ts index b5b831e..ee92a26 100644 --- a/functions/[[path]].ts +++ b/functions/[[path]].ts @@ -1,5 +1,5 @@ -import handle from 'hono-remix-adapter/cloudflare-pages' -import * as build from '../build/server' -import server from '../server' +import handle from "hono-remix-adapter/cloudflare-pages"; +import * as build from "../build/server"; +import server from "../server"; -export const onRequest = handle(build, server) \ No newline at end of file +export const onRequest = handle(build, server); diff --git a/package.json b/package.json index a925224..43e4160 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@remix-run/cloudflare": "^2.13.1", "@remix-run/cloudflare-pages": "^2.13.1", "@remix-run/react": "^2.13.1", + "@std/ulid": "npm:@jsr/std__ulid@1.0.0-rc.4", "@tidbcloud/prisma-adapter": "^5.20.0", "@tidbcloud/serverless": "^0.2.0", "hono": "^4.6.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5640f74..522dff8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: '@remix-run/react': specifier: ^2.13.1 version: 2.13.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3) + '@std/ulid': + specifier: npm:@jsr/std__ulid@1.0.0-rc.4 + version: '@jsr/std__ulid@1.0.0-rc.4' '@tidbcloud/prisma-adapter': specifier: ^5.20.0 version: 5.20.0(@tidbcloud/serverless@0.2.0) @@ -951,6 +954,9 @@ packages: '@jspm/core@2.1.0': resolution: {integrity: sha512-3sRl+pkyFY/kLmHl0cgHiFp2xEqErA8N3ECjMs7serSUBmoJ70lBa0PG5t0IM6WJgdZNyyI0R8YFfi5wM8+mzg==} + '@jsr/std__ulid@1.0.0-rc.4': + resolution: {integrity: sha512-dJPkGZitKk31EOSyP64SAlTXdGPlzu4CXOBIYwq+0zSeATGMjB4ZVgGjrUqUp/YZEUah6XwX1WLc9krGHqQjPw==, tarball: https://npm.jsr.io/~/11/@jsr/std__ulid/1.0.0-rc.4.tgz} + '@mdx-js/mdx@2.3.0': resolution: {integrity: sha512-jLuwRlz8DQfQNiUCJR50Y09CGPq3fLtmtUQfVrj79E0JWu3dvsVcxVIcfhR5h0iXu+/z++zDrYeiJqifRynJkA==} @@ -3941,6 +3947,8 @@ snapshots: '@jspm/core@2.1.0': {} + '@jsr/std__ulid@1.0.0-rc.4': {} + '@mdx-js/mdx@2.3.0': dependencies: '@types/estree-jsx': 1.0.5 diff --git a/prisma/migrations/20241030130225_init/migration.sql b/prisma/migrations/20241030130225_init/migration.sql deleted file mode 100644 index 4fa529e..0000000 --- a/prisma/migrations/20241030130225_init/migration.sql +++ /dev/null @@ -1,30 +0,0 @@ --- CreateTable -CREATE TABLE `tbl_movieinfo` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `title` VARCHAR(246) NOT NULL, - `is_dubbed` BOOLEAN NOT NULL, - `is_domestic` BOOLEAN NOT NULL, - `is_live_action` BOOLEAN NOT NULL, - `theater_id` INTEGER NOT NULL, - `view_start_datetime` DATETIME(3) NOT NULL, - `view_end_datetime` DATETIME(3) NOT NULL, - `accompanier` INTEGER NULL, - `rating` INTEGER NULL, - `comment` TEXT NULL, - - UNIQUE INDEX `tbl_movieinfo_id_key`(`id`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `tbl_theater` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(246) NOT NULL, - - UNIQUE INDEX `tbl_theater_id_key`(`id`), - UNIQUE INDEX `tbl_theater_name_key`(`name`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `tbl_movieinfo` ADD CONSTRAINT `tbl_movieinfo_theater_id_fkey` FOREIGN KEY (`theater_id`) REFERENCES `tbl_theater`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20241030143918_init/migration.sql b/prisma/migrations/20241030143918_init/migration.sql deleted file mode 100644 index cc18856..0000000 --- a/prisma/migrations/20241030143918_init/migration.sql +++ /dev/null @@ -1,62 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `accompanier` on the `tbl_movieinfo` table. All the data in the column will be lost. - - You are about to drop the column `is_domestic` on the `tbl_movieinfo` table. All the data in the column will be lost. - - You are about to drop the column `is_dubbed` on the `tbl_movieinfo` table. All the data in the column will be lost. - - You are about to drop the column `is_live_action` on the `tbl_movieinfo` table. All the data in the column will be lost. - - Added the required column `creater_country_id` to the `tbl_movieinfo` table without a default value. This is not possible if the table is not empty. - - Added the required column `is_subtitles` to the `tbl_movieinfo` table without a default value. This is not possible if the table is not empty. - - Added the required column `movie_format_id` to the `tbl_movieinfo` table without a default value. This is not possible if the table is not empty. - - Added the required column `screening_format_id` to the `tbl_movieinfo` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE `tbl_movieinfo` DROP COLUMN `accompanier`, - DROP COLUMN `is_domestic`, - DROP COLUMN `is_dubbed`, - DROP COLUMN `is_live_action`, - ADD COLUMN `companions_count` INTEGER NULL, - ADD COLUMN `creater_country_id` INTEGER NOT NULL, - ADD COLUMN `is_subtitles` BOOLEAN NOT NULL, - ADD COLUMN `movie_format_id` INTEGER NOT NULL, - ADD COLUMN `screening_format_id` INTEGER NOT NULL; - --- CreateTable -CREATE TABLE `creaters_countries` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(246) NOT NULL, - - UNIQUE INDEX `creaters_countries_id_key`(`id`), - UNIQUE INDEX `creaters_countries_name_key`(`name`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `movie_formats` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(246) NOT NULL, - - UNIQUE INDEX `movie_formats_id_key`(`id`), - UNIQUE INDEX `movie_formats_name_key`(`name`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `screening_formats` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(246) NOT NULL, - - UNIQUE INDEX `screening_formats_id_key`(`id`), - UNIQUE INDEX `screening_formats_name_key`(`name`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `tbl_movieinfo` ADD CONSTRAINT `tbl_movieinfo_creater_country_id_fkey` FOREIGN KEY (`creater_country_id`) REFERENCES `creaters_countries`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `tbl_movieinfo` ADD CONSTRAINT `tbl_movieinfo_movie_format_id_fkey` FOREIGN KEY (`movie_format_id`) REFERENCES `movie_formats`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `tbl_movieinfo` ADD CONSTRAINT `tbl_movieinfo_screening_format_id_fkey` FOREIGN KEY (`screening_format_id`) REFERENCES `screening_formats`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20241030144158_init/migration.sql b/prisma/migrations/20241030144158_init/migration.sql deleted file mode 100644 index 0f413fa..0000000 --- a/prisma/migrations/20241030144158_init/migration.sql +++ /dev/null @@ -1,65 +0,0 @@ -/* - Warnings: - - - You are about to drop the `tbl_movieinfo` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `tbl_theater` table. If the table is not empty, all the data it contains will be lost. - -*/ --- DropForeignKey -ALTER TABLE `tbl_movieinfo` DROP FOREIGN KEY `tbl_movieinfo_creater_country_id_fkey`; - --- DropForeignKey -ALTER TABLE `tbl_movieinfo` DROP FOREIGN KEY `tbl_movieinfo_movie_format_id_fkey`; - --- DropForeignKey -ALTER TABLE `tbl_movieinfo` DROP FOREIGN KEY `tbl_movieinfo_screening_format_id_fkey`; - --- DropForeignKey -ALTER TABLE `tbl_movieinfo` DROP FOREIGN KEY `tbl_movieinfo_theater_id_fkey`; - --- DropTable -DROP TABLE `tbl_movieinfo`; - --- DropTable -DROP TABLE `tbl_theater`; - --- CreateTable -CREATE TABLE `movies` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `title` VARCHAR(246) NOT NULL, - `is_subtitles` BOOLEAN NOT NULL, - `theater_id` INTEGER NOT NULL, - `creater_country_id` INTEGER NOT NULL, - `movie_format_id` INTEGER NOT NULL, - `screening_format_id` INTEGER NOT NULL, - `view_start_datetime` DATETIME(3) NOT NULL, - `view_end_datetime` DATETIME(3) NOT NULL, - `companions_count` INTEGER NULL, - `rating` INTEGER NULL, - `comment` TEXT NULL, - - UNIQUE INDEX `movies_id_key`(`id`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `theaters` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(246) NOT NULL, - - UNIQUE INDEX `theaters_id_key`(`id`), - UNIQUE INDEX `theaters_name_key`(`name`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `movies` ADD CONSTRAINT `movies_theater_id_fkey` FOREIGN KEY (`theater_id`) REFERENCES `theaters`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `movies` ADD CONSTRAINT `movies_creater_country_id_fkey` FOREIGN KEY (`creater_country_id`) REFERENCES `creaters_countries`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `movies` ADD CONSTRAINT `movies_movie_format_id_fkey` FOREIGN KEY (`movie_format_id`) REFERENCES `movie_formats`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `movies` ADD CONSTRAINT `movies_screening_format_id_fkey` FOREIGN KEY (`screening_format_id`) REFERENCES `screening_formats`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20241103161851_init/migration.sql b/prisma/migrations/20241103161851_init/migration.sql new file mode 100644 index 0000000..12abb4b --- /dev/null +++ b/prisma/migrations/20241103161851_init/migration.sql @@ -0,0 +1,94 @@ +-- DropTable +DROP TABLE `movies`; + +-- DropTable +DROP TABLE `theaters`; + +-- DropTable +DROP TABLE `creaters_countries`; + +-- DropTable +DROP TABLE `movie_formats`; + +-- DropTable +DROP TABLE `screening_formats`; + +-- CreateTable +CREATE TABLE `movies` ( + `movie_pk` INTEGER NOT NULL AUTO_INCREMENT, + `id` CHAR(26) NOT NULL, + `title` VARCHAR(246) NOT NULL, + `is_subtitles` BOOLEAN NOT NULL, + `theater_id` CHAR(26) NOT NULL, + `creater_country_id` CHAR(26) NOT NULL, + `movie_format_id` CHAR(26) NOT NULL, + `screening_format_id` CHAR(26) NOT NULL, + `view_start_datetime` DATETIME(3) NOT NULL, + `view_end_datetime` DATETIME(3) NOT NULL, + `companions_count` INTEGER NULL, + `rating` INTEGER NULL, + `comment` TEXT NULL, + + UNIQUE INDEX `movies_movie_pk_key`(`movie_pk`), + PRIMARY KEY (`movie_pk`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `theaters` ( + `theater_pk` INTEGER NOT NULL AUTO_INCREMENT, + `id` CHAR(26) NOT NULL, + `name` VARCHAR(246) NOT NULL, + + UNIQUE INDEX `theaters_theater_pk_key`(`theater_pk`), + UNIQUE INDEX `theaters_id_key`(`id`), + UNIQUE INDEX `theaters_name_key`(`name`), + PRIMARY KEY (`theater_pk`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `creaters_countries` ( + `creater_country_pk` INTEGER NOT NULL AUTO_INCREMENT, + `id` CHAR(26) NOT NULL, + `name` VARCHAR(246) NOT NULL, + + UNIQUE INDEX `creaters_countries_creater_country_pk_key`(`creater_country_pk`), + UNIQUE INDEX `creaters_countries_id_key`(`id`), + UNIQUE INDEX `creaters_countries_name_key`(`name`), + PRIMARY KEY (`creater_country_pk`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `movie_formats` ( + `movie_format_pk` INTEGER NOT NULL AUTO_INCREMENT, + `id` CHAR(26) NOT NULL, + `name` VARCHAR(246) NOT NULL, + + UNIQUE INDEX `movie_formats_movie_format_pk_key`(`movie_format_pk`), + UNIQUE INDEX `movie_formats_id_key`(`id`), + UNIQUE INDEX `movie_formats_name_key`(`name`), + PRIMARY KEY (`movie_format_pk`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `screening_formats` ( + `screening_format_pk` INTEGER NOT NULL AUTO_INCREMENT, + `id` CHAR(26) NOT NULL, + `name` VARCHAR(246) NOT NULL, + + UNIQUE INDEX `screening_formats_screening_format_pk_key`(`screening_format_pk`), + UNIQUE INDEX `screening_formats_id_key`(`id`), + UNIQUE INDEX `screening_formats_name_key`(`name`), + PRIMARY KEY (`screening_format_pk`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `movies` ADD CONSTRAINT `movies_theater_id_fkey` FOREIGN KEY (`theater_id`) REFERENCES `theaters`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `movies` ADD CONSTRAINT `movies_creater_country_id_fkey` FOREIGN KEY (`creater_country_id`) REFERENCES `creaters_countries`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `movies` ADD CONSTRAINT `movies_movie_format_id_fkey` FOREIGN KEY (`movie_format_id`) REFERENCES `movie_formats`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `movies` ADD CONSTRAINT `movies_screening_format_id_fkey` FOREIGN KEY (`screening_format_id`) REFERENCES `screening_formats`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0a3cbd6..cb16b61 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -5,7 +5,7 @@ // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" previewFeatures = ["driverAdapters"] } @@ -15,13 +15,14 @@ datasource db { } model Movie { - id Int @id @unique @default(autoincrement()) + moviePk Int @id @unique @default(autoincrement()) @map("movie_pk") + id String @db.Char(26) title String @db.VarChar(246) isSubtitles Boolean @map("is_subtitles") - theaterId Int @map("theater_id") - createrCountryId Int @map("creater_country_id") - movieFormatId Int @map("movie_format_id") - screeningFormatId Int @map("screening_format_id") + theaterId String @map("theater_id") @db.Char(26) + createrCountryId String @map("creater_country_id") @db.Char(26) + movieFormatId String @map("movie_format_id") @db.Char(26) + screeningFormatId String @map("screening_format_id") @db.Char(26) viewStartDatetime DateTime @map("view_start_datetime") viewEndDatetime DateTime @map("view_end_datetime") companionsCount Int? @map("companions_count") @@ -37,8 +38,9 @@ model Movie { } model Theater { - id Int @id @unique @default(autoincrement()) - name String @unique @db.VarChar(246) + theaterPk Int @id @unique @default(autoincrement()) @map("theater_pk") + id String @unique @db.Char(26) + name String @unique @db.VarChar(246) movies Movie[] @@ -46,8 +48,9 @@ model Theater { } model CreaterCountry { - id Int @id @unique @default(autoincrement()) - name String @unique @db.VarChar(246) + createrCountryPk Int @id @unique @default(autoincrement()) @map("creater_country_pk") + id String @unique @db.Char(26) + name String @unique @db.VarChar(246) movies Movie[] @@ -55,8 +58,9 @@ model CreaterCountry { } model MovieFormat { - id Int @id @unique @default(autoincrement()) - name String @unique @db.VarChar(246) + movieFormatPk Int @id @unique @default(autoincrement()) @map("movie_format_pk") + id String @unique @db.Char(26) + name String @unique @db.VarChar(246) movies Movie[] @@ -64,8 +68,9 @@ model MovieFormat { } model ScreeningFormat { - id Int @id @unique @default(autoincrement()) - name String @unique @db.VarChar(246) + screeningFormatPk Int @id @unique @default(autoincrement()) @map("screening_format_pk") + id String @unique @db.Char(26) + name String @unique @db.VarChar(246) movies Movie[] diff --git a/prisma/seed.ts b/prisma/seed.ts index c95cef2..5aa730b 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,36 +1,47 @@ import { PrismaClient } from "@prisma/client"; +import { ulid } from "@std/ulid"; const client = new PrismaClient(); +const theaterId = ulid(); +const createrCountryId = ulid(); +const movieFormatId = ulid(); +const screeningFormatId = ulid(); + async function main() { await client.theater.create({ data: { + id: theaterId, name: "Theater 1", }, }); await client.createrCountry.create({ data: { + id: createrCountryId, name: "アメリカ合衆国", }, }); await client.movieFormat.create({ data: { + id: movieFormatId, name: "2Dアニメーション", }, }); await client.screeningFormat.create({ data: { + id: screeningFormatId, name: "IMAX", }, }); await client.movie.create({ data: { + id: ulid(), title: "The Shawshank Redemption", isSubtitles: true, - theaterId: 1, - createrCountryId: 1, - movieFormatId: 1, - screeningFormatId: 1, + theaterId, + createrCountryId, + movieFormatId, + screeningFormatId, viewStartDatetime: new Date("2022-01-01T00:00:00Z"), viewEndDatetime: new Date("2022-01-02T00:00:00Z"), rating: 2, diff --git a/server/index.ts b/server/index.ts index b8d613f..307093f 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1,3 +1,4 @@ +import { ulid } from "@std/ulid"; import { Hono } from "hono"; import { setupPrisma } from "../prisma"; const app = new Hono<{ Bindings: { DATABASE_URL: string } }>(); @@ -14,9 +15,14 @@ const routes = app const movie = await prisma.movie.findFirst({ where: { - id: Number.parseInt(id), + id, }, include: { + theater: { + select: { + name: true, + }, + }, createrCountry: { select: { name: true, @@ -41,11 +47,16 @@ const routes = app return c.json(movie); }) - .get(`${BASE_PATH}/movie`, async (c) => { + .get(`${BASE_PATH}/movies`, async (c) => { const prisma = setupPrisma(c.env.DATABASE_URL); const movies = await prisma.movie.findMany({ include: { + theater: { + select: { + name: true, + }, + }, createrCountry: { select: { name: true, @@ -70,10 +81,10 @@ const routes = app const body = await c.req.json<{ title: string; isSubtitles: boolean; - theaterId: number; - createrCountryId: number; - movieFormatId: number; - screeningFormatId: number; + theaterId: string; + createrCountryId: string; + movieFormatId: string; + screeningFormatId: string; viewStartDatetime: string; viewEndDatetime: string; companionsCount: number | null; @@ -84,6 +95,7 @@ const routes = app const movie = await prisma.movie.create({ data: { + id: ulid(), title: body.title, isSubtitles: body.isSubtitles, theaterId: body.theaterId, @@ -101,11 +113,19 @@ const routes = app return c.json(movie); }) .patch(`${BASE_PATH}/movie/:id`, async (c) => { + const id = c.req.param("id"); const prisma = setupPrisma(c.env.DATABASE_URL); + const sorceMovie = await prisma.movie.findFirst({ + where: { + id, + }, + }); + const movie = await prisma.movie.update({ where: { - id: 1, + moviePk: sorceMovie?.moviePk, + id, }, data: { title: "The Godfather", @@ -118,13 +138,48 @@ const routes = app const id = c.req.param("id"); const prisma = setupPrisma(c.env.DATABASE_URL); + const sorceMovie = await prisma.movie.findFirst({ + where: { + id, + }, + }); + const movie = await prisma.movie.delete({ where: { - id: Number.parseInt(id), + moviePk: sorceMovie?.moviePk, + id, }, }); return c.json(movie); + }) + .get(`${BASE_PATH}/theaters`, async (c) => { + const prisma = setupPrisma(c.env.DATABASE_URL); + + const theaters = await prisma.theater.findMany(); + + return c.json(theaters); + }) + .get(`${BASE_PATH}/creaters_countries`, async (c) => { + const prisma = setupPrisma(c.env.DATABASE_URL); + + const createrCountries = await prisma.createrCountry.findMany(); + + return c.json(createrCountries); + }) + .get(`${BASE_PATH}/movie_formats`, async (c) => { + const prisma = setupPrisma(c.env.DATABASE_URL); + + const movieFormats = await prisma.movieFormat.findMany(); + + return c.json(movieFormats); + }) + .get(`${BASE_PATH}/screening_formats`, async (c) => { + const prisma = setupPrisma(c.env.DATABASE_URL); + + const screeningFormats = await prisma.screeningFormat.findMany(); + + return c.json(screeningFormats); }); export default app; diff --git a/vite.config.ts b/vite.config.ts index 86fc860..4e9a8ca 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,4 +1,4 @@ -import { defaultOptions} from '@hono/vite-dev-server'; +import { defaultOptions } from "@hono/vite-dev-server"; import adapter from "@hono/vite-dev-server/cloudflare"; import { vitePlugin as remix, @@ -30,7 +30,12 @@ export default defineConfig({ serverAdapter({ adapter, entry: "./server/index.ts", - exclude: [...defaultOptions.exclude, '/assets/**', '/app/**', "/public/**"], + exclude: [ + ...defaultOptions.exclude, + "/assets/**", + "/app/**", + "/public/**", + ], }), tsconfigPaths(), ], diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index c013460..d1da21b 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -1,3 +1,5 @@ -// Generated by Wrangler -// After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen` -type Env = {}; +// Generated by Wrangler by running `wrangler types` + +interface Env { + DATABASE_URL: string; +}