Skip to content

Commit

Permalink
Merge branch 'development' into Alihan2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alihanaslan75 committed Jan 20, 2025
2 parents 278951f + 88c1ff2 commit 52034de
Show file tree
Hide file tree
Showing 43 changed files with 4,046 additions and 729 deletions.
22 changes: 11 additions & 11 deletions CargoHub/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasForeignKey(oi => oi.ItemUid); // De koppeling is via ItemUid


modelBuilder.Entity<Inventory>()
.HasMany(i => i.Locations)
.WithMany(l => l.Inventories);
// .UsingEntity(j => j.ToTable("StudentCourses"));
modelBuilder.Entity<Classification>().Navigation(c => c.Warehouses).AutoInclude(true);
modelBuilder.Entity<Classification>().Navigation(c => c.Locations).AutoInclude(true);
modelBuilder.Entity<Classification>().Navigation(c => c.Transfers).AutoInclude(true);
modelBuilder.Entity<Classification>().Navigation(c => c.Suppliers).AutoInclude(true);
modelBuilder.Entity<Classification>().Navigation(c => c.Items).AutoInclude(true);
modelBuilder.Entity<Classification>().Navigation(c => c.Shipments).AutoInclude(true);
modelBuilder.Entity<Classification>().Navigation(c => c.Orders).AutoInclude(true);
// modelBuilder.Entity<Inventory>()
// .HasMany(i => i.Locations)
// .WithMany(l => l.Inventories);
// // .UsingEntity(j => j.ToTable("StudentCourses"));
// modelBuilder.Entity<Classification>().Navigation(c => c.Warehouses).AutoInclude(true);
// modelBuilder.Entity<Classification>().Navigation(c => c.Locations).AutoInclude(true);
// modelBuilder.Entity<Classification>().Navigation(c => c.Transfers).AutoInclude(true);
// modelBuilder.Entity<Classification>().Navigation(c => c.Suppliers).AutoInclude(true);
// modelBuilder.Entity<Classification>().Navigation(c => c.Items).AutoInclude(true);
// modelBuilder.Entity<Classification>().Navigation(c => c.Shipments).AutoInclude(true);
// modelBuilder.Entity<Classification>().Navigation(c => c.Orders).AutoInclude(true);



Expand Down
2 changes: 2 additions & 0 deletions CargoHub/CargoHub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Dropbox.Api" Version="7.0.0" />
<PackageReference Include="itext7" Version="9.0.0" />
<PackageReference Include="itext7.pdfhtml" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
Expand Down
108 changes: 54 additions & 54 deletions CargoHub/Controllers/ClassificationsControlller.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
using CargoHub.Models;
using CargoHub.Services;
using CargoHub.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
// using CargoHub.Models;
// using CargoHub.Services;
// using CargoHub.Utilities;
// using Microsoft.AspNetCore.Mvc;
// using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace CargoHub.Controllers
{
[Route("api/v2/[Controller]")]
public class ClassificationController(ClassificationService service, ErrorHandler handler) : BaseController<Classification>(service, handler)
{
[HttpPut("Order")]
public async Task<IActionResult> AssignClassificationToOrder([FromQuery] int OrderId, [FromQuery] int ClassificationId)
{
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Order>(OrderId, ClassificationId);
return SuccessfullyAssigned ? Ok() : BadRequest();
}
// namespace CargoHub.Controllers
// {
// [Route("api/v2/[Controller]")]
// public class ClassificationController(ClassificationService service, ErrorHandler handler) : BaseController<Classification>(service, handler)
// {
// [HttpPut("Order")]
// public async Task<IActionResult> AssignClassificationToOrder([FromQuery] int OrderId, [FromQuery] int ClassificationId)
// {
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Order>(OrderId, ClassificationId);
// return SuccessfullyAssigned ? Ok() : BadRequest();
// }

[HttpPut("Shipment")]
public async Task<IActionResult> AssignClassificationToShipment([FromQuery] int ShipmentId, [FromQuery] int ClassificationId)
{
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Shipment>(ShipmentId, ClassificationId);
return SuccessfullyAssigned ? Ok() : BadRequest();
}
// [HttpPut("Shipment")]
// public async Task<IActionResult> AssignClassificationToShipment([FromQuery] int ShipmentId, [FromQuery] int ClassificationId)
// {
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Shipment>(ShipmentId, ClassificationId);
// return SuccessfullyAssigned ? Ok() : BadRequest();
// }

[HttpPut("Warehouse")]
public async Task<IActionResult> AssignClassificationToWarehouse([FromQuery] int WarehouseId, [FromQuery] int ClassificationId)
{
var SuccessfullyAssigned = await service.AssignClassificationToEntity<Warehouse>(WarehouseId, ClassificationId);
return SuccessfullyAssigned ? Ok() : BadRequest();
}
[HttpPut("Location")]
public async Task<IActionResult> AssignClassificationToLocation([FromQuery] int LocationId, [FromBody] int ClassificationId)
{
// [HttpPut("Warehouse")]
// public async Task<IActionResult> AssignClassificationToWarehouse([FromQuery] int WarehouseId, [FromQuery] int ClassificationId)
// {
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Warehouse>(WarehouseId, ClassificationId);
// return SuccessfullyAssigned ? Ok() : BadRequest();
// }
// [HttpPut("Location")]
// public async Task<IActionResult> AssignClassificationToLocation([FromQuery] int LocationId, [FromBody] int ClassificationId)
// {

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

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

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

var SuccessfullyAssigned = await service.AssignClassificationToEntity<Item>(ItemId, ClassificationId);
return SuccessfullyAssigned ? Ok() : BadRequest();
}
}
}
// var SuccessfullyAssigned = await service.AssignClassificationToEntity<Item>(ItemId, ClassificationId);
// return SuccessfullyAssigned ? Ok() : BadRequest();
// }
// }
// }
16 changes: 14 additions & 2 deletions CargoHub/Controllers/MigrationsController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using CargoHub.Services;
using CsvHelper;
using System.Globalization;
using Microsoft.AspNetCore.Components.Web;

