From 769d1556573947864a1b58290d126caf1548c857 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E3=81=97=E3=81=BF?=
<37952374+Simirall@users.noreply.github.com>
Date: Wed, 21 Aug 2024 23:10:34 +0900
Subject: [PATCH] Add: Bought column (#3)
* chore: add column
* feat: apply bought
---
migrations/0003_noisy_raider.sql | 1 +
migrations/meta/0003_snapshot.json | 206 ++++++++++++++++++++++++++
migrations/meta/_journal.json | 7 +
schema.ts | 1 +
src/apis/madamis.ts | 13 +-
src/pages/components/MadamisList.tsx | 28 ++--
src/pages/components/MadamisModal.tsx | 7 +
7 files changed, 240 insertions(+), 23 deletions(-)
create mode 100644 migrations/0003_noisy_raider.sql
create mode 100644 migrations/meta/0003_snapshot.json
diff --git a/migrations/0003_noisy_raider.sql b/migrations/0003_noisy_raider.sql
new file mode 100644
index 0000000..63a0b42
--- /dev/null
+++ b/migrations/0003_noisy_raider.sql
@@ -0,0 +1 @@
+ALTER TABLE `Madamis` ADD `bought` integer NOT NULL;
\ No newline at end of file
diff --git a/migrations/meta/0003_snapshot.json b/migrations/meta/0003_snapshot.json
new file mode 100644
index 0000000..3383eb6
--- /dev/null
+++ b/migrations/meta/0003_snapshot.json
@@ -0,0 +1,206 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "bb029370-8595-4b6b-b547-cf137e8f8105",
+ "prevId": "f9cf0395-0599-44ce-9bf4-cf72af4fc42c",
+ "tables": {
+ "GameUsers": {
+ "name": "GameUsers",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "gm": {
+ "name": "gm",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "gameId": {
+ "name": "gameId",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "GameUsers_gameId_Games_id_fk": {
+ "name": "GameUsers_gameId_Games_id_fk",
+ "tableFrom": "GameUsers",
+ "tableTo": "Games",
+ "columnsFrom": [
+ "gameId"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ },
+ "GameUsers_userId_Users_id_fk": {
+ "name": "GameUsers_userId_Users_id_fk",
+ "tableFrom": "GameUsers",
+ "tableTo": "Users",
+ "columnsFrom": [
+ "userId"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "Games": {
+ "name": "Games",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "date": {
+ "name": "date",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "madamisId": {
+ "name": "madamisId",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "Games_madamisId_Madamis_id_fk": {
+ "name": "Games_madamisId_Madamis_id_fk",
+ "tableFrom": "Games",
+ "tableTo": "Madamis",
+ "columnsFrom": [
+ "madamisId"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "Madamis": {
+ "name": "Madamis",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "link": {
+ "name": "link",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "player": {
+ "name": "player",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "gmRequired": {
+ "name": "gmRequired",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bought": {
+ "name": "bought",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "Users": {
+ "name": "Users",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ }
+ },
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "indexes": {}
+ }
+}
\ No newline at end of file
diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json
index 6cc1e60..117ab0c 100644
--- a/migrations/meta/_journal.json
+++ b/migrations/meta/_journal.json
@@ -22,6 +22,13 @@
"when": 1724078667553,
"tag": "0002_bouncy_legion",
"breakpoints": true
+ },
+ {
+ "idx": 3,
+ "version": "6",
+ "when": 1724248328072,
+ "tag": "0003_noisy_raider",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/schema.ts b/schema.ts
index f08d3b9..8499090 100644
--- a/schema.ts
+++ b/schema.ts
@@ -7,6 +7,7 @@ export const madamis = sqliteTable("Madamis", {
link: text("link").notNull(),
player: integer("player").notNull(),
gmRequired: integer("gmRequired").notNull(),
+ bought: integer("bought").notNull(),
});
export const madamisRelations = relations(madamis, ({ many }) => ({
diff --git a/src/apis/madamis.ts b/src/apis/madamis.ts
index 0910064..4a3eb46 100644
--- a/src/apis/madamis.ts
+++ b/src/apis/madamis.ts
@@ -10,6 +10,7 @@ const madamisPostSchema = z.object({
link: z.string().url(),
player: z.number().int().min(1).max(6),
gmRequired: z.boolean().transform((b) => Number(b)),
+ bought: z.boolean().transform((b) => Number(b)),
});
const madamisPutSchema = madamisPostSchema.extend({
@@ -60,19 +61,15 @@ export const madamisApp = madamisApi
const db = drizzle(c.env.DB);
const body = c.req.valid("json");
- const [result] = await db.insert(madamis).values(body).returning();
- return c.json(result);
+ await db.insert(madamis).values(body);
+ return new Response(null, { status: 204 });
})
.put("/", zValidator("json", madamisPutSchema), async (c) => {
const db = drizzle(c.env.DB);
const body = c.req.valid("json");
- const [result] = await db
- .update(madamis)
- .set(body)
- .where(eq(madamis.id, body.id))
- .returning();
- return c.json(result);
+ await db.update(madamis).set(body).where(eq(madamis.id, body.id));
+ return new Response(null, { status: 204 });
})
.delete("/:id", async (c) => {
const db = drizzle(c.env.DB);
diff --git a/src/pages/components/MadamisList.tsx b/src/pages/components/MadamisList.tsx
index c845d81..32789e1 100644
--- a/src/pages/components/MadamisList.tsx
+++ b/src/pages/components/MadamisList.tsx
@@ -19,24 +19,22 @@ export const MadamisList = () => {
key={d.id}
w="20rem"
shadow="sm"
- padding="lg"
+ p="md"
radius="md"
withBorder
>
-
- }
- style={{
- borderRadius: "4px",
- }}
- />
-
+ }
+ style={{
+ borderRadius: "4px",
+ }}
+ />
GM: {d.gmRequired ? "要" : "レス可"}
@@ -62,7 +60,7 @@ export const MadamisList = () => {
))}
)}
-
+ {Boolean(d.bought) && }
))}
diff --git a/src/pages/components/MadamisModal.tsx b/src/pages/components/MadamisModal.tsx
index 18fd220..72aea86 100644
--- a/src/pages/components/MadamisModal.tsx
+++ b/src/pages/components/MadamisModal.tsx
@@ -23,6 +23,7 @@ const formSchema = z.object({
link: z.string().url(),
player: z.coerce.number().int().min(1).max(6),
gmRequired: z.boolean(),
+ bought: z.boolean(),
});
type FormSchema = z.infer;
@@ -109,6 +110,12 @@ export const MadamisModal = () => {
{...register("gmRequired")}
error={errors.gmRequired?.message}
/>
+