mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-08-11 11:42:03 +00:00
Compare commits
7 Commits
ddd90aa5a5
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 775d64ef9e | |||
| 4a479283da | |||
| 2eaa8723d0 | |||
| 0d2e049e69 | |||
| 656ccd7d52 | |||
| 7dcc366393 | |||
| 8b0a90d2e5 |
+4
-3
@@ -12,7 +12,7 @@ using barkmanapi;
|
||||
namespace barkmanapi.Migrations
|
||||
{
|
||||
[DbContext(typeof(BarkContext))]
|
||||
[Migration("20260723004900_changedOrderToJob")]
|
||||
[Migration("20260719204137_changedOrderToJob")]
|
||||
partial class changedOrderToJob
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -214,8 +214,9 @@ namespace barkmanapi.Migrations
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("address");
|
||||
|
||||
b.Property<int>("CustomerId")
|
||||
.HasColumnType("integer")
|
||||
b.Property<string>("CustomerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("customer_id");
|
||||
|
||||
b.Property<DateTimeOffset>("EndDate")
|
||||
+2
-2
@@ -39,7 +39,7 @@ namespace barkmanapi.Migrations
|
||||
{
|
||||
id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
customer_id = table.Column<int>(type: "integer", nullable: false),
|
||||
customer_id = table.Column<string>(type: "text", nullable: false),
|
||||
name = table.Column<string>(type: "text", nullable: false),
|
||||
status_id = table.Column<string>(type: "text", nullable: true),
|
||||
start_date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
@@ -123,7 +123,7 @@ namespace barkmanapi.Migrations
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
status_id = table.Column<string>(type: "text", nullable: true),
|
||||
address = table.Column<string>(type: "text", nullable: true),
|
||||
customer_id = table.Column<int>(type: "integer", nullable: false),
|
||||
customer_id = table.Column<string>(type: "text", nullable: false),
|
||||
end_date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
name = table.Column<string>(type: "text", nullable: false),
|
||||
notes = table.Column<string>(type: "text", nullable: true),
|
||||
@@ -1,294 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
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("20260723003407_fixedOrderCustomerID")]
|
||||
partial class fixedOrderCustomerID
|
||||
{
|
||||
/// <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.Customers", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("address");
|
||||
|
||||
b.Property<string>("BillingTerms")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("billing_terms");
|
||||
|
||||
b.Property<string>("Company")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("company");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("email");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("notes");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("phone_number");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_customers");
|
||||
|
||||
b.ToTable("customers", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("barkmanapi.InventoryItems", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Barcode")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.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.Property<float?>("Weight")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("weight");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_inventory");
|
||||
|
||||
b.HasIndex("Barcode")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_inventory_barcode");
|
||||
|
||||
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.OrderItems", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ItemId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("item_id");
|
||||
|
||||
b.Property<string>("OrderId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("order_id");
|
||||
|
||||
b.Property<int?>("OrdersId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("orders_id");
|
||||
|
||||
b.Property<int>("Quantity")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("quantity");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_order_items");
|
||||
|
||||
b.HasIndex("OrdersId")
|
||||
.HasDatabaseName("ix_order_items_orders_id");
|
||||
|
||||
b.ToTable("order_items", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("barkmanapi.OrderStatus", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_order_status");
|
||||
|
||||
b.ToTable("order_status", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("barkmanapi.Orders", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("address");
|
||||
|
||||
b.Property<int>("CustomerId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("customer_id");
|
||||
|
||||
b.Property<DateTimeOffset>("EndDate")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("end_date");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("notes");
|
||||
|
||||
b.Property<DateTimeOffset>("StartDate")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("start_date");
|
||||
|
||||
b.Property<string>("StatusId")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("status_id");
|
||||
|
||||
b.Property<decimal>("TotalPrice")
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("total_price");
|
||||
|
||||
b.Property<string>("Venue")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("venue");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_orders");
|
||||
|
||||
b.HasIndex("StatusId")
|
||||
.HasDatabaseName("ix_orders_status_id");
|
||||
|
||||
b.ToTable("orders", (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");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("barkmanapi.OrderItems", b =>
|
||||
{
|
||||
b.HasOne("barkmanapi.Orders", null)
|
||||
.WithMany("Items")
|
||||
.HasForeignKey("OrdersId")
|
||||
.HasConstraintName("fk_order_items_orders_orders_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("barkmanapi.Orders", b =>
|
||||
{
|
||||
b.HasOne("barkmanapi.OrderStatus", "Status")
|
||||
.WithMany()
|
||||
.HasForeignKey("StatusId")
|
||||
.HasConstraintName("fk_orders_order_status_status_id");
|
||||
|
||||
b.Navigation("Status");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("barkmanapi.Orders", b =>
|
||||
{
|
||||
b.Navigation("Items");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace barkmanapi.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class fixedOrderCustomerID : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "customer_id",
|
||||
table: "orders",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "customer_id",
|
||||
table: "orders",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,8 +211,9 @@ namespace barkmanapi.Migrations
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("address");
|
||||
|
||||
b.Property<int>("CustomerId")
|
||||
.HasColumnType("integer")
|
||||
b.Property<string>("CustomerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("customer_id");
|
||||
|
||||
b.Property<DateTimeOffset>("EndDate")
|
||||
|
||||
+161
-1
@@ -51,6 +51,18 @@ var customerGroup = app.MapGroup(prefix: "/customers")
|
||||
.WithTags("Customers")
|
||||
.WithDescription("Endpoints for managing customers");
|
||||
|
||||
var jobGroup = app.MapGroup(prefix: "/jobs")
|
||||
.WithTags("Jobs")
|
||||
.WithDescription("Endpoints for managing jobs");
|
||||
|
||||
var jobStatusGroup = app.MapGroup(prefix: "/jobstatus")
|
||||
.WithTags("Job Status")
|
||||
.WithDescription("Endpoints for managing job status");
|
||||
|
||||
var jobItemGroup = app.MapGroup(prefix: "/jobitems")
|
||||
.WithTags("Job Items")
|
||||
.WithDescription("Endpoints for managing job items");
|
||||
|
||||
inventoryGroup.MapGet("", async (BarkContext db) =>
|
||||
await db.Inventory.OrderBy(item => item.Barcode).ToListAsync());
|
||||
|
||||
@@ -144,7 +156,7 @@ itemStatusGroup.MapPut("/{id}", async (string id, ItemStatus updatedStatus, Bark
|
||||
var existingStatus = await db.ItemStatus.FindAsync(id);
|
||||
if (existingStatus == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Inventory item not found" });
|
||||
return Results.NotFound(new { Message = "Item status not found" });
|
||||
}
|
||||
|
||||
existingStatus.Id = updatedStatus.Id;
|
||||
@@ -232,6 +244,154 @@ customerGroup.MapDelete("/{id}", async (int id, BarkContext db) =>
|
||||
return Results.Ok(new { Message = "Customer deleted successfully" });
|
||||
});
|
||||
|
||||
jobGroup.MapGet("", async (BarkContext db) =>
|
||||
await db.Jobs.OrderBy(jobs => jobs.Id).ToListAsync());
|
||||
|
||||
jobGroup.MapGet("/{id}", async (int id, BarkContext db) =>
|
||||
{
|
||||
var job = await db.Jobs
|
||||
.FirstOrDefaultAsync(i => i.Id == id);
|
||||
|
||||
if (job == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Job not found" });
|
||||
}
|
||||
|
||||
return Results.Ok(job);
|
||||
});
|
||||
|
||||
jobGroup.MapPut("/{id}", async (int id, Jobs updatedJob, BarkContext db) =>
|
||||
{
|
||||
var existingJob = await db.Jobs.FindAsync(id);
|
||||
if (existingJob == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Job not found" });
|
||||
}
|
||||
|
||||
existingJob.Name = updatedJob.Name;
|
||||
existingJob.StartDate = updatedJob.StartDate;
|
||||
existingJob.EndDate = updatedJob.EndDate;
|
||||
existingJob.TotalPrice = updatedJob.TotalPrice;
|
||||
existingJob.Venue = updatedJob.Venue;
|
||||
existingJob.Address = updatedJob.Address;
|
||||
existingJob.Notes = updatedJob.Notes;
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(existingJob);
|
||||
});
|
||||
|
||||
jobGroup.MapPost("", async (Jobs newJobInput, BarkContext db) =>
|
||||
{
|
||||
var newJob = new Jobs()
|
||||
{
|
||||
CustomerId = newJobInput.CustomerId,
|
||||
Name = newJobInput.Name,
|
||||
StartDate = newJobInput.StartDate,
|
||||
EndDate = newJobInput.EndDate,
|
||||
Venue = newJobInput.Venue,
|
||||
Address = newJobInput.Address,
|
||||
};
|
||||
|
||||
db.Jobs.Add(newJob);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Created($"/jobs/{newJob.Id}", newJob);
|
||||
});
|
||||
|
||||
jobStatusGroup.MapGet("/", async (BarkContext db) =>
|
||||
await db.JobStatus.ToListAsync());
|
||||
|
||||
jobStatusGroup.MapPost("/", async (JobStatus newJobStatus, BarkContext db) =>
|
||||
{
|
||||
db.JobStatus.Add(newJobStatus);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Created($"/jobstatus/{newJobStatus.Id}", newJobStatus);
|
||||
});
|
||||
|
||||
jobStatusGroup.MapGet("/{id}", async (string id, BarkContext db) =>
|
||||
{
|
||||
var jobStatus = await db.JobStatus.FindAsync(id);
|
||||
if (jobStatus == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Job Status not found" });
|
||||
}
|
||||
|
||||
return Results.Ok(jobStatus);
|
||||
});
|
||||
|
||||
jobStatusGroup.MapPut("/{id}", async (string id, JobStatus updatedStatus, BarkContext db) =>
|
||||
{
|
||||
var existingStatus = await db.JobStatus.FindAsync(id);
|
||||
if (existingStatus == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Job status not found" });
|
||||
}
|
||||
|
||||
existingStatus.Id = updatedStatus.Id;
|
||||
existingStatus.Name = updatedStatus.Name;
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(existingStatus);
|
||||
});
|
||||
|
||||
jobStatusGroup.MapDelete("/{id}", async (string id, BarkContext db) =>
|
||||
{
|
||||
var jobStatus = await db.JobStatus.FindAsync(id);
|
||||
if (jobStatus == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Job status not found" });
|
||||
}
|
||||
|
||||
db.JobStatus.Remove(jobStatus);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(new { Message = "Job status deleted successfully" });
|
||||
});
|
||||
|
||||
jobItemGroup.MapGet("", async (BarkContext db) =>
|
||||
await db.JobItems.OrderBy(items => items.Id).ToListAsync());
|
||||
|
||||
jobItemGroup.MapGet("/{id}", async (int id, BarkContext db) =>
|
||||
{
|
||||
var jobItems = await db.JobItems
|
||||
.FirstOrDefaultAsync(i => i.Id == id);
|
||||
|
||||
if (jobItems == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Job Items not found" });
|
||||
}
|
||||
|
||||
return Results.Ok(jobItems);
|
||||
});
|
||||
|
||||
jobItemGroup.MapPut("/{id}", async (int id, JobItems updatedJobItems, BarkContext db) =>
|
||||
{
|
||||
var existingJobItems = await db.JobItems.FindAsync(id);
|
||||
if (existingJobItems == null)
|
||||
{
|
||||
return Results.NotFound(new { Message = "Job Items not found" });
|
||||
}
|
||||
|
||||
existingJobItems.OrderId = updatedJobItems.OrderId;
|
||||
existingJobItems.ItemId = updatedJobItems.ItemId;
|
||||
existingJobItems.Quantity = updatedJobItems.Quantity;
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(existingJobItems);
|
||||
});
|
||||
|
||||
jobItemGroup.MapPost("", async (JobItems newJobItemsInput, BarkContext db) =>
|
||||
{
|
||||
var newJobItem = new JobItems()
|
||||
{
|
||||
OrderId = newJobItemsInput.OrderId,
|
||||
ItemId = newJobItemsInput.ItemId,
|
||||
Quantity = newJobItemsInput.Quantity,
|
||||
};
|
||||
|
||||
db.JobItems.Add(newJobItem);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Created($"/jobItems/{newJobItem.Id}", newJobItem);
|
||||
});
|
||||
|
||||
using (var serviceScope = app.Services.CreateScope())
|
||||
{
|
||||
var dbContext = serviceScope.ServiceProvider.GetRequiredService<BarkContext>();
|
||||
|
||||
@@ -49,7 +49,7 @@ public class Customers
|
||||
public class Jobs
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public required int CustomerId { get; set; }
|
||||
public required string CustomerId { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public JobStatus Status { get; set; }
|
||||
public string? StatusId { get; set; }
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
22.22.1
|
||||
Generated
+1310
-1802
File diff suppressed because it is too large
Load Diff
+26
-26
@@ -10,34 +10,34 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mantine/core": "^7.16.0",
|
||||
"@mantine/form": "^7.16.0",
|
||||
"@mantine/hooks": "^7.16.0",
|
||||
"@mantine/notifications": "^7.16.2",
|
||||
"@tabler/icons-react": "^3.29.0",
|
||||
"@tanstack/react-query": "^5.64.1",
|
||||
"@tanstack/react-query-devtools": "^5.64.1",
|
||||
"axios": "^1.7.9",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-router": "^7.1.1",
|
||||
"react-router-dom": "^7.1.1"
|
||||
"@mantine/core": "^9.4.2",
|
||||
"@mantine/form": "^9.4.2",
|
||||
"@mantine/hooks": "^9.4.2",
|
||||
"@mantine/notifications": "^9.4.2",
|
||||
"@tabler/icons-react": "^3.45.0",
|
||||
"@tanstack/react-query": "^5.101.4",
|
||||
"@tanstack/react-query-devtools": "^5.101.4",
|
||||
"axios": "^1.18.1",
|
||||
"react": "^19.2.8",
|
||||
"react-dom": "^19.2.8",
|
||||
"react-router": "^8.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.17.0",
|
||||
"@tanstack/eslint-plugin-query": "^5.62.16",
|
||||
"@types/react": "^18.3.18",
|
||||
"@types/react-dom": "^18.3.5",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"eslint": "^9.17.0",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.16",
|
||||
"globals": "^15.14.0",
|
||||
"postcss": "^8.5.1",
|
||||
"postcss-preset-mantine": "^1.17.0",
|
||||
"@eslint/js": "^9.39.5",
|
||||
"@tanstack/eslint-plugin-query": "^5.101.4",
|
||||
"@types/node": "^26.1.1",
|
||||
"@types/react": "^19.2.17",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^6.0.4",
|
||||
"eslint": "^9.39.5",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"eslint-plugin-react-refresh": "^0.5.3",
|
||||
"globals": "^17.7.0",
|
||||
"postcss": "^8.5.22",
|
||||
"postcss-preset-mantine": "^1.18.0",
|
||||
"postcss-simple-vars": "^7.0.1",
|
||||
"typescript": "~5.6.2",
|
||||
"typescript-eslint": "^8.18.2",
|
||||
"vite": "^6.0.5"
|
||||
"typescript": "^6.0.3",
|
||||
"typescript-eslint": "^8.65.0",
|
||||
"vite": "^8.1.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
import {Button, Group, TextInput, Container, Title, Flex} from '@mantine/core';
|
||||
import {useForm} from '@mantine/form';
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import {NewJob} from "./types.ts";
|
||||
import {useNavigate} from "react-router";
|
||||
import {IconX, IconCheck} from '@tabler/icons-react';
|
||||
import {notifications} from '@mantine/notifications';
|
||||
import useJobList from "./hooks/useJobList.tsx";
|
||||
|
||||
|
||||
function AddJob() {
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const customerQuery = useCustomerList();
|
||||
|
||||
const newJobForm = useForm<NewJob>({
|
||||
mode: 'uncontrolled',
|
||||
initialValues: {
|
||||
name: "",
|
||||
company: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
address: "",
|
||||
},
|
||||
|
||||
validate: {},
|
||||
});
|
||||
|
||||
const updateCustomer = useMutation({
|
||||
mutationFn: async (values: newJob) => {
|
||||
|
||||
const result = await fetch(import.meta.env.VITE_API_URL + '/customers', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(values),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
notifications.show({
|
||||
icon: <IconCheck size={20}/>,
|
||||
color: "teal",
|
||||
title: "All good!",
|
||||
message: "Customer Created",
|
||||
position: 'top-center',
|
||||
});
|
||||
navigate("/customers");
|
||||
|
||||
}
|
||||
|
||||
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 create customer');
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
})
|
||||
|
||||
if (customerQuery.isPending) return 'Loading...'
|
||||
if (customerQuery.error) return 'An error has occurred: ' + customerQuery.error.message
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<form onSubmit={newCustomerForm.onSubmit(async (values) => await
|
||||
updateCustomer.mutateAsync(values))}>
|
||||
<Container m="lg">
|
||||
<Flex mih={50}
|
||||
gap="md"
|
||||
justify="flex-start"
|
||||
align="flex-start"
|
||||
direction="column"
|
||||
wrap="wrap">
|
||||
|
||||
<Title order={1}>Add Item</Title>
|
||||
<TextInput withAsterisk key={newCustomerForm.key('name')} size="md" label="Name"
|
||||
placeholder="Name" {...newCustomerForm.getInputProps('name')}/>
|
||||
<TextInput size="md" key={newCustomerForm.key('company')} label="Company"
|
||||
placeholder="Company"{...newCustomerForm.getInputProps('company')}/>
|
||||
<TextInput withAsterisk size="md" key={newCustomerForm.key('email')} label="Email"
|
||||
placeholder="Email" {...newCustomerForm.getInputProps('email')}/>
|
||||
<TextInput size="md" key={newCustomerForm.key('phone')} label="Phone"
|
||||
placeholder="Phone" {...newCustomerForm.getInputProps('phone')}/>
|
||||
<TextInput size="md" key={newCustomerForm.key('address')} label="Address"
|
||||
placeholder="Address" {...newCustomerForm.getInputProps('address')}/>
|
||||
|
||||
<Group justify="flex-end" mt="md">
|
||||
<Button type="submit">Submit</Button>
|
||||
</Group>
|
||||
</Flex>
|
||||
</Container>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default AddCustomer;
|
||||
@@ -1,17 +0,0 @@
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
import {Job} from "../types.ts";
|
||||
|
||||
const useJobList = () => useQuery({
|
||||
queryKey: ['job'],
|
||||
queryFn: async (): Promise<Job[]> => {
|
||||
const response = await fetch(
|
||||
import.meta.env.VITE_API_URL + '/jobs',
|
||||
)
|
||||
|
||||
if (!response.ok) throw new Error('Failed to fetch jobs ' + response.statusText)
|
||||
|
||||
return await response.json()
|
||||
},
|
||||
});
|
||||
|
||||
export default useJobList;
|
||||
@@ -1,23 +0,0 @@
|
||||
export interface Job {
|
||||
id: number,
|
||||
customerId: number,
|
||||
name: string,
|
||||
status: {id: string; name: string},
|
||||
statusId: string;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
totalPrice: string,
|
||||
venue: number,
|
||||
address: number,
|
||||
notes: string,
|
||||
}
|
||||
|
||||
export interface NewJob {
|
||||
customerId: number,
|
||||
name: string,
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
venue: number,
|
||||
address: number,
|
||||
notes: string,
|
||||
}
|
||||
@@ -21,8 +21,7 @@
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true,
|
||||
|
||||
"baseUrl": ".",
|
||||
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user