namespace CargoHub.Controllers
{
Expand All @@ -16,9 +19,18 @@ public MigrationsController(MigrationsService Migrate)
[HttpPost()]
public async Task<IActionResult> Migrate([FromQuery] string FolderName)
{
var files = MigrationService.ReadDataFolder(FolderName);
return Ok($"Files transfered:\n${files}");
// Get the absolute path using a known directory (e.g., Logs)
var logFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Logs", MigrationService.ReadDataFolder(FolderName));

if (string.IsNullOrEmpty(logFilePath) || !System.IO.File.Exists(logFilePath))
{
return NotFound("File not found");
}
byte[] fileBytes = await System.IO.File.ReadAllBytesAsync(logFilePath);

return File(fileBytes, "application/octet-stream", Path.GetFileName(logFilePath));
}

}

}
18 changes: 9 additions & 9 deletions CargoHub/Controllers/MonthlyReportController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using CargoHub.Services;

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

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

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

return Ok();
return File(csvBytes, "text/csv", fileName);
}
else
{
return NotFound(new { message = "Report not found." });
return NotFound(new { message = "No data available for the specified month and year." });
}
}
}
}
}
122 changes: 83 additions & 39 deletions CargoHub/Controllers/OrdersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ public async Task<ActionResult<OrderWithItemsDTO>> GetOrder(int id)
return Ok(order);
}

// GET /orders/{orderId}/items
[HttpGet("{orderId}/items")]
public async Task<IActionResult> GetOrderItems(int orderId)
{
try
{
var items = await _orderService.GetOrderItems(orderId);
return Ok(items);
}
catch (Exception ex)
{
return NotFound(new { message = ex.Message });
}
}

[HttpGet("client/{clientId}")]
public async Task<ActionResult<List<Order>>> GetOrdersForClient(int clientId)
{
Expand Down Expand Up @@ -88,46 +103,75 @@ public async Task<ActionResult<List<Order>>> GetOrderForStatus(string status)
}

