Compare commits
13 Commits
17f8f18574
...
staging
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ea83b66f7 | |||
| 311f55e68e | |||
| 72f073fad6 | |||
| c1bbbd7d8c | |||
| 1bf12c7fb3 | |||
| 7db1f2dcf2 | |||
| b408570fdf | |||
| 1b695e44f2 | |||
| 9088b1f479 | |||
| f15b8683a6 | |||
| 2f818c34b0 | |||
| 6cdce103a5 | |||
| 3382c0ef4e |
24
.gitea/workflows/workflow.yaml
Normal file
24
.gitea/workflows/workflow.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
name: ordr deploy
|
||||
run-name: ${{ gitea.actor }} is deploying ordr
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- staging
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Create SSH key
|
||||
run: |
|
||||
mkdir -p ~/.ssh/
|
||||
echo "$SSH_PRIVATE_KEY" > ~/private.key
|
||||
sudo chmod 600 ~/private.key
|
||||
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
||||
shell: bash
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}}
|
||||
SSH_KNOWN_HOSTS: ${{secrets.SSH_KNOWN_HOSTS}}
|
||||
- name: Up the services
|
||||
run: |
|
||||
ssh -i ~/private.key ada@conway.engineer "cd /home/shared/ordr/ordr && git pull && cd .. && echo ${{secrets.SSH_PASSWORD}} | sudo -S docker compose down && echo ${{secrets.SSH_PASSWORD}} | sudo -S docker compose up --build --force-recreate --detach"
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -18,4 +18,9 @@
|
||||
*.tmp
|
||||
|
||||
# dotenv
|
||||
.env
|
||||
.env
|
||||
.env.local
|
||||
|
||||
ordr-api
|
||||
|
||||
./nohup.out
|
||||
31
api/Dockerfile
Normal file
31
api/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
# Stage 1: Build the application
|
||||
FROM golang:1.25.3-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go.mod and go.sum first to leverage Docker's caching
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy the rest of the application source code
|
||||
COPY . .
|
||||
|
||||
# Build the Go application
|
||||
# CGO_ENABLED=0 disables Cgo for a fully static binary
|
||||
# -a links all packages statically
|
||||
# -installsuffix cgo_non_shared avoids issues with shared libraries
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo_non_shared -o main .
|
||||
|
||||
# Stage 2: Create the final lean image
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the built binary from the builder stage
|
||||
COPY --from=builder /app/main .
|
||||
|
||||
# Expose the port your Gin application listens on (e.g., 8080)
|
||||
EXPOSE 8080
|
||||
|
||||
# Command to run the application
|
||||
CMD ["./ordr-api"]
|
||||
BIN
api/__debug_bin2336935653
Executable file
BIN
api/__debug_bin2336935653
Executable file
Binary file not shown.
BIN
api/ordr-api
BIN
api/ordr-api
Binary file not shown.
7
ordr-ui/.dockerignore
Normal file
7
ordr-ui/.dockerignore
Normal file
@@ -0,0 +1,7 @@
|
||||
.git
|
||||
.next
|
||||
node_modules
|
||||
npm-debug.log
|
||||
Dockerfile
|
||||
docker-compose.yml
|
||||
README.md
|
||||
65
ordr-ui/Dockerfile
Normal file
65
ordr-ui/Dockerfile
Normal file
@@ -0,0 +1,65 @@
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
# Install dependencies only when needed
|
||||
FROM base AS deps
|
||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
# Install dependencies based on the preferred package manager
|
||||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
|
||||
RUN \
|
||||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||
elif [ -f package-lock.json ]; then npm ci; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||
else npm install --force; \
|
||||
fi
|
||||
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Next.js collects completely anonymous telemetry data about general usage.
|
||||
# Learn more here: https://nextjs.org/telemetry
|
||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||
# ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN \
|
||||
if [ -f yarn.lock ]; then yarn run build; \
|
||||
elif [ -f package-lock.json ]; then npm run build; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||
# ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT=3000
|
||||
|
||||
# server.js is created by next build from the standalone output
|
||||
# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
CMD ["node", "server.js"]
|
||||
@@ -25,16 +25,15 @@ export const CreateItem = async (query: CreateItemQuery): Promise<ItemPriceRespo
|
||||
return res.data
|
||||
}
|
||||
|
||||
export const SetItemPrice = async (query: SetItemPriceQuery) => {
|
||||
export const SetItemPrice = async (query: SetItemPriceQuery): Promise<ItemPriceResponse> => {
|
||||
const queryParams = new URLSearchParams({
|
||||
item_id: query.item_id,
|
||||
item_price: query.item_price
|
||||
})
|
||||
|
||||
const res = await axios.put(process.env.NEXT_PUBLIC_API_URL + `/item/price?${queryParams.toString()}`, {}, {withCredentials: true})
|
||||
if (res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
return res.data as ItemPriceResponse
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Mutex } from "async-mutex"
|
||||
import { useState } from "react"
|
||||
import styled from "styled-components"
|
||||
import useAsyncEffect from "use-async-effect"
|
||||
import { GetItemHistory } from "../client/controllers"
|
||||
import { ItemHistoryResponse } from "../client/response"
|
||||
import { useItemStore } from "../providers/ItemsProvider"
|
||||
|
||||
type ItemHistoryTableProps = {
|
||||
itemId: number
|
||||
@@ -39,17 +37,15 @@ const ItemHistoryTableRow = styled.tr`
|
||||
const itemHistoryMutex = new Mutex()
|
||||
|
||||
export const ItemHistoryTable = ({itemId}: ItemHistoryTableProps) => {
|
||||
const [itemPriceHistory, setItemPriceHistory] = useState<ItemHistoryResponse[]>([])
|
||||
const itemStore = useItemStore((state) => state)
|
||||
|
||||
useAsyncEffect(async () => {
|
||||
if(itemPriceHistory.length === 0) {
|
||||
if(itemStore.itemHistories.filter((ih) => parseInt(ih.ItemId) === itemId).length === 0) {
|
||||
const release = await itemHistoryMutex.acquire()
|
||||
setItemPriceHistory(await GetItemHistory(itemId))
|
||||
await itemStore.getItemHistory(itemId)
|
||||
await release()
|
||||
}
|
||||
}, [])
|
||||
|
||||
console.log(itemPriceHistory)
|
||||
}, [itemStore.itemHistories])
|
||||
|
||||
return (
|
||||
<ItemHistoryTableStyle>
|
||||
@@ -70,7 +66,7 @@ export const ItemHistoryTable = ({itemId}: ItemHistoryTableProps) => {
|
||||
</tr>
|
||||
</ItemHistoryTableHead>
|
||||
<ItemHistoryTableBody>
|
||||
{itemPriceHistory.map((iph) => (
|
||||
{itemStore.itemHistories.filter((ih) => parseInt(ih.ItemId) === itemId).map((iph) => (
|
||||
<ItemHistoryTableRow key = {iph.ItemId + new Date(iph.ValidFrom).getMilliseconds()}>
|
||||
<ItemHistoryTableItem>
|
||||
{iph.ItemName}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
'use client'
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useEffect } from "react"
|
||||
import { useAsyncEffect } from 'use-async-effect'
|
||||
import { useShallow } from 'zustand/react/shallow'
|
||||
import { UserResponse } from './client/response'
|
||||
import { useCurrentAuthenticatedUserStore, UserActions } from './providers'
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export default function Home() {
|
||||
const authenticatedUserStore: UserResponse & UserActions = useCurrentAuthenticatedUserStore(useShallow((state) => ({
|
||||
|
||||
@@ -2,11 +2,12 @@ import { create } from 'zustand'
|
||||
import * as ItemController from '../client/controllers/ItemController'
|
||||
import { CreateItemQuery } from '../client/queries/CreateItemQuery'
|
||||
import { SetItemPriceQuery } from '../client/queries/SetItemPriceQuery'
|
||||
import { ItemPriceResponse, OrderFilledResponse, OrderItemPriceResponse } from '../client/response'
|
||||
import { ItemHistoryResponse, ItemPriceResponse, OrderFilledResponse, OrderItemPriceResponse } from '../client/response'
|
||||
|
||||
export type ItemData = {
|
||||
items: ItemPriceResponse[],
|
||||
orderItems: OrderItemPriceResponse[]
|
||||
itemHistories: ItemHistoryResponse[]
|
||||
}
|
||||
|
||||
export type ItemActions = {
|
||||
@@ -20,11 +21,13 @@ export type ItemActions = {
|
||||
setItemQuantity: (orderId: number, itemId: number, quantity: number) => Promise<OrderFilledResponse>
|
||||
deleteOrderItem: (orderId: number, itemId: number) => Promise<void>
|
||||
deleteItem: (itemId: number) => Promise<void>
|
||||
getItemHistory: (itemId: number) => Promise<ItemHistoryResponse[]>
|
||||
}
|
||||
|
||||
export const useItemStore = create<ItemData & ItemActions>((set, get) => ({
|
||||
items: [],
|
||||
orderItems: [],
|
||||
itemHistories: [],
|
||||
sync: async (): Promise<void> => {
|
||||
const itemPrices = await ItemController.GetItems()
|
||||
set((state) => ({
|
||||
@@ -52,7 +55,7 @@ export const useItemStore = create<ItemData & ItemActions>((set, get) => ({
|
||||
item_price: price.toString()
|
||||
}
|
||||
|
||||
await ItemController.SetItemPrice(itemPriceQuery)
|
||||
const itemPrice = await ItemController.SetItemPrice(itemPriceQuery)
|
||||
|
||||
set((state) => {
|
||||
const item = state.items.filter((i) => i.ItemId === itemId)[0]
|
||||
@@ -68,7 +71,14 @@ export const useItemStore = create<ItemData & ItemActions>((set, get) => ({
|
||||
if(!a.InSeason && b.InSeason)
|
||||
return -1
|
||||
return a.ItemId - b.ItemId
|
||||
})
|
||||
}),
|
||||
itemHistories: [...state.itemHistories, {
|
||||
ItemId: itemPrice.ItemId.toString(),
|
||||
ItemName: itemPrice.ItemName,
|
||||
ItemPrice: (Math.trunc(itemPrice.ItemPrice * 100) / 100).toString(),
|
||||
ValidFrom: new Date().toLocaleDateString(),
|
||||
ValidTo: new Date().toLocaleDateString()
|
||||
} as ItemHistoryResponse]
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -151,7 +161,7 @@ export const useItemStore = create<ItemData & ItemActions>((set, get) => ({
|
||||
const orderItem = state.orderItems.filter((oi) => oi.ItemId === itemId && oi.OrderId === orderId)[0]
|
||||
const orderItemsWithoutOrderItem = state.orderItems.filter((oi) => oi.ItemId !== itemId || oi.OrderId !== orderId)
|
||||
|
||||
orderItem.Quantity = quantity
|
||||
orderItem.Quantity= quantity
|
||||
|
||||
return {
|
||||
...state,
|
||||
@@ -183,5 +193,18 @@ export const useItemStore = create<ItemData & ItemActions>((set, get) => ({
|
||||
orderItems: orderItemsWithoutItem
|
||||
}
|
||||
})
|
||||
},
|
||||
getItemHistory: async (itemId: number): Promise<ItemHistoryResponse[]> => {
|
||||
const currHist = get().itemHistories.filter((ih) => parseInt(ih.ItemId) === itemId)
|
||||
if(currHist.length > 0)
|
||||
return currHist
|
||||
const itemHistory = await ItemController.GetItemHistory(itemId)
|
||||
|
||||
set((state) => ({
|
||||
...state,
|
||||
itemHistories: [...state.itemHistories, ...itemHistory]
|
||||
}))
|
||||
|
||||
return itemHistory
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
};
|
||||
output: 'standalone',
|
||||
// other configurations
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
|
||||
86
ordr-ui/nohup.out
Normal file
86
ordr-ui/nohup.out
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
> ordr-ui@0.1.0 start
|
||||
> next start
|
||||
|
||||
▲ Next.js 16.0.3
|
||||
- Local: http://localhost:3000
|
||||
- Network: http://49.12.213.49:3000
|
||||
|
||||
✓ Starting...
|
||||
✓ Ready in 439ms
|
||||
|
||||
> ordr-ui@0.1.0 start
|
||||
> next start
|
||||
|
||||
▲ Next.js 16.0.3
|
||||
- Local: http://localhost:3000
|
||||
- Network: http://49.12.213.49:3000
|
||||
|
||||
✓ Starting...
|
||||
✓ Ready in 416ms
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
{
|
||||
Id: -1,
|
||||
Name: '',
|
||||
JobPosition: '',
|
||||
Active: false,
|
||||
Admin: false,
|
||||
sync: [AsyncFunction: sync],
|
||||
updateName: [AsyncFunction: updateName]
|
||||
}
|
||||
[]
|
||||
0
|
||||
{
|
||||
Id: -1,
|
||||
Name: '',
|
||||
JobPosition: '',
|
||||
Active: false,
|
||||
Admin: false,
|
||||
sync: [AsyncFunction: sync],
|
||||
updateName: [AsyncFunction: updateName]
|
||||
}
|
||||
[]
|
||||
0
|
||||
0
|
||||
0
|
||||
{
|
||||
Id: -1,
|
||||
Name: '',
|
||||
JobPosition: '',
|
||||
Active: false,
|
||||
Admin: false,
|
||||
sync: [AsyncFunction: sync],
|
||||
updateName: [AsyncFunction: updateName]
|
||||
}
|
||||
[]
|
||||
0
|
||||
0
|
||||
{
|
||||
Id: -1,
|
||||
Name: '',
|
||||
JobPosition: '',
|
||||
Active: false,
|
||||
Admin: false,
|
||||
sync: [AsyncFunction: sync],
|
||||
updateName: [AsyncFunction: updateName]
|
||||
}
|
||||
[]
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
{
|
||||
Id: -1,
|
||||
Name: '',
|
||||
JobPosition: '',
|
||||
Active: false,
|
||||
Admin: false,
|
||||
sync: [AsyncFunction: sync],
|
||||
updateName: [AsyncFunction: updateName]
|
||||
}
|
||||
[]
|
||||
Reference in New Issue
Block a user