Skip to content

Commit

Permalink
feat(formats): improve the readability of received models for creatin…
Browse files Browse the repository at this point in the history
…g formats
  • Loading branch information
CarlosPavajeau committed Aug 29, 2021
1 parent d336309 commit e63b793
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Armory.Formats.Shared.Application;
using Armory.Formats.Shared.Domain;

namespace Armory.Api.Controllers.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Requests
Expand All @@ -23,8 +24,8 @@ public class CreateWarMaterialAndSpecialEquipmentAssignmentFormatRequest
public string Others { get; set; }

public ICollection<string> Weapons { get; set; }
public IDictionary<string, int> Ammunition { get; set; }
public IDictionary<string, int> Equipments { get; set; }
public IDictionary<string, int> Explosives { get; set; }
public ICollection<AmmunitionAndQuantity> Ammunition { get; set; }
public ICollection<EquipmentAndQuantity> Equipments { get; set; }
public ICollection<ExplosiveAndQuantity> Explosives { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Armory.Formats.Shared.Application;

namespace Armory.Api.Controllers.Formats.WarMaterialDeliveryCertificateFormats.Requests
{
Expand All @@ -14,9 +15,9 @@ public class CreateWarMaterialDeliveryCertificateFormatRequest
public string SquadCode { get; set; }
public string TroopId { get; set; }

public ICollection<string> Weapons { get; set; } = new HashSet<string>();
public IDictionary<string, int> Ammunition { get; set; } = new Dictionary<string, int>();
public IDictionary<string, int> Equipments { get; set; } = new Dictionary<string, int>();
public IDictionary<string, int> Explosives { get; set; } = new Dictionary<string, int>();
public ICollection<string> Weapons { get; set; }
public ICollection<AmmunitionAndQuantity> Ammunition { get; set; }
public ICollection<EquipmentAndQuantity> Equipments { get; set; }
public ICollection<ExplosiveAndQuantity> Explosives { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Armory.Formats.Shared.Application
{
public class AmmunitionAndQuantity
{
public string AmmunitionCode { get; init; }
public int Quantity { get; init; }
}
}
8 changes: 8 additions & 0 deletions src/Armory/Formats/Shared/Application/EquipmentAndQuantity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Armory.Formats.Shared.Application
{
public class EquipmentAndQuantity
{
public string EquipmentCode { get; init; }
public int Quantity { get; init; }
}
}
8 changes: 8 additions & 0 deletions src/Armory/Formats/Shared/Application/ExplosiveAndQuantity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Armory.Formats.Shared.Application
{
public class ExplosiveAndQuantity
{
public string ExplosiveCode { get; init; }
public int Quantity { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Armory.Formats.Shared.Application;
using Armory.Formats.Shared.Domain;
using Armory.Shared.Domain.Bus.Command.Generic;

Expand Down Expand Up @@ -41,9 +42,9 @@ public CreateWarMaterialAndSpecialEquipmentAssignmentFormatCommand(string code,
public string PhysicalLocation { get; }
public string Others { get; }

public ICollection<string> Weapons { get; } = new HashSet<string>();
public IDictionary<string, int> Ammunition { get; } = new Dictionary<string, int>();
public IDictionary<string, int> Equipments { get; } = new Dictionary<string, int>();
public IDictionary<string, int> Explosives { get; } = new Dictionary<string, int>();
public IEnumerable<string> Weapons { get; } = new HashSet<string>();
public IEnumerable<AmmunitionAndQuantity> Ammunition { get; } = new HashSet<AmmunitionAndQuantity>();
public IEnumerable<EquipmentAndQuantity> Equipments { get; } = new HashSet<EquipmentAndQuantity>();
public IEnumerable<ExplosiveAndQuantity> Explosives { get; } = new HashSet<ExplosiveAndQuantity>();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Armory.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Application.Generate;
Expand Down Expand Up @@ -36,9 +37,9 @@ public async Task<int> Handle(CreateWarMaterialAndSpecialEquipmentAssignmentForm
request.PhysicalLocation,
request.Others,
request.Weapons,
request.Ammunition,
request.Equipments,
request.Explosives);
request.Ammunition.ToDictionary(c => c.AmmunitionCode, c => c.Quantity),
request.Equipments.ToDictionary(c => c.EquipmentCode, c => c.Quantity),
request.Explosives.ToDictionary(c => c.ExplosiveCode, c => c.Quantity));

return format.Id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Armory.Formats.Shared.Application;
using Armory.Shared.Domain.Bus.Command.Generic;

namespace Armory.Formats.WarMaterialDeliveryCertificateFormats.Application.Create
Expand Down Expand Up @@ -27,9 +28,9 @@ public CreateWarMaterialDeliveryCertificateFormatCommand(string code, DateTime v
public string SquadCode { get; }
public string TroopId { get; }

public ICollection<string> Weapons { get; } = new HashSet<string>();
public IDictionary<string, int> Ammunition { get; } = new Dictionary<string, int>();
public IDictionary<string, int> Equipments { get; } = new Dictionary<string, int>();
public IDictionary<string, int> Explosives { get; } = new Dictionary<string, int>();
public IEnumerable<string> Weapons { get; } = new HashSet<string>();
public IEnumerable<AmmunitionAndQuantity> Ammunition { get; } = new HashSet<AmmunitionAndQuantity>();
public IEnumerable<EquipmentAndQuantity> Equipments { get; } = new HashSet<EquipmentAndQuantity>();
public IEnumerable<ExplosiveAndQuantity> Explosives { get; } = new HashSet<ExplosiveAndQuantity>();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Armory.Shared.Domain.Bus.Command;
Expand Down Expand Up @@ -28,9 +29,9 @@ public async Task<int> Handle(CreateWarMaterialDeliveryCertificateFormatCommand
request.SquadCode,
request.TroopId,
request.Weapons,
request.Ammunition,
request.Equipments,
request.Explosives);
request.Ammunition.ToDictionary(c => c.AmmunitionCode, c => c.Quantity),
request.Equipments.ToDictionary(c => c.EquipmentCode, c => c.Quantity),
request.Explosives.ToDictionary(c => c.ExplosiveCode, c => c.Quantity));

return format.Id;
}
Expand Down

0 comments on commit e63b793

Please sign in to comment.