Skip to content

Commit

Permalink
Merge pull request #55 from Adel-Atzouza/mark
Browse files Browse the repository at this point in the history
Mark
  • Loading branch information
mark-175 authored Jan 20, 2025
2 parents 88c1ff2 + 0a34cc7 commit 8185baf
Show file tree
Hide file tree
Showing 25 changed files with 592 additions and 509 deletions.
13 changes: 0 additions & 13 deletions CargoHub/LogTransferData.csv

This file was deleted.

27 changes: 18 additions & 9 deletions CargoHub/Models/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@ namespace CargoHub.Models
{
public class Client : BaseModel
{
public required string Name { get; set; }
public required string Address { get; set; }
public required string City { get; set; }
[JsonPropertyName("name")]
public required string? Name { get; set; }
[JsonPropertyName("address")]

public required string? Address { get; set; }
[JsonPropertyName("city")]

public required string? City { get; set; }
[JsonPropertyName("zip_code")]
public required string ZipCode { get; set; }
public required string Province { get; set; }
public required string Country { get; set; }
public required string? ZipCode { get; set; }
[JsonPropertyName("province")]

public required string? Province { get; set; }
[JsonPropertyName("country")]

public required string? Country { get; set; }
[JsonPropertyName("contact_name")]
public required string ContactName { get; set; }
public required string? ContactName { get; set; }
[JsonPropertyName("contact_phone")]
public required string ContactPhone { get; set; }
public required string? ContactPhone { get; set; }
[JsonPropertyName("contact_email")]
public required string ContactEmail { get; set; }
public required string? ContactEmail { get; set; }
}
}
21 changes: 11 additions & 10 deletions CargoHub/Models/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,32 @@ public class Inventory : BaseModel
{

[JsonPropertyName("item_id")]
public required string ItemId { get; set; }

public required string Description { get; set; }
public required string? ItemId { get; set; }
[JsonPropertyName("description")]

public required string? Description { get; set; }

[JsonPropertyName("item_reference")]
public required string ItemReference { get; set; }
public required string? ItemReference { get; set; }
[JsonPropertyName("locations")]
[NotMapped]
public required List<int> LocationIds { get; set; } = [];
public required List<int?> LocationIds { get; set; } = [];
[JsonIgnore]
public ICollection<Location> Locations { get; set; } = [];

[JsonPropertyName("total_on_hand")]
public required int TotalOnHand { get; set; }
public required int? TotalOnHand { get; set; }

[JsonPropertyName("total_expected")]
public required int TotalExpected { get; set; }
public required int? TotalExpected { get; set; }

[JsonPropertyName("total_ordered")]
public required int TotalOrdered { get; set; }
public required int? TotalOrdered { get; set; }

[JsonPropertyName("total_allocated")]
public required int TotalAllocated { get; set; }
public required int? TotalAllocated { get; set; }

[JsonPropertyName("total_available")]
public required int TotalAvailable { get; set; }
public required int? TotalAvailable { get; set; }
}
}
18 changes: 9 additions & 9 deletions CargoHub/Models/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ public class Item : BaseModel, IContainsClassification
[Key]
[JsonPropertyName("uid")]

public string Uid { get; set; } = string.Empty;
public string? Uid { get; set; } = string.Empty;
[JsonPropertyName("code")]

public required string Code { get; set; }
public required string? Code { get; set; }
[JsonPropertyName("description")]
public required string Description { get; set; }
public required string? Description { get; set; }

[JsonPropertyName("short_description")]
public required string ShortDescription { get; set; }
public required string? ShortDescription { get; set; }

[JsonPropertyName("upc_code")]
public required string UpcCode { get; set; }
public required string? UpcCode { get; set; }

[JsonPropertyName("model_number")]
public required string ModelNumber { get; set; }
public required string? ModelNumber { get; set; }

[JsonPropertyName("commodity_code")]
public required string CommodityCode { get; set; }
public required string? CommodityCode { get; set; }

[JsonPropertyName("item_line")]
public required int ItemLine { get; set; }
Expand All @@ -55,10 +55,10 @@ public class Item : BaseModel, IContainsClassification
public required int SupplierId { get; set; }

[JsonPropertyName("supplier_code")]
public required string SupplierCode { get; set; }
public required string? SupplierCode { get; set; }

[JsonPropertyName("supplier_part_number")]
public required string SupplierPartNumber { get; set; }
public required string? SupplierPartNumber { get; set; }

[JsonIgnore]
public List<Classification> Classifications { get; set; } = [];
Expand Down
7 changes: 5 additions & 2 deletions CargoHub/Models/ItemGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ namespace CargoHub.Models
{
public class ItemGroup : BaseModel
{
public required string Name {get;set;}
public required string Description {get;set;}
[JsonPropertyName("name")]
public required string? Name {get;set;}
[JsonPropertyName("description")]

public required string? Description {get;set;}
}
}
8 changes: 6 additions & 2 deletions CargoHub/Models/ItemLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ namespace CargoHub.Models
{
public class ItemLine : BaseModel
{
public required string Name {get;set;}
public required string Description {get;set;}
[JsonPropertyName("name")]

public required string? Name {get;set;}
[JsonPropertyName("description")]

public required string? Description {get;set;}
}
}
8 changes: 6 additions & 2 deletions CargoHub/Models/ItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ namespace CargoHub.Models

public class ItemType : BaseModel
{
public required string Name {get;set;}
public required string Description {get;set;}
[JsonPropertyName("name")]

public required string? Name {get;set;}
[JsonPropertyName("description")]

public required string? Description {get;set;}
}
}

4 changes: 3 additions & 1 deletion CargoHub/Models/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class Location : BaseModel, IContainsClassification
public string? Code { get; set; } // Nullable based on provided JSON
[JsonIgnore]
public ICollection<Inventory> Inventories { get; } = [];
public required string Name { get; set; }
[JsonPropertyName("name")]

public required string? Name { get; set; }
[JsonIgnore]
public List<Classification> Classifications { get; set; } = [];
}
Expand Down
1 change: 1 addition & 0 deletions CargoHub/Models/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Order : IContainsClassification
// Avoid serializing the OrderItems navigation property

public List<OrderItem>? OrderItems { get; set; } = new List<OrderItem>();
[JsonIgnore]
public List<Classification> Classifications { get; set; } = [];
[JsonPropertyOrder(-1)]
[JsonPropertyName("id")]
Expand Down
6 changes: 4 additions & 2 deletions CargoHub/Models/Supplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ public class Supplier : BaseModel, IContainsClassification
[JsonPropertyName("address")]

public required string? Address { get; set; }


[JsonPropertyName("address_extra")]
public required string? AddressExtra { get; set; }
[JsonPropertyName("city")]
public required string? City { get; set; }

[JsonPropertyName("zip_code")]
public required string? ZipCode { get; set; }
[JsonPropertyName("province")]
Expand All @@ -25,7 +28,6 @@ public class Supplier : BaseModel, IContainsClassification
[JsonPropertyName("country")]

public required string? Country { get; set; }

[JsonPropertyName("contact_name")]
public required string? ContactName { get; set; }
[JsonPropertyName("phonenumber")]
Expand All @@ -37,4 +39,4 @@ public class Supplier : BaseModel, IContainsClassification
[JsonIgnore]
public List<Classification> Classifications { get; set; } = [];
}
}
}
10 changes: 6 additions & 4 deletions CargoHub/Models/Transfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ namespace CargoHub.Models
{
public class Transfer : BaseModel, IContainsClassification
{
public required string Reference { get; set; }
[JsonPropertyName("reference")]

public required string? Reference { get; set; }
[JsonPropertyName("transfer_from")]
public required int TransferFrom { get; set; }
public required int? TransferFrom { get; set; }
[JsonPropertyName("transfer_to")]
public required int TransferTo { get; set; }
public required int? TransferTo { get; set; }
[JsonPropertyName("transfer_status")]
public required string TransferStatus { get; set; }
public string? TransferStatus { get; set; }

// Items list for JSON serialization/deserialization
[NotMapped]
Expand Down
8 changes: 4 additions & 4 deletions CargoHub/Models/TransferData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ namespace CargoHub.Models

public class TransferData
{
public string File { get; set; }
public string DateOfTransfer { get; set; }
public string? File { get; set; }
public string? DateOfTransfer { get; set; }
public int RowsChanged { get; set; }
public string TransferTime { get; set; }
public string Error { get; set; }
public string? TransferTime { get; set; }
public string? Error { get; set; }

public TransferData(string file, string dateOfTransfer, int rows, string transferTime, string error)
{
Expand Down
37 changes: 26 additions & 11 deletions CargoHub/Models/Warehouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,36 @@ namespace CargoHub.Models
{
public class Warehouse : BaseModel, IContainsClassification
{
public required string Code { get; set; }
public required string Name { get; set; }
public required string Address { get; set; }
public required string Zip { get; set; }
public required string City { get; set; }
public required string Province { get; set; }
public required string Country { get; set; }
[JsonPropertyName("code")]

public required string? Code { get; set; }
[JsonPropertyName("name")]

public required string? Name { get; set; }
[JsonPropertyName("address")]

public required string? Address { get; set; }
[JsonPropertyName("zip")]

public required string? Zip { get; set; }
[JsonPropertyName("city")]

public required string? City { get; set; }
[JsonPropertyName("province")]

public required string? Province { get; set; }
[JsonPropertyName("country")]

public required string? Country { get; set; }

[JsonIgnore]
public string ContactName { get; set; } = string.Empty;
public string? ContactName { get; set; } = string.Empty;

[JsonIgnore]
public string ContactPhone { get; set; } = string.Empty;
public string? ContactPhone { get; set; } = string.Empty;

[JsonIgnore]
public string ContactEmail { get; set; } = string.Empty;
public string? ContactEmail { get; set; } = string.Empty;

[NotMapped]
// Contact dictionary for JSON serialization/deserialization
Expand All @@ -45,7 +60,7 @@ public class Warehouse : BaseModel, IContainsClassification
}

[JsonIgnore]
public ICollection<Location> Locations { get; } = [];
public ICollection<Location> Locations { get; } = [];
[JsonIgnore]
public List<Classification> Classifications { get; set; } = [];
}
Expand Down
1 change: 1 addition & 0 deletions CargoHub/Rest/Migrate.rest
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

POST {{baseUrl}}?FolderName=data


12 changes: 12 additions & 0 deletions CargoHub/Services/APIKeyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Text;
using CargoHub.Enums;
using CargoHub.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace CargoHub.Services
{
Expand Down Expand Up @@ -39,5 +41,15 @@ public bool VerifyApiKey(string rawApiKey)

return apiKey != null; // Return true if a match is found
}

public async Task<RolesEnum.Roles?> GetRoleForApiKey(string ApiKey)
{
APIKey? key = await _context.APIKeys.FirstOrDefaultAsync(key => key.HashedApiKey == HashString(ApiKey));
if (key != null)
{
return key.UserRole;
}
return null;
}
}
}
39 changes: 39 additions & 0 deletions CargoHub/Services/AuthorizationFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

// using CargoHub.Enums;
// using Microsoft.AspNetCore.Mvc.Filters;

// namespace CargoHub.Services
// {
// public class AuthorizationFilter : Attribute, IAsyncActionFilter
// {
// private readonly Dictionary<RolesEnum.Roles, List<string>> _roles = new Dictionary<RolesEnum.Roles, List<string>>(){
// {RolesEnum.Roles.WarehouseManager, new List<string>(){"api/v2/ItemGroups","api/v2/ItemLines", "api/v2/Warehouses", "api/v2/Locations", "api/v2/ItemTypes", "api/v2/Transfer", "api/v2/Classifications"}},
// {RolesEnum.Roles.FloorManager, new List<string>(){ "api/v2/[Controller]", "", "",}}
// };
// public async Task OnActionExecutionAsync(ActionExecutingContext _context, ActionExecutionDelegate next)
// {
// RolesEnum.Roles[] ApiRoles = []
// var context = _context.HttpContext;
// string? ApiKey = context.Request.Headers["ApiKey"].FirstOrDefault();
// if (ApiKey == null)
// {
// context.Response.StatusCode = 401;
// context.Response.ContentType = "text/plain";
// await context.Response.WriteAsync("Unauthorized: API key is missing.");
// return;
// }
// var apiKeyService = context.RequestServices.GetService<APIKeyService>();
// bool KeyExists = apiKeyService.VerifyApiKey(ApiKey);
// if (!KeyExists)
// {
// context.Response.StatusCode = 401;
// context.Response.ContentType = "text/plain";
// await context.Response.WriteAsync("Unknown or inactive Api key");
// }
// RolesEnum.Roles? UserRole = await apiKeyService.GetRoleForApiKey(ApiKey);
// UserRole.


// }
// }
// }
Loading

0 comments on commit 8185baf

Please sign in to comment.