[HttpPost]
public async Task<ActionResult<Order>> CreateOrder([FromBody] OrderWithItemsDTO orderDto)
{
if (orderDto == null)
{
return BadRequest("Ordergegevens zijn verplicht.");
}
[HttpPost]
public async Task<ActionResult<OrderWithItemsDTO>> CreateOrder([FromBody] OrderWithItemsDTO orderDto)
{
if (orderDto == null)
{
return BadRequest("Ordergegevens zijn verplicht.");
}

try
{
var order = new Order
{
SourceId = orderDto.SourceId,
OrderDate = orderDto.OrderDate,
RequestDate = orderDto.RequestDate,
Reference = orderDto.Reference,
ExtrReference = orderDto.ReferenceExtra,
OrderStatus = orderDto.OrderStatus,
Notes = orderDto.Notes,
ShippingNotes = orderDto.ShippingNotes,
PickingNotes = orderDto.PickingNotes,
WarehouseId = orderDto.WarehouseId ?? null,
ShipTo = orderDto.ShipTo ?? null,
BillTo = orderDto.BillTo ?? null,
ShipmentId = orderDto.ShipmentId ?? null,
TotalAmount = orderDto.TotalAmount,
TotalDiscount = orderDto.TotalDiscount,
TotalTax = orderDto.TotalTax,
TotalSurcharge = orderDto.TotalSurcharge,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};

var createdOrder = await _orderService.CreateOrder(order, orderDto.Items);
return CreatedAtAction(nameof(GetOrder), new { id = createdOrder.Id }, createdOrder);
}
catch (Exception ex)
{
return StatusCode(500, $"Interne serverfout: {ex.Message}");
}
}
try
{
var order = new Order
{
SourceId = orderDto.SourceId,
OrderDate = orderDto.OrderDate,
RequestDate = orderDto.RequestDate,
Reference = orderDto.Reference,
ExtrReference = orderDto.ReferenceExtra,
OrderStatus = orderDto.OrderStatus,
Notes = orderDto.Notes,
ShippingNotes = orderDto.ShippingNotes,
PickingNotes = orderDto.PickingNotes,
WarehouseId = orderDto.WarehouseId ?? null,
ShipTo = orderDto.ShipTo ?? null,
BillTo = orderDto.BillTo ?? null,
ShipmentId = orderDto.ShipmentId ?? null,
TotalAmount = orderDto.TotalAmount,
TotalDiscount = orderDto.TotalDiscount,
TotalTax = orderDto.TotalTax,
TotalSurcharge = orderDto.TotalSurcharge,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};

// Maak de order aan via de service
var createdOrder = await _orderService.CreateOrder(order, orderDto.Items);

// Map de gemaakte order naar een DTO
var createdOrderDto = new OrderWithItemsDTO
{
Id = createdOrder.Id,
SourceId = createdOrder.SourceId,
OrderDate = createdOrder.OrderDate,
RequestDate = createdOrder.RequestDate,
Reference = createdOrder.Reference,
ReferenceExtra = createdOrder.ExtrReference,
OrderStatus = createdOrder.OrderStatus,
Notes = createdOrder.Notes,
ShippingNotes = createdOrder.ShippingNotes,
PickingNotes = createdOrder.PickingNotes,
WarehouseId = createdOrder.WarehouseId,
ShipTo = createdOrder.ShipTo,
BillTo = createdOrder.BillTo,
ShipmentId = createdOrder.ShipmentId,
TotalAmount = createdOrder.TotalAmount,
TotalDiscount = createdOrder.TotalDiscount,
TotalTax = createdOrder.TotalTax,
TotalSurcharge = createdOrder.TotalSurcharge,
CreatedAt = createdOrder.CreatedAt,
UpdatedAt = createdOrder.UpdatedAt,
Items = orderDto.Items // Aangezien deze al correct zijn aangeleverd
};

return CreatedAtAction(nameof(GetOrder), new { id = createdOrder.Id }, createdOrderDto);
}
catch (Exception ex)
{
return StatusCode(500, $"Interne serverfout: {ex.Message}");
}
}

[HttpPut("{id}/items")]
public async Task<IActionResult> UpdateItemsInOrder(int id, [FromBody] List<ItemDTO> orderItems)
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions CargoHub/Controllers/ShipmentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ public async Task<IActionResult> UpdateShipmentFields(int shipmentId, [FromBody]
}
}

[HttpGet("{shipmentId}/items")]
public async Task<ActionResult<List<ItemDTO>>> GetItemsByShipmentId(int shipmentId)
{
var items = await _shipmentService.GetItemsByShipmentId(shipmentId);

if (items == null)
{
return NotFound($"Shipment met ID {shipmentId} niet gevonden of bevat geen items.");
}

return Ok(items);
}


[HttpDelete("{id}")]
public async Task<IActionResult> DeleteShipment(int id)
{
Expand Down
13 changes: 13 additions & 0 deletions CargoHub/LogTransferData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
File,DateOfTransfer,RowsChanged,TransferTime,Error
../data\clients.json,18-01-25,9820,00:00:02,
../data\inventories.json,18-01-25,11720,00:00:04,
../data\items.json,18-01-25,11720,00:00:08,
../data\item_groups.json,18-01-25,100,00:00:08,
../data\item_lines.json,18-01-25,97,00:00:08,
../data\item_types.json,18-01-25,100,00:00:08,
../data\locations.json,18-01-25,34533,00:00:13,
../data\orders.json,18-01-25,0,00:00:14,Error: The entity type 'JsonOrder' was not found. Ensure that the entity type has been added to the model.
../data\shipments.json,18-01-25,0,00:00:14,Error: The entity type 'JsonShipment' was not found. Ensure that the entity type has been added to the model.
../data\suppliers.json,18-01-25,497,00:00:14,
../data\transfers.json,18-01-25,119240,00:00:39,
../data\warehouses.json,18-01-25,58,00:00:39,
Loading

0 comments on commit 52034de

Please sign in to comment.