From d22be3f7443a886f8396e320127ba1c4eba29e13 Mon Sep 17 00:00:00 2001 From: toririm Date: Sat, 21 Sep 2024 03:35:40 +0900 Subject: [PATCH 1/7] =?UTF-8?q?assignee=E3=82=92item=E3=81=8C=E6=8C=81?= =?UTF-8?q?=E3=81=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/item.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/item.ts b/app/models/item.ts index 6acbd573..7ee88806 100644 --- a/app/models/item.ts +++ b/app/models/item.ts @@ -11,6 +11,7 @@ export const itemSchema = z.object({ required_error: "種類が未選択です", invalid_type_error: "不正な種類です", }), + assignee: z.string().nullable(), }); export type Item = z.infer; @@ -33,10 +34,11 @@ export class ItemEntity implements Item { public readonly name: string, public readonly price: number, public readonly type: ItemType, + public assignee: string | null = null, ) {} static createNew({ name, price, type }: Item): ItemEntity { - return new ItemEntity(undefined, name, price, type); + return new ItemEntity(undefined, name, price, type, null); } static fromItem(item: WithId): WithId { From 8bc71e6ceab0d3185812f34e501d8250cf5345d2 Mon Sep 17 00:00:00 2001 From: toririm Date: Sat, 21 Sep 2024 03:42:01 +0900 Subject: [PATCH 2/7] =?UTF-8?q?order=E3=82=82=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/order.ts | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/app/models/order.ts b/app/models/order.ts index 6ffc339c..48d9d50c 100644 --- a/app/models/order.ts +++ b/app/models/order.ts @@ -8,7 +8,6 @@ export const orderSchema = z.object({ createdAt: z.date(), servedAt: z.date().nullable(), items: z.array(itemSchema.required()), - assignee: z.string().nullable(), total: z.number(), orderReady: z.boolean(), }); @@ -23,22 +22,12 @@ export class OrderEntity implements Order { private readonly _createdAt: Date, private _servedAt: Date | null, private _items: WithId[], - private _assignee: string | null, private _total: number, private _orderReady: boolean, ) {} static createNew({ orderId }: { orderId: number }): OrderEntity { - return new OrderEntity( - undefined, - orderId, - new Date(), - null, - [], - null, - 0, - false, - ); + return new OrderEntity(undefined, orderId, new Date(), null, [], 0, false); } static fromOrder(order: WithId): WithId { @@ -48,7 +37,6 @@ export class OrderEntity implements Order { order.createdAt, order.servedAt, order.items, - order.assignee, order.total, order.orderReady, ) as WithId; @@ -81,13 +69,6 @@ export class OrderEntity implements Order { this._items = items; } - get assignee() { - return this._assignee; - } - set assignee(assignee: string | null) { - this._assignee = assignee; - } - get total() { // items の更新に合わせて total を自動で計算する // その代わり total は直接更新できない @@ -121,7 +102,6 @@ export class OrderEntity implements Order { createdAt: this.createdAt, servedAt: this.servedAt, items: this.items, - assignee: this.assignee, total: this.total, orderReady: this.orderReady, }; From a6bdc04423198a39562d9b02f1caac39918a37e0 Mon Sep 17 00:00:00 2001 From: toririm Date: Mon, 23 Sep 2024 21:56:08 +0900 Subject: [PATCH 3/7] fix: test --- app/models/item.ts | 2 +- app/models/order.test.ts | 3 +++ app/repositories/item.test.ts | 2 ++ app/repositories/order.test.ts | 20 +++++++++++++------- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/models/item.ts b/app/models/item.ts index 7ee88806..832a88ad 100644 --- a/app/models/item.ts +++ b/app/models/item.ts @@ -37,7 +37,7 @@ export class ItemEntity implements Item { public assignee: string | null = null, ) {} - static createNew({ name, price, type }: Item): ItemEntity { + static createNew({ name, price, type }: Omit): ItemEntity { return new ItemEntity(undefined, name, price, type, null); } diff --git a/app/models/order.test.ts b/app/models/order.test.ts index 095c3869..be3969e3 100644 --- a/app/models/order.test.ts +++ b/app/models/order.test.ts @@ -18,12 +18,14 @@ describe("[unit] order entity", () => { name: "item1", price: 100, type: "hot", + assignee: null, }, { id: "2", name: "item2", price: 341, type: "ice", + assignee: null, }, ]; order.items.push(...items); @@ -34,6 +36,7 @@ describe("[unit] order entity", () => { name: "item3", price: 100, type: "ore", + assignee: null, }); expect(order.total).toBe(541); }); diff --git a/app/repositories/item.test.ts b/app/repositories/item.test.ts index a2654227..17cd9592 100644 --- a/app/repositories/item.test.ts +++ b/app/repositories/item.test.ts @@ -43,8 +43,10 @@ describe("[db] itemRepository", async () => { }); test("itemRepository.save (update)", async () => { + savedItemHoge.assignee = "toririm"; const savedItem = await itemRepository.save(savedItemHoge); expect(savedItem.id).toEqual(savedItemHoge.id); + expect(savedItem.assignee).toEqual("toririm"); }); test("itemRepository.findById", async () => { diff --git a/app/repositories/order.test.ts b/app/repositories/order.test.ts index 25a6962e..a22cf273 100644 --- a/app/repositories/order.test.ts +++ b/app/repositories/order.test.ts @@ -21,7 +21,7 @@ const isEmulatorRunning = async (): Promise => { describe("[db] orderRepository", async () => { // To use this environment, firebase emulator must be running. - let savedOrderHoge: WithId; + let savedOrderChange: WithId; let orderRepository: OrderRepository; beforeAll(async () => { @@ -47,15 +47,21 @@ describe("[db] orderRepository", async () => { test("orderRepository.save (create)", async () => { const order = OrderEntity.createNew({ orderId: 2024 }); - savedOrderHoge = await orderRepository.save(order); - expect(savedOrderHoge.id).toBeDefined(); + savedOrderChange = await orderRepository.save(order); + expect(savedOrderChange.id).toBeDefined(); }); test("orderRepository.save (update)", async () => { - savedOrderHoge.assignee = "hoge"; - const savedOrder = await orderRepository.save(savedOrderHoge); - expect(savedOrder.id).toEqual(savedOrderHoge.id); - expect(savedOrder.assignee).toEqual("hoge"); + savedOrderChange.items.push({ + id: "1", + name: "item1", + price: 100, + type: "hot", + assignee: null, + }); + const savedOrder = await orderRepository.save(savedOrderChange); + expect(savedOrder.id).toEqual(savedOrderChange.id); + expect(savedOrder.items).toEqual(savedOrderChange.items); }); test("orderRepository.findById", async () => { From fd4b153cf6ddb65d6ac9c3e8f7b76f93d5ef321f Mon Sep 17 00:00:00 2001 From: toririm Date: Mon, 23 Sep 2024 22:10:24 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E3=81=94=E3=82=81=E3=82=93=E3=82=A2?= =?UTF-8?q?=E3=82=B9=E3=82=BF=E3=83=AB=EF=BC=81=EF=BC=81=E4=B8=80=E6=97=A6?= =?UTF-8?q?=E6=B6=88=E3=81=99=E3=81=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routes/_header.casher.tsx | 253 ---------------------------------- 1 file changed, 253 deletions(-) delete mode 100644 app/routes/_header.casher.tsx diff --git a/app/routes/_header.casher.tsx b/app/routes/_header.casher.tsx deleted file mode 100644 index ccd71888..00000000 --- a/app/routes/_header.casher.tsx +++ /dev/null @@ -1,253 +0,0 @@ -import { parseWithZod } from "@conform-to/zod"; -import { AlertDialogCancel } from "@radix-ui/react-alert-dialog"; -import { TrashIcon } from "@radix-ui/react-icons"; -import { type ClientActionFunction, json } from "@remix-run/react"; -import { useState } from "react"; -import useSWRSubscription from "swr/subscription"; -import { - AlertDialog, - AlertDialogAction, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, - AlertDialogTrigger, -} from "~/components/ui/alert-dialog"; -import { Button } from "~/components/ui/button"; -import { Input } from "~/components/ui/input"; -import { - Table, - TableBody, - TableCaption, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "~/components/ui/table"; -import { itemConverter } from "~/firebase/converter"; -import { collectionSub } from "~/firebase/subscription"; -import type { WithId } from "~/lib/typeguard"; -import { type Item, type ItemType, itemSchema } from "~/models/item"; -import type { Order } from "~/models/order"; -import { itemRepository } from "~/repositories/item"; - -const mockOrder: Order = { - orderId: 1, - createdAt: new Date(), - servedAt: null, - items: [ - // { - // id: "1", - // type: "ice", - // name: "珈琲・俺ブレンド", - // price: 300, - // }, - ], - assignee: "1st", - total: 0, - orderReady: false, -}; - -export default function Casher() { - // const total = mockOrder.items.reduce((acc, cur) => acc + cur.price, 0); - const { data: items } = useSWRSubscription( - "items", - collectionSub({ converter: itemConverter }), - ); - const [recieved, setText] = useState(0); - const [total, setTotal] = useState(0); - const [queue, setQueue] = useState[]>([]); - - // console.log(mockOrder); - // console.log(items?.[0]); - return ( -
-
-
-
- {items?.map((item) => ( -
- -
- ))} -
-
-
-
- - - - - - No. {mockOrder.orderId} - - - - - {queue?.map((item) => ( - - -
{item.name}
- -
-
- ))} -
-
-
    -
  • -

    合計金額:{total} 円

    - {/*

    {mockOrder.reduce}

    */} -
  • -
  • - {/*

    受領金額:

    */} -
    - {/* setText(parseInt(event.target.value))} - /> */} - - - - - - - - 金額を確認してください - - - {/*

    受領額: {recieved} 円

    */} -

    - 受領額: - - setText(Number.parseInt(event.target.value)) - } - /> -

    -

    合計: {mockOrder.total} 円

    -

    - お釣り: {recieved - mockOrder.total < 0 && 0} - {recieved - mockOrder.total >= 0 && - recieved - mockOrder.total}{" "} - 円 -

    -
    -
    - - - 戻る - - mockOrderInitialize()} - > - 送信 - - -
    -
    -
    -
  • -
-
-
-
-
- ); -} - -export const clientAction: ClientActionFunction = async ({ request }) => { - const formData = await request.formData(); - const submission = parseWithZod(formData, { schema: itemSchema }); - - if (submission.status !== "success") { - return json(submission.reply()); - } - - const newItem = submission.value; - // あとでマシなエラーハンドリングにする - const savedItem = await itemRepository.save(ItemEntity.createNew(newItem)); - - console.log("Document written with ID: ", savedItem.id); - return new Response(null, { status: 204 }); -}; - -function trashIcon() { - return ( -
- -
- ); -} - -function mockOrderInitialize() { - mockOrder.items = []; - mockOrder.total = 0; - console.log(mockOrder); -} - -export class ItemEntity implements Item { - // TODO(toririm) - // ゲッターやセッターを使う際にはすべてのプロパティにアンスコをつけてprivateにする - // 実装の詳細は OrderEntity を参照 - private constructor( - public readonly id: string | undefined, - public readonly name: string, - public readonly price: number, - public readonly type: ItemType, - ) {} - - static createNew({ name, price, type }: Item): ItemEntity { - return new ItemEntity(undefined, name, price, type); - } - - static fromItem(item: WithId): WithId { - return new ItemEntity( - item.id, - item.name, - item.price, - item.type, - ) as WithId; - } -} From e0faad964cc02e24337e119dfdc862344ac651cb Mon Sep 17 00:00:00 2001 From: toririm Date: Mon, 23 Sep 2024 22:14:23 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[=E3=82=B9=E3=82=AD=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3]=20=E5=82=99=E8=80=83=E6=AC=84=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=20close=20#141?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/order.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/order.ts b/app/models/order.ts index 48d9d50c..0c7a894e 100644 --- a/app/models/order.ts +++ b/app/models/order.ts @@ -10,6 +10,7 @@ export const orderSchema = z.object({ items: z.array(itemSchema.required()), total: z.number(), orderReady: z.boolean(), + description: z.string(), }); export type Order = z.infer; @@ -24,10 +25,20 @@ export class OrderEntity implements Order { private _items: WithId[], private _total: number, private _orderReady: boolean, + private _description: string, ) {} static createNew({ orderId }: { orderId: number }): OrderEntity { - return new OrderEntity(undefined, orderId, new Date(), null, [], 0, false); + return new OrderEntity( + undefined, + orderId, + new Date(), + null, + [], + 0, + false, + "", + ); } static fromOrder(order: WithId): WithId { @@ -39,6 +50,7 @@ export class OrderEntity implements Order { order.items, order.total, order.orderReady, + order.description, ) as WithId; } @@ -81,6 +93,13 @@ export class OrderEntity implements Order { return this._orderReady; } + get description() { + return this._description; + } + set description(description: string) { + this._description = description; + } + // -------------------------------------------------- // methods // -------------------------------------------------- @@ -104,6 +123,7 @@ export class OrderEntity implements Order { items: this.items, total: this.total, orderReady: this.orderReady, + description: this.description, }; } } From e02ac2a221bae13c07b26b84680fdfc7c677cda8 Mon Sep 17 00:00:00 2001 From: toririm Date: Mon, 23 Sep 2024 22:17:49 +0900 Subject: [PATCH 6/7] =?UTF-8?q?Revert=20"=E3=81=94=E3=82=81=E3=82=93?= =?UTF-8?q?=E3=82=A2=E3=82=B9=E3=82=BF=E3=83=AB=EF=BC=81=EF=BC=81=E4=B8=80?= =?UTF-8?q?=E6=97=A6=E6=B6=88=E3=81=99=E3=81=AD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fd4b153cf6ddb65d6ac9c3e8f7b76f93d5ef321f. --- app/routes/_header.casher.tsx | 253 ++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 app/routes/_header.casher.tsx diff --git a/app/routes/_header.casher.tsx b/app/routes/_header.casher.tsx new file mode 100644 index 00000000..ccd71888 --- /dev/null +++ b/app/routes/_header.casher.tsx @@ -0,0 +1,253 @@ +import { parseWithZod } from "@conform-to/zod"; +import { AlertDialogCancel } from "@radix-ui/react-alert-dialog"; +import { TrashIcon } from "@radix-ui/react-icons"; +import { type ClientActionFunction, json } from "@remix-run/react"; +import { useState } from "react"; +import useSWRSubscription from "swr/subscription"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "~/components/ui/alert-dialog"; +import { Button } from "~/components/ui/button"; +import { Input } from "~/components/ui/input"; +import { + Table, + TableBody, + TableCaption, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "~/components/ui/table"; +import { itemConverter } from "~/firebase/converter"; +import { collectionSub } from "~/firebase/subscription"; +import type { WithId } from "~/lib/typeguard"; +import { type Item, type ItemType, itemSchema } from "~/models/item"; +import type { Order } from "~/models/order"; +import { itemRepository } from "~/repositories/item"; + +const mockOrder: Order = { + orderId: 1, + createdAt: new Date(), + servedAt: null, + items: [ + // { + // id: "1", + // type: "ice", + // name: "珈琲・俺ブレンド", + // price: 300, + // }, + ], + assignee: "1st", + total: 0, + orderReady: false, +}; + +export default function Casher() { + // const total = mockOrder.items.reduce((acc, cur) => acc + cur.price, 0); + const { data: items } = useSWRSubscription( + "items", + collectionSub({ converter: itemConverter }), + ); + const [recieved, setText] = useState(0); + const [total, setTotal] = useState(0); + const [queue, setQueue] = useState[]>([]); + + // console.log(mockOrder); + // console.log(items?.[0]); + return ( +
+
+
+
+ {items?.map((item) => ( +
+ +
+ ))} +
+
+
+
+ + + + + + No. {mockOrder.orderId} + + + + + {queue?.map((item) => ( + + +
{item.name}
+ +
+
+ ))} +
+
+
    +
  • +

    合計金額:{total} 円

    + {/*

    {mockOrder.reduce}

    */} +
  • +
  • + {/*

    受領金額:

    */} +
    + {/* setText(parseInt(event.target.value))} + /> */} + + + + + + + + 金額を確認してください + + + {/*

    受領額: {recieved} 円

    */} +

    + 受領額: + + setText(Number.parseInt(event.target.value)) + } + /> +

    +

    合計: {mockOrder.total} 円

    +

    + お釣り: {recieved - mockOrder.total < 0 && 0} + {recieved - mockOrder.total >= 0 && + recieved - mockOrder.total}{" "} + 円 +

    +
    +
    + + + 戻る + + mockOrderInitialize()} + > + 送信 + + +
    +
    +
    +
  • +
