mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-12 22:11:54 +00:00
Merge pull request #28 from Pup-Ion-Dev/add-barcode-field
Add barcode field
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using barkmanapi;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace barkmanapi.Migrations
|
||||
{
|
||||
[DbContext(typeof(BarkContext))]
|
||||
[Migration("20250203160519_add-barcodes")]
|
||||
partial class addbarcodes
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.1")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("barkmanapi.InventoryItems", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Barcode")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("barcode");
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("brand");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("notes");
|
||||
|
||||
b.Property<float?>("RentalPrice")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("rental_price");
|
||||
|
||||
b.Property<float?>("ReplacementCost")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("replacement_cost");
|
||||
|
||||
b.Property<string>("SerialNumber")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("serial_number");
|
||||
|
||||
b.Property<string>("StatusId")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("status_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_inventory");
|
||||
|
||||
b.HasIndex("StatusId")
|
||||
.HasDatabaseName("ix_inventory_status_id");
|
||||
|
||||
b.ToTable("inventory", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("barkmanapi.ItemStatus", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_item_status");
|
||||
|
||||
b.ToTable("item_status", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("barkmanapi.InventoryItems", b =>
|
||||
{
|
||||
b.HasOne("barkmanapi.ItemStatus", "Status")
|
||||
.WithMany()
|
||||
.HasForeignKey("StatusId")
|
||||
.HasConstraintName("fk_inventory_item_status_status_id");
|
||||
|
||||
b.Navigation("Status");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace barkmanapi.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class addbarcodes : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "barcode",
|
||||
table: "inventory",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "barcode",
|
||||
table: "inventory");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,10 @@ namespace barkmanapi.Migrations
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Barcode")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("barcode");
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
|
||||
@@ -48,7 +48,7 @@ var itemStatusGroup = app.MapGroup(prefix: "/itemstatus")
|
||||
.WithDescription("Endpoints for managing item status");
|
||||
|
||||
inventoryGroup.MapGet("", async (BarkContext db) =>
|
||||
await db.Inventory.OrderBy(item => item.Id).ToListAsync());
|
||||
await db.Inventory.OrderBy(item => item.Barcode).ToListAsync());
|
||||
|
||||
inventoryGroup.MapGet("/{id}", async (int id, BarkContext db) =>
|
||||
{
|
||||
@@ -73,9 +73,10 @@ inventoryGroup.MapPut("/{id}", async (int id, InventoryItems updatedItem, BarkCo
|
||||
}
|
||||
|
||||
existingItem.Name = updatedItem.Name;
|
||||
existingItem.Barcode = updatedItem.Barcode;
|
||||
existingItem.Brand = updatedItem.Brand;
|
||||
existingItem.SerialNumber = updatedItem.SerialNumber;
|
||||
existingItem.Status = updatedItem.Status;
|
||||
existingItem.StatusId = updatedItem.StatusId;
|
||||
existingItem.RentalPrice = updatedItem.RentalPrice;
|
||||
existingItem.ReplacementCost = updatedItem.ReplacementCost;
|
||||
existingItem.Notes = updatedItem.Notes;
|
||||
@@ -88,6 +89,7 @@ inventoryGroup.MapPost("", async (InventoryItems newItemInput, BarkContext db) =
|
||||
{
|
||||
var newItem = new InventoryItems();
|
||||
newItem.Name = newItemInput.Name;
|
||||
newItem.Barcode = newItemInput.Barcode;
|
||||
newItem.Brand = newItemInput.Brand;
|
||||
newItem.SerialNumber = newItemInput.SerialNumber;
|
||||
newItem.RentalPrice = newItemInput.RentalPrice;
|
||||
|
||||
@@ -10,7 +10,8 @@ public class BarkContext(DbContextOptions<BarkContext> options) : DbContext(opti
|
||||
|
||||
public class InventoryItems
|
||||
{
|
||||
public int Id {get; set;}
|
||||
public int Id {get; set;}
|
||||
public int Barcode {get; set;}
|
||||
public string Name { get; set; }
|
||||
public string Brand { get; set; }
|
||||
public string? SerialNumber { get; set; }
|
||||
|
||||
@@ -43,9 +43,9 @@ function App() {
|
||||
<Routes>
|
||||
<Route index element={<Home/>}/>
|
||||
<Route path="inventory" element={<InventoryList/>}/>
|
||||
<Route path="itemDetail/:itemId" element={<ItemDetail/>}/>
|
||||
<Route path="editItem/:itemId" element={<EditItem/>}/>
|
||||
<Route path="addItem" element={<AddItem/>}/>
|
||||
<Route path="inventory/itemDetail/:itemId" element={<ItemDetail/>}/>
|
||||
<Route path="inventory/editItem/:itemId" element={<EditItem/>}/>
|
||||
<Route path="inventory/addItem" element={<AddItem/>}/>
|
||||
</Routes>
|
||||
</>
|
||||
</QueryClientProvider>
|
||||
|
||||
@@ -2,17 +2,23 @@ import {Button, Group, TextInput, NumberInput, Container, Title, Flex} from '@ma
|
||||
import {useForm} from '@mantine/form';
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import {NewItem} from "./types.ts";
|
||||
import { useNavigate} from "react-router";
|
||||
import { IconX, IconCheck } from '@tabler/icons-react';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import {useNavigate} from "react-router";
|
||||
import {IconX, IconCheck} from '@tabler/icons-react';
|
||||
import {notifications} from '@mantine/notifications';
|
||||
import useInventoryList from "./hooks/useInventoryList.tsx";
|
||||
import {useEffect} from "react";
|
||||
|
||||
|
||||
function AddItem() {
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const inventoryQuery = useInventoryList();
|
||||
|
||||
const newItemForm = useForm<NewItem>({
|
||||
mode: 'uncontrolled',
|
||||
initialValues: {
|
||||
barcode: 0,
|
||||
name: "",
|
||||
brand: "",
|
||||
serialNumber: "",
|
||||
@@ -36,8 +42,8 @@ function AddItem() {
|
||||
|
||||
if (result.ok) {
|
||||
notifications.show({
|
||||
icon: <IconCheck size={20} />,
|
||||
color:"teal",
|
||||
icon: <IconCheck size={20}/>,
|
||||
color: "teal",
|
||||
title: "All good!",
|
||||
message: "Item Created",
|
||||
position: 'top-center',
|
||||
@@ -48,8 +54,8 @@ function AddItem() {
|
||||
|
||||
if (!result.ok) {
|
||||
notifications.show({
|
||||
icon: <IconX size={20} />,
|
||||
color:"red",
|
||||
icon: <IconX size={20}/>,
|
||||
color: "red",
|
||||
title: "Bummer!",
|
||||
message: "Something went wrong",
|
||||
position: 'top-center',
|
||||
@@ -57,9 +63,23 @@ function AddItem() {
|
||||
throw new Error('Failed to create inventory item');
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (inventoryQuery.data) {
|
||||
const nextBarcode = inventoryQuery.data[inventoryQuery.data.length - 1].barcode + 1;
|
||||
newItemForm.setValues({barcode: nextBarcode});
|
||||
}
|
||||
},[inventoryQuery.data]);
|
||||
|
||||
if (inventoryQuery.isPending) return 'Loading...'
|
||||
if (inventoryQuery.error) return 'An error has occurred: ' + inventoryQuery.error.message
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -74,7 +94,8 @@ function AddItem() {
|
||||
wrap="wrap">
|
||||
|
||||
<Title order={1}>Add Item</Title>
|
||||
|
||||
<NumberInput withAsterisk size="md" key={newItemForm.key('barcode')} label="Barcode"
|
||||
placeholder="Barcode" {...newItemForm.getInputProps('barcode')}/>
|
||||
<TextInput withAsterisk key={newItemForm.key('brand')} size="md" label="Brand"
|
||||
placeholder="Brand" {...newItemForm.getInputProps('brand')}/>
|
||||
<TextInput withAsterisk key={newItemForm.key('name')} size="md" label="Name"
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
import {Button, Group, TextInput, Text, Textarea, NumberInput, Container, Title, Flex} from '@mantine/core';
|
||||
import {Button, Group, TextInput, Textarea, NumberInput, Container, Title, Flex} from '@mantine/core';
|
||||
import {useForm} from '@mantine/form';
|
||||
import {useParams} from "react-router";
|
||||
import {useNavigate, useParams} from "react-router";
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {InventoryItem} from "./types.ts";
|
||||
import {useEffect} from "react";
|
||||
import {notifications} from "@mantine/notifications";
|
||||
import {IconCheck, IconX} from "@tabler/icons-react";
|
||||
|
||||
type EditableInventoryItem = Omit<InventoryItem, 'id'>;
|
||||
|
||||
function EditItem() {
|
||||
const params = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const editItemForm = useForm<EditableInventoryItem>({
|
||||
mode: 'uncontrolled',
|
||||
initialValues: {
|
||||
barcode: 0,
|
||||
name: "",
|
||||
brand: "",
|
||||
statusId: "",
|
||||
@@ -53,7 +57,26 @@ function EditItem() {
|
||||
}
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
notifications.show({
|
||||
icon: <IconCheck size={20} />,
|
||||
color:"teal",
|
||||
title: "All good!",
|
||||
message: "Item Updated",
|
||||
position: 'top-center',
|
||||
});
|
||||
navigate("/inventory");
|
||||
|
||||
}
|
||||
|
||||
if (!result.ok) {
|
||||
notifications.show({
|
||||
icon: <IconX size={20} />,
|
||||
color:"red",
|
||||
title: "Bummer!",
|
||||
message: "Something went wrong",
|
||||
position: 'top-center',
|
||||
});
|
||||
throw new Error('Failed to update inventory item');
|
||||
}
|
||||
|
||||
@@ -90,7 +113,8 @@ function EditItem() {
|
||||
|
||||
<div>{isFetching ? 'Updating...' : ''}</div>
|
||||
<Title order={1}>Edit Item</Title>
|
||||
<Text>ID: {data.id}</Text>
|
||||
<NumberInput withAsterisk size="md" key={editItemForm.key('barcode')} label="Barcode"
|
||||
placeholder="Barcode" {...editItemForm.getInputProps('barcode')}/>
|
||||
<TextInput withAsterisk key={editItemForm.key('brand')} size="md" label="Brand"
|
||||
placeholder="Brand" {...editItemForm.getInputProps('brand')}/>
|
||||
<TextInput withAsterisk key={editItemForm.key('name')} size="md" label="Name"
|
||||
|
||||
@@ -1,27 +1,16 @@
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
import {InventoryItem} from "./types";
|
||||
import {Flex, Table} from '@mantine/core';
|
||||
import BarkButton from "../../common/components/BarkButton.tsx";
|
||||
import {Link, NavLink} from "react-router";
|
||||
import useInventoryList from "./hooks/useInventoryList.tsx";
|
||||
|
||||
|
||||
function InventoryList() {
|
||||
|
||||
const { isPending, error, data, isFetching } = useQuery({
|
||||
queryKey: ['inventory'],
|
||||
queryFn: async (): Promise<InventoryItem[]> => {
|
||||
const response = await fetch(
|
||||
import.meta.env.VITE_API_URL + '/inventory',
|
||||
)
|
||||
const inventoryQuery = useInventoryList();
|
||||
|
||||
if (!response.ok) throw new Error('Failed to fetch inventory ' + response.statusText)
|
||||
if (inventoryQuery.isPending) return 'Loading...'
|
||||
|
||||
return await response.json()
|
||||
},
|
||||
});
|
||||
|
||||
if (isPending) return 'Loading...'
|
||||
|
||||
if (error) return 'An error has occurred: ' + error.message
|
||||
if (inventoryQuery.error) return 'An error has occurred: ' + inventoryQuery.error.message
|
||||
|
||||
|
||||
return (
|
||||
@@ -37,16 +26,13 @@ function InventoryList() {
|
||||
<p>
|
||||
ARFF ARFF BARK BARK
|
||||
</p>
|
||||
<NavLink to={'/addItem'}><BarkButton>Add Item</BarkButton></NavLink>
|
||||
<NavLink to={'/inventory/addItem'}><BarkButton>Add Item</BarkButton></NavLink>
|
||||
</Flex>
|
||||
|
||||
|
||||
<div>{isFetching ? 'Updating...' : ''}</div>
|
||||
|
||||
<Table striped>
|
||||
<Table.Thead>
|
||||
<Table.Tr>
|
||||
<Table.Th c="red">ID</Table.Th>
|
||||
<Table.Th c="red">Barcode</Table.Th>
|
||||
<Table.Th c="red">Brand</Table.Th>
|
||||
<Table.Th c="red">Item</Table.Th>
|
||||
<Table.Th c="red">Status</Table.Th>
|
||||
@@ -54,14 +40,14 @@ function InventoryList() {
|
||||
</Table.Tr>
|
||||
</Table.Thead>
|
||||
<Table.Tbody>
|
||||
{data.map((data) => (
|
||||
{inventoryQuery.data?.map((data) => (
|
||||
<Table.Tr key={data.id}>
|
||||
<Table.Td>{data.id}</Table.Td>
|
||||
<Table.Td>{data.barcode}</Table.Td>
|
||||
<Table.Td>{data.brand}</Table.Td>
|
||||
<Table.Td>{data.name}</Table.Td>
|
||||
<Table.Td>{data.statusId}</Table.Td>
|
||||
<Table.Td>
|
||||
<Link to={`/itemDetail/${data.id}`}>Details</Link>
|
||||
<Link to={`/inventory/itemDetail/${data.id}`}>Details</Link>
|
||||
</Table.Td>
|
||||
</Table.Tr>
|
||||
))}
|
||||
|
||||
@@ -29,7 +29,7 @@ function ItemDetail() {
|
||||
<Container m="lg">
|
||||
<Title order={1}>Item Detail</Title>
|
||||
<div>{isFetching ? 'Updating...' : ''}</div>
|
||||
<Text>ID: {data.id}</Text>
|
||||
<Text>Barcode: {data.barcode}</Text>
|
||||
<Text>Brand: {data.brand}</Text>
|
||||
<Text>Name: {data.name}</Text>
|
||||
<Text>Status: {data.status.name}</Text>
|
||||
@@ -38,7 +38,7 @@ function ItemDetail() {
|
||||
<Text>Replacement Cost: ${data.replacementCost}</Text>
|
||||
<Text>Notes: {data.notes}</Text>
|
||||
|
||||
<Link to={`/editItem/${data.id}`}>Edit</Link>
|
||||
<Link to={`/inventory/editItem/${data.id}`}>Edit</Link>
|
||||
</Container>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
import {InventoryItem} from "../types.js";
|
||||
|
||||
const useInventoryList = () => useQuery({
|
||||
queryKey: ['inventory'],
|
||||
queryFn: async (): Promise<InventoryItem[]> => {
|
||||
const response = await fetch(
|
||||
import.meta.env.VITE_API_URL + '/inventory',
|
||||
)
|
||||
|
||||
if (!response.ok) throw new Error('Failed to fetch inventory ' + response.statusText)
|
||||
|
||||
return await response.json()
|
||||
},
|
||||
});
|
||||
|
||||
export default useInventoryList;
|
||||
@@ -1,5 +1,6 @@
|
||||
export interface InventoryItem {
|
||||
id: number,
|
||||
barcode: number,
|
||||
brand: string,
|
||||
name: string,
|
||||
status: {id: string; name: string},
|
||||
@@ -11,6 +12,7 @@ export interface InventoryItem {
|
||||
}
|
||||
|
||||
export interface NewItem {
|
||||
barcode: number,
|
||||
brand: string,
|
||||
name: string,
|
||||
serialNumber: string,
|
||||
|
||||
Reference in New Issue
Block a user