Skip to content

Commit

Permalink
Merge branch 'main' into feature/deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
sou1118 authored Nov 17, 2024
2 parents 91273b1 + 1aa638d commit 99e1b32
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 60 deletions.
32 changes: 24 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,40 @@ WORKDIR /app
COPY --chown=appuser:appuser .tool-versions ./
RUN . ~/.bashrc && mise install

FROM base AS builder
FROM base AS prod-deps
WORKDIR /app
USER root
RUN mkdir /app/node_modules && chown -R appuser:appuser /app
USER appuser
COPY --chown=appuser:appuser package.json bun.lockb ./
RUN bun install --frozen-lockfile --verbose
COPY --chown=appuser:appuser prisma ./prisma
RUN bun install --frozen-lockfile --production && \
bun prisma generate
USER root
RUN mkdir -p /tmp/prod-deps && \
cp -r node_modules /tmp/prod-deps/ && \
chown -R 65532:65532 /tmp/prod-deps

FROM base AS deps
WORKDIR /app
USER root
RUN mkdir /app/node_modules && chown -R appuser:appuser /app
USER appuser
COPY --chown=appuser:appuser package.json bun.lockb ./
RUN bun install --frozen-lockfile

FROM deps AS builder
WORKDIR /app
USER appuser
COPY --chown=appuser:appuser . .
RUN bun prisma generate
ENV DATABASE_URL=file:/app/prisma/data/deploy.db
RUN mkdir -p prisma/data && \
touch prisma/data/deploy.db && \
bun prisma migrate deploy
RUN bun run build
bun prisma migrate deploy && \
bun run build
USER root
RUN bun install --frozen-lockfile --production && \
mkdir -p /tmp/prod/app && \
RUN mkdir -p /tmp/prod/app && \
cp -r build /tmp/prod/app/ && \
cp -r node_modules /tmp/prod/app/ && \
cp -r prisma /tmp/prod/app/ && \
cp package.json /tmp/prod/app/ && \
chown -R 65532:65532 /tmp/prod && \
Expand All @@ -47,6 +62,7 @@ RUN bun install --frozen-lockfile --production && \

FROM gcr.io/distroless/nodejs22-debian12:nonroot AS runner
WORKDIR /app
COPY --from=prod-deps /tmp/prod-deps/node_modules ./node_modules
COPY --from=builder /tmp/prod/app ./
ENV NODE_ENV=production \
DATABASE_URL=file:/app/prisma/data/deploy.db
Expand Down
45 changes: 45 additions & 0 deletions app/components/organisms/reception/Calculator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Box, Button, HStack, Text, VStack } from "@chakra-ui/react"
import { FC, memo } from "react"

export const Calculator: FC = memo(() => {
return (
<Box
w="300px"
h="250px"
bg="blackAlpha.500"
borderRadius="10px"
shadow="lg"
p={4}
>
<VStack>
<Text></Text>
<HStack>
<Button>7</Button>
<Button>8</Button>
<Button>9</Button>
<Button>*</Button>
</HStack>
<HStack>
<Button>4</Button>
<Button>5</Button>
<Button>6</Button>
<Button>-</Button>
</HStack>
<HStack>
<Button>1</Button>
<Button>2</Button>
<Button>3</Button>
<Button>+</Button>
</HStack>
<HStack>
<Button>0</Button>
<Button>T</Button>
<Button>C</Button>
<Button>=</Button>
</HStack>
</VStack>
</Box>
)
})

Calculator.displayName = "Calculator"
29 changes: 26 additions & 3 deletions app/components/organisms/reception/ReceptionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,42 @@ import { TypeProduct } from "~/type/typeproduct"
import PropTypes from "prop-types"

type Props = {
quantity?: number
product: TypeProduct
addOrder: (product: TypeProduct) => void
cancelOrder: (product: TypeProduct) => void
}

export const ReceptionCard: FC<Props> = memo((props) => {
const { product, addOrder, cancelOrder } = props
const { quantity = 0, product, addOrder, cancelOrder } = props

return (
<Box w="300px" h="250px" bg="white" borderRadius="10px" shadow="md" p={4}>
<Box
w="300px"
h="250px"
bg={
product.stock - quantity === 0
? "red.200"
: product.stock - quantity <= 10
? "red.100"
: "white"
}
borderRadius="10px"
shadow="md"
p={4}
>
<h1>ID:{product.product_id}</h1>
<Stack textAlign={"center"}>
<Text>{product.product_name}</Text>
<Text>価格:{product.price}</Text>
<Button onClick={() => addOrder(product)} colorScheme="blue">
<Text>在庫:{product.stock - quantity}</Text>
<Button
isDisabled={
quantity ? product.stock - quantity <= 0 : product.stock <= 0
}
onClick={() => addOrder(product)}
colorScheme="blue"
>
+
</Button>
<Button onClick={() => cancelOrder(product)} colorScheme="red">
Expand All @@ -32,10 +53,12 @@ export const ReceptionCard: FC<Props> = memo((props) => {
ReceptionCard.displayName = "ReceptionCard"

ReceptionCard.propTypes = {
quantity: PropTypes.number,
product: PropTypes.shape({
product_id: PropTypes.number.isRequired,
product_name: PropTypes.string.isRequired,
price: PropTypes.number.isRequired,
stock: PropTypes.number.isRequired,
}).isRequired,
addOrder: PropTypes.func.isRequired,
cancelOrder: PropTypes.func.isRequired,
Expand Down
4 changes: 3 additions & 1 deletion app/components/organisms/register/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export const ProductCard: FC<Props> = memo((props) => {
const { product, clickDelete, clickChange } = props

return (
<Box w="300px" h="250px" bg="white" borderRadius="10px" shadow="md" p={4}>
<Box w="300px" h="250px" bg={"white"} borderRadius="10px" shadow="md" p={4}>
<h1>ID:{product.product_id}</h1>
<Stack textAlign={"center"}>
<Text>{product.product_name}</Text>
<Text>価格:{product.price}</Text>
<Text>在庫:{product.stock}</Text>
<Button onClick={() => clickDelete(product)} colorScheme="red">
削除
</Button>
Expand All @@ -36,6 +37,7 @@ ProductCard.propTypes = {
product_id: PropTypes.number.isRequired,
product_name: PropTypes.string.isRequired,
price: PropTypes.number.isRequired,
stock: PropTypes.number.isRequired,
}).isRequired,
clickDelete: PropTypes.func.isRequired,
clickChange: PropTypes.func.isRequired,
Expand Down
18 changes: 18 additions & 0 deletions app/crud/crud_products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ const prisma = new PrismaClient()
export async function createProduct(data: {
product_name: string
price: number
stock: number
}) {
return await prisma.products.create({
data: {
product_name: data.product_name,
price: data.price,
stock: data.stock,
},
})
}
Expand All @@ -26,6 +28,7 @@ export async function updateProduct(
product_id: number,
product_name: string,
price: number,
stock: number,
) {
return await prisma.products.update({
where: {
Expand All @@ -34,10 +37,25 @@ export async function updateProduct(
data: {
product_name: product_name,
price: price,
stock: stock,
},
})
}

//在庫の変更
export async function updateStock(data: {
product_id: number
stock: number | undefined
num: number
}) {
return await prisma.products.update({
where: {
product_id: data.product_id,
},
data: { stock: data.stock ? data.stock - data.num : 0 },
})
}

//同じ商品名の商品が既に存在するか確認する
export async function existProduct(name: string) {
return await prisma.products.findFirst({
Expand Down
26 changes: 26 additions & 0 deletions app/routes/order_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ export default function OrderTable() {
<Thead>
<Tr>
<Th>ID</Th>
<Th>注文日時</Th>
<Th>テーブル番号</Th>
<Th>注文内容</Th>
<Th>売上</Th>
<Th>ステータス</Th>
</Tr>
</Thead>
Expand All @@ -61,10 +63,33 @@ export default function OrderTable() {
const quantities = filteredDetails.map(
(detail) => detail.quantity,
)
const totalPrice = filteredDetails.reduce(
(sum, detail) =>
sum +
detail.quantity *
products
.filter(
(product) => detail.product_id === product.product_id,
)
.reduce((sum, product) => sum + product.price, 0),
0,
)
const createTime = new Date(order.createTime).toLocaleString(
"ja-JP",
{
timeZone: "Asia/Tokyo",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
},
)

return (
<Tr key={order.order_id}>
<Td>{order.order_id}</Td>
<Td>{createTime}</Td>
<Td>{order.table_number}</Td>
<Td>
{productNames.map((name, index) => (
Expand All @@ -73,6 +98,7 @@ export default function OrderTable() {
</div>
))}
</Td>
<Td>{totalPrice}</Td>
<Td>{order.status}</Td>
</Tr>
)
Expand Down
Loading

0 comments on commit 99e1b32

Please sign in to comment.