+
+
+
+
+ ); +} + +export const clientAction: ClientActionFunction = async ({ request }) => { + const formData = await request.formData(); + const submission = parseWithZod(formData, { schema: itemSchema }); + + if (submission.status !== "success") { + return json(submission.reply()); + } + + const newItem = submission.value; + // あとでマシなエラーハンドリングにする + const savedItem = await itemRepository.save(ItemEntity.createNew(newItem)); + + console.log("Document written with ID: ", savedItem.id); + return new Response(null, { status: 204 }); +}; + +function trashIcon() { + return ( +
+ +
+ ); +} + +function mockOrderInitialize() { + mockOrder.items = []; + mockOrder.total = 0; + console.log(mockOrder); +} + +export class ItemEntity implements Item { + // TODO(toririm) + // ゲッターやセッターを使う際にはすべてのプロパティにアンスコをつけてprivateにする + // 実装の詳細は OrderEntity を参照 + private constructor( + public readonly id: string | undefined, + public readonly name: string, + public readonly price: number, + public readonly type: ItemType, + ) {} + + static createNew({ name, price, type }: Item): ItemEntity { + return new ItemEntity(undefined, name, price, type); + } + + static fromItem(item: WithId): WithId { + return new ItemEntity( + item.id, + item.name, + item.price, + item.type, + ) as WithId; + } +} From 41fea1b0c9c2068f57c5b043ec8ef3bf230e8855 Mon Sep 17 00:00:00 2001 From: toririm Date: Mon, 23 Sep 2024 22:25:56 +0900 Subject: [PATCH 7/7] fix --- app/models/item.ts | 3 ++- app/routes/_header.casher.tsx | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/models/item.ts b/app/models/item.ts index 832a88ad..be59053f 100644 --- a/app/models/item.ts +++ b/app/models/item.ts @@ -34,7 +34,7 @@ export class ItemEntity implements Item { public readonly name: string, public readonly price: number, public readonly type: ItemType, - public assignee: string | null = null, + public assignee: string | null, ) {} static createNew({ name, price, type }: Omit): ItemEntity { @@ -47,6 +47,7 @@ export class ItemEntity implements Item { item.name, item.price, item.type, + item.assignee, ) as WithId; } } diff --git a/app/routes/_header.casher.tsx b/app/routes/_header.casher.tsx index ccd71888..9d8e6e8c 100644 --- a/app/routes/_header.casher.tsx +++ b/app/routes/_header.casher.tsx @@ -44,9 +44,9 @@ const mockOrder: Order = { // price: 300, // }, ], - assignee: "1st", total: 0, orderReady: false, + description: "", }; export default function Casher() { @@ -207,7 +207,13 @@ export const clientAction: ClientActionFunction = async ({ request }) => { const newItem = submission.value; // あとでマシなエラーハンドリングにする - const savedItem = await itemRepository.save(ItemEntity.createNew(newItem)); + const savedItem = await itemRepository.save( + ItemEntity.createNew({ + name: newItem.name, + price: newItem.price, + type: newItem.type, + }), + ); console.log("Document written with ID: ", savedItem.id); return new Response(null, { status: 204 }); @@ -236,10 +242,11 @@ export class ItemEntity implements Item { public readonly name: string, public readonly price: number, public readonly type: ItemType, + public assignee: string | null, ) {} - static createNew({ name, price, type }: Item): ItemEntity { - return new ItemEntity(undefined, name, price, type); + static createNew({ name, price, type }: Omit): ItemEntity { + return new ItemEntity(undefined, name, price, type, null); } static fromItem(item: WithId): WithId { @@ -248,6 +255,7 @@ export class ItemEntity implements Item { item.name, item.price, item.type, + item.assignee, ) as WithId; } }