Skip to content

Commit 05b8504

Browse files
committed
Merge branch 'development' into mark
2 parents 9dd5f07 + 88c1ff2 commit 05b8504

35 files changed

+3830
-671
lines changed

CargoHub.sln

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CargoHub", "CargoHub\CargoHub.csproj", "{DF5C2A7E-1DF9-42A8-B3B9-D6552BDB3BE3}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CargoHub.Tests", "UnitTest\CargoHub.Tests.csproj", "{08CCD5C8-5AE7-4908-843D-884E2BAC774D}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CargoHub.Test", "UnitTest\CargoHub.Test.csproj", "{2565E8A5-EBB2-4773-AE8C-C14387ACB2A0}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -24,5 +24,9 @@ Global
2424
{08CCD5C8-5AE7-4908-843D-884E2BAC774D}.Debug|Any CPU.Build.0 = Debug|Any CPU
2525
{08CCD5C8-5AE7-4908-843D-884E2BAC774D}.Release|Any CPU.ActiveCfg = Release|Any CPU
2626
{08CCD5C8-5AE7-4908-843D-884E2BAC774D}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{2565E8A5-EBB2-4773-AE8C-C14387ACB2A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{2565E8A5-EBB2-4773-AE8C-C14387ACB2A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{2565E8A5-EBB2-4773-AE8C-C14387ACB2A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{2565E8A5-EBB2-4773-AE8C-C14387ACB2A0}.Release|Any CPU.Build.0 = Release|Any CPU
2731
EndGlobalSection
2832
EndGlobal

CargoHub/AppDbContext.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
9090
.HasForeignKey(oi => oi.ItemUid); // De koppeling is via ItemUid
9191

9292

93-
modelBuilder.Entity<Inventory>()
94-
.HasMany(i => i.Locations)
95-
.WithMany(l => l.Inventories);
96-
// .UsingEntity(j => j.ToTable("StudentCourses"));
97-
modelBuilder.Entity<Classification>().Navigation(c => c.Warehouses).AutoInclude(true);
98-
modelBuilder.Entity<Classification>().Navigation(c => c.Locations).AutoInclude(true);
99-
modelBuilder.Entity<Classification>().Navigation(c => c.Transfers).AutoInclude(true);
100-
modelBuilder.Entity<Classification>().Navigation(c => c.Suppliers).AutoInclude(true);
101-
modelBuilder.Entity<Classification>().Navigation(c => c.Items).AutoInclude(true);
102-
modelBuilder.Entity<Classification>().Navigation(c => c.Shipments).AutoInclude(true);
103-
modelBuilder.Entity<Classification>().Navigation(c => c.Orders).AutoInclude(true);
93+
// modelBuilder.Entity<Inventory>()
94+
// .HasMany(i => i.Locations)
95+
// .WithMany(l => l.Inventories);
96+
// // .UsingEntity(j => j.ToTable("StudentCourses"));
97+
// modelBuilder.Entity<Classification>().Navigation(c => c.Warehouses).AutoInclude(true);
98+
// modelBuilder.Entity<Classification>().Navigation(c => c.Locations).AutoInclude(true);
99+
// modelBuilder.Entity<Classification>().Navigation(c => c.Transfers).AutoInclude(true);
100+
// modelBuilder.Entity<Classification>().Navigation(c => c.Suppliers).AutoInclude(true);
101+
// modelBuilder.Entity<Classification>().Navigation(c => c.Items).AutoInclude(true);
102+
// modelBuilder.Entity<Classification>().Navigation(c => c.Shipments).AutoInclude(true);
103+
// modelBuilder.Entity<Classification>().Navigation(c => c.Orders).AutoInclude(true);
104104

105105

106106

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
1-
using CargoHub.Models;
2-
using CargoHub.Services;
3-
using CargoHub.Utilities;
4-
using Microsoft.AspNetCore.Mvc;
5-
using Microsoft.EntityFrameworkCore.Metadata.Internal;
1+
// using CargoHub.Models;
2+
// using CargoHub.Services;
3+
// using CargoHub.Utilities;
4+
// using Microsoft.AspNetCore.Mvc;
5+
// using Microsoft.EntityFrameworkCore.Metadata.Internal;
66

7-
namespace CargoHub.Controllers
8-
{
9-
[Route("api/v2/[Controller]")]
10-
public class ClassificationController(ClassificationService service, ErrorHandler handler) : BaseController<Classification>(service, handler)
11-
{
12-
[HttpPut("Order")]
13-
public async Task<IActionResult> AssignClassificationToOrder([FromQuery] int OrderId, [FromQuery] int ClassificationId)
14-
{
15-
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Order>(OrderId, ClassificationId);
16-
return SuccessfullyAssigned ? Ok() : BadRequest();
17-
}
7+
// namespace CargoHub.Controllers
8+
// {
9+
// [Route("api/v2/[Controller]")]
10+
// public class ClassificationController(ClassificationService service, ErrorHandler handler) : BaseController<Classification>(service, handler)
11+
// {
12+
// [HttpPut("Order")]
13+
// public async Task<IActionResult> AssignClassificationToOrder([FromQuery] int OrderId, [FromQuery] int ClassificationId)
14+
// {
15+
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Order>(OrderId, ClassificationId);
16+
// return SuccessfullyAssigned ? Ok() : BadRequest();
17+
// }
1818

19-
[HttpPut("Shipment")]
20-
public async Task<IActionResult> AssignClassificationToShipment([FromQuery] int ShipmentId, [FromQuery] int ClassificationId)
21-
{
22-
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Shipment>(ShipmentId, ClassificationId);
23-
return SuccessfullyAssigned ? Ok() : BadRequest();
24-
}
19+
// [HttpPut("Shipment")]
20+
// public async Task<IActionResult> AssignClassificationToShipment([FromQuery] int ShipmentId, [FromQuery] int ClassificationId)
21+
// {
22+
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Shipment>(ShipmentId, ClassificationId);
23+
// return SuccessfullyAssigned ? Ok() : BadRequest();
24+
// }
2525

26-
[HttpPut("Warehouse")]
27-
public async Task<IActionResult> AssignClassificationToWarehouse([FromQuery] int WarehouseId, [FromQuery] int ClassificationId)
28-
{
29-
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Warehouse>(WarehouseId, ClassificationId);
30-
return SuccessfullyAssigned ? Ok() : BadRequest();
31-
}
32-
[HttpPut("Location")]
33-
public async Task<IActionResult> AssignClassificationToLocation([FromQuery] int LocationId, [FromBody] int ClassificationId)
34-
{
26+
// [HttpPut("Warehouse")]
27+
// public async Task<IActionResult> AssignClassificationToWarehouse([FromQuery] int WarehouseId, [FromQuery] int ClassificationId)
28+
// {
29+
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Warehouse>(WarehouseId, ClassificationId);
30+
// return SuccessfullyAssigned ? Ok() : BadRequest();
31+
// }
32+
// [HttpPut("Location")]
33+
// public async Task<IActionResult> AssignClassificationToLocation([FromQuery] int LocationId, [FromBody] int ClassificationId)
34+
// {
3535

36-
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Location>(LocationId, ClassificationId);
37-
return SuccessfullyAssigned ? Ok() : BadRequest();
38-
}
39-
[HttpPut("Transfer")]
40-
public async Task<IActionResult> AssignClassificationToTransfer([FromQuery] int LocationId, [FromQuery] int ClassificationId)
41-
{
36+
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Location>(LocationId, ClassificationId);
37+
// return SuccessfullyAssigned ? Ok() : BadRequest();
38+
// }
39+
// [HttpPut("Transfer")]
40+
// public async Task<IActionResult> AssignClassificationToTransfer([FromQuery] int LocationId, [FromQuery] int ClassificationId)
41+
// {
4242

43-
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Location>(LocationId, ClassificationId);
44-
return SuccessfullyAssigned ? Ok() : BadRequest();
45-
}
46-
[HttpPut("Supplier")]
47-
public async Task<IActionResult> AssignClassificationToSupplier([FromQuery] int SupplierId, [FromQuery] int ClassificationId)
48-
{
43+
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Location>(LocationId, ClassificationId);
44+
// return SuccessfullyAssigned ? Ok() : BadRequest();
45+
// }
46+
// [HttpPut("Supplier")]
47+
// public async Task<IActionResult> AssignClassificationToSupplier([FromQuery] int SupplierId, [FromQuery] int ClassificationId)
48+
// {
4949

50-
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Supplier>(SupplierId, ClassificationId);
51-
return SuccessfullyAssigned ? Ok() : BadRequest();
52-
}
53-
[HttpPut("Item")]
54-
public async Task<IActionResult> AssignClassificationToItem([FromQuery] int ItemId, [FromQuery] int ClassificationId)
55-
{
50+
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Supplier>(SupplierId, ClassificationId);
51+
// return SuccessfullyAssigned ? Ok() : BadRequest();
52+
// }
53+
// [HttpPut("Item")]
54+
// public async Task<IActionResult> AssignClassificationToItem([FromQuery] int ItemId, [FromQuery] int ClassificationId)
55+
// {
5656

57-
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Item>(ItemId, ClassificationId);
58-
return SuccessfullyAssigned ? Ok() : BadRequest();
59-
}
60-
}
61-
}
57+
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Item>(ItemId, ClassificationId);
58+
// return SuccessfullyAssigned ? Ok() : BadRequest();
59+
// }
60+
// }
61+
// }

CargoHub/Controllers/MonthlyReportController.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
22
using System.IO;
3+
using System.Text;
34
using System.Threading.Tasks;
45
using CargoHub.Services;
56

@@ -24,21 +25,20 @@ public async Task<IActionResult> GenerateMonthlyReport(int year, int month)
2425
return BadRequest(new { message = "Invalid year or month. Please provide valid values." });
2526
}
2627

27-
// Generate the report and get the file path
28-
string filePath = await _reportService.GenerateMonthlyReport(year, month);
28+
// Generate the report and get the CSV content
29+
string csvContent = await _reportService.GenerateMonthlyCsvReport(year, month);
2930

30-
// Serve the file if it exists
31-
if (System.IO.File.Exists(filePath))
31+
if (!string.IsNullOrEmpty(csvContent))
3232
{
33-
byte[] fileBytes = await System.IO.File.ReadAllBytesAsync(filePath);
34-
string fileName = Path.GetFileName(filePath);
33+
byte[] csvBytes = Encoding.UTF8.GetBytes(csvContent);
34+
string fileName = $"MonthlyReport_{year}_{month:D2}.csv";
3535

36-
return Ok();
36+
return File(csvBytes, "text/csv", fileName);
3737
}
3838
else
3939
{
40-
return NotFound(new { message = "Report not found." });
40+
return NotFound(new { message = "No data available for the specified month and year." });
4141
}
4242
}
4343
}
44-
}
44+
}

CargoHub/Controllers/OrdersController.cs

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ public async Task<ActionResult<OrderWithItemsDTO>> GetOrder(int id)
3838
return Ok(order);
3939
}
4040

41+
// GET /orders/{orderId}/items
42+
[HttpGet("{orderId}/items")]
43+
public async Task<IActionResult> GetOrderItems(int orderId)
44+
{
45+
try
46+
{
47+
var items = await _orderService.GetOrderItems(orderId);
48+
return Ok(items);
49+
}
50+
catch (Exception ex)
51+
{
52+
return NotFound(new { message = ex.Message });
53+
}
54+
}
55+
4156
[HttpGet("client/{clientId}")]
4257
public async Task<ActionResult<List<Order>>> GetOrdersForClient(int clientId)
4358
{
@@ -88,46 +103,75 @@ public async Task<ActionResult<List<Order>>> GetOrderForStatus(string status)
88103
}
89104

90105
[HttpPost]
91-
public async Task<ActionResult<Order>> CreateOrder([FromBody] OrderWithItemsDTO orderDto)
92-
{
93-
if (orderDto == null)
94-
{
95-
return BadRequest("Ordergegevens zijn verplicht.");
96-
}
106+
[HttpPost]
107+
public async Task<ActionResult<OrderWithItemsDTO>> CreateOrder([FromBody] OrderWithItemsDTO orderDto)
108+
{
109+
if (orderDto == null)
110+
{
111+
return BadRequest("Ordergegevens zijn verplicht.");
112+
}
97113

98-
try
99-
{
100-
var order = new Order
101-
{
102-
SourceId = orderDto.SourceId,
103-
OrderDate = orderDto.OrderDate,
104-
RequestDate = orderDto.RequestDate,
105-
Reference = orderDto.Reference,
106-
ExtrReference = orderDto.ReferenceExtra,
107-
OrderStatus = orderDto.OrderStatus,
108-
Notes = orderDto.Notes,
109-
ShippingNotes = orderDto.ShippingNotes,
110-
PickingNotes = orderDto.PickingNotes,
111-
WarehouseId = orderDto.WarehouseId ?? null,
112-
ShipTo = orderDto.ShipTo ?? null,
113-
BillTo = orderDto.BillTo ?? null,
114-
ShipmentId = orderDto.ShipmentId ?? null,
115-
TotalAmount = orderDto.TotalAmount,
116-
TotalDiscount = orderDto.TotalDiscount,
117-
TotalTax = orderDto.TotalTax,
118-
TotalSurcharge = orderDto.TotalSurcharge,
119-
CreatedAt = DateTime.UtcNow,
120-
UpdatedAt = DateTime.UtcNow
121-
};
122-
123-
var createdOrder = await _orderService.CreateOrder(order, orderDto.Items);
124-
return CreatedAtAction(nameof(GetOrder), new { id = createdOrder.Id }, createdOrder);
125-
}
126-
catch (Exception ex)
127-
{
128-
return StatusCode(500, $"Interne serverfout: {ex.Message}");
129-
}
130-
}
114+
try
115+
{
116+
var order = new Order
117+
{
118+
SourceId = orderDto.SourceId,
119+
OrderDate = orderDto.OrderDate,
120+
RequestDate = orderDto.RequestDate,
121+
Reference = orderDto.Reference,
122+
ExtrReference = orderDto.ReferenceExtra,
123+
OrderStatus = orderDto.OrderStatus,
124+
Notes = orderDto.Notes,
125+
ShippingNotes = orderDto.ShippingNotes,
126+
PickingNotes = orderDto.PickingNotes,
127+
WarehouseId = orderDto.WarehouseId ?? null,
128+
ShipTo = orderDto.ShipTo ?? null,
129+
BillTo = orderDto.BillTo ?? null,
130+
ShipmentId = orderDto.ShipmentId ?? null,
131+
TotalAmount = orderDto.TotalAmount,
132+
TotalDiscount = orderDto.TotalDiscount,
133+
TotalTax = orderDto.TotalTax,
134+
TotalSurcharge = orderDto.TotalSurcharge,
135+
CreatedAt = DateTime.UtcNow,
136+
UpdatedAt = DateTime.UtcNow
137+
};
138+
139+
// Maak de order aan via de service
140+
var createdOrder = await _orderService.CreateOrder(order, orderDto.Items);
141+
142+
// Map de gemaakte order naar een DTO
143+
var createdOrderDto = new OrderWithItemsDTO
144+
{
145+
Id = createdOrder.Id,
146+
SourceId = createdOrder.SourceId,
147+
OrderDate = createdOrder.OrderDate,
148+
RequestDate = createdOrder.RequestDate,
149+
Reference = createdOrder.Reference,
150+
ReferenceExtra = createdOrder.ExtrReference,
151+
OrderStatus = createdOrder.OrderStatus,
152+
Notes = createdOrder.Notes,
153+
ShippingNotes = createdOrder.ShippingNotes,
154+
PickingNotes = createdOrder.PickingNotes,
155+
WarehouseId = createdOrder.WarehouseId,
156+
ShipTo = createdOrder.ShipTo,
157+
BillTo = createdOrder.BillTo,
158+
ShipmentId = createdOrder.ShipmentId,
159+
TotalAmount = createdOrder.TotalAmount,
160+
TotalDiscount = createdOrder.TotalDiscount,
161+
TotalTax = createdOrder.TotalTax,
162+
TotalSurcharge = createdOrder.TotalSurcharge,
163+
CreatedAt = createdOrder.CreatedAt,
164+
UpdatedAt = createdOrder.UpdatedAt,
165+
Items = orderDto.Items // Aangezien deze al correct zijn aangeleverd
166+
};
167+
168+
return CreatedAtAction(nameof(GetOrder), new { id = createdOrder.Id }, createdOrderDto);
169+
}
170+
catch (Exception ex)
171+
{
172+
return StatusCode(500, $"Interne serverfout: {ex.Message}");
173+
}
174+
}
131175

132176
[HttpPut("{id}/items")]
133177
public async Task<IActionResult> UpdateItemsInOrder(int id, [FromBody] List<ItemDTO> orderItems)

CargoHub/Controllers/Paklijst.cs

Whitespace-only changes.

CargoHub/Controllers/ShipmentsController.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ public async Task<IActionResult> UpdateShipmentFields(int shipmentId, [FromBody]
148148
}
149149
}
150150

151+
[HttpGet("{shipmentId}/items")]
152+
public async Task<ActionResult<List<ItemDTO>>> GetItemsByShipmentId(int shipmentId)
153+
{
154+
var items = await _shipmentService.GetItemsByShipmentId(shipmentId);
155+
156+
if (items == null)
157+
{
158+
return NotFound($"Shipment met ID {shipmentId} niet gevonden of bevat geen items.");
159+
}
160+
161+
return Ok(items);
162+
}
163+
164+
151165
[HttpDelete("{id}")]
152166
public async Task<IActionResult> DeleteShipment(int id)
153167
{

CargoHub/Models/Inventory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ public class Inventory : BaseModel
3838
[JsonPropertyName("total_available")]
3939
public required int? TotalAvailable { get; set; }
4040
}
41-
}
41+
}

0 commit comments

Comments
 (0)