Skip to content

Commit

Permalink
feat(explosives): new changes for explosives
Browse files Browse the repository at this point in the history
* Remove the 'Code' property
* Add relationship with fligths
  • Loading branch information
CarlosPavajeau committed Sep 28, 2021
1 parent 3f1f7c6 commit 4280f1a
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public async Task<IActionResult> RegisterExplosive([FromBody] CreateExplosiveReq
}
catch (DbUpdateException)
{
var exists = await _mediator.Send(new CheckExplosiveExistsQuery(request.Code));
var exists = await _mediator.Send(new CheckExplosiveExistsQuery(request.Serial));
if (!exists)
{
throw;
}

ModelState.AddModelError("ExplosiveAlreadyRegistered",
$"Ya existe un explosivo con el código '{request.Code}'");
$"Ya existe un explosivo con el número de serie '{request.Serial}'");
return Conflict(new ValidationProblemDetails(ModelState));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Armory.Api.Controllers.Armament.Explosives.Requests
{
public class CreateExplosiveRequest
{
[Required(ErrorMessage = "El código del explosivo es requerido.")]
[MaxLength(50, ErrorMessage = "El código del referido no debe tener más de 50 caracteres.")]
public string Code { get; set; }
[Required(ErrorMessage = "El número de serie del explosivo es requerido.")]
[MaxLength(256, ErrorMessage = "El número de serie del explosivo no debe tener más de 256 caracteres.")]
public string Serial { get; set; }

[Required(ErrorMessage = "El tipo de explosivo es requerido.")]
[MaxLength(128, ErrorMessage = "El tipo de explosivo no debe tener más de 128 caracteres.")]
Expand All @@ -24,11 +24,11 @@ public class CreateExplosiveRequest
[MaxLength(256, ErrorMessage = "El lote del explosivo no debe tener más de 256 caracteres.")]
public string Lot { get; set; }

[Required(ErrorMessage = "El número de serie del explosivo es requerido.")]
[MaxLength(256, ErrorMessage = "El número de serie del explosivo no debe tener más de 256 caracteres.")]
public string Series { get; set; }

[Required(ErrorMessage = "La cantidad disponible del explosivo es requerida.")]
public int QuantityAvailable { get; set; }

[Required(ErrorMessage = "El código de la escuadrilla del arma es requerida.")]
[MaxLength(50, ErrorMessage = "El código de la escuadrilla no debe tener más de 50 caracteres.")]
public string FlightCode { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public ExplosiveExistsChecker(IExplosivesRepository repository)
_repository = repository;
}

public async Task<bool> Exists(string code)
public async Task<bool> Exists(string serial)
{
return await _repository.Any(e => e.Code == code);
return await _repository.Any(e => e.Serial == serial);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@ namespace Armory.Armament.Explosives.Application.Create
{
public class CreateExplosiveCommand : Command
{
public CreateExplosiveCommand(string code, string type, string caliber, string mark, string lot, string series,
int quantityAvailable)
{
Code = code;
Type = type;
Caliber = caliber;
Mark = mark;
Lot = lot;
Series = series;
QuantityAvailable = quantityAvailable;
}

public string Code { get; }
public string Type { get; }
public string Caliber { get; }
public string Mark { get; }
public string Lot { get; }
public string Series { get; }
public int QuantityAvailable { get; }
public string Serial { get; init; }
public string Type { get; init; }
public string Caliber { get; init; }
public string Mark { get; init; }
public string Lot { get; init; }
public int QuantityAvailable { get; init; }
public string FlightCode { get; set; }
}
}
16 changes: 10 additions & 6 deletions src/Armory/Armament/Explosives/Domain/Explosive.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Armory.Flights.Domain;
using Armory.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Domain;
using Armory.Formats.WarMaterialDeliveryCertificateFormats.Domain;

namespace Armory.Armament.Explosives.Domain
{
public class Explosive
{
public Explosive(string code, string type, string caliber, string mark, string lot, string series,
public Explosive(string type, string caliber, string mark, string lot, string serial,
int quantityAvailable)
{
Code = code;
Type = type;
Caliber = caliber;
Mark = mark;
Lot = lot;
Series = series;
Serial = serial;
QuantityAvailable = quantityAvailable;
}

[Key] [MaxLength(50)] public string Code { get; set; }

[Key] [MaxLength(256)] public string Serial { get; set; }
[Required] [MaxLength(128)] public string Type { get; set; }
[Required] [MaxLength(256)] public string Caliber { get; set; }
[Required] [MaxLength(256)] public string Mark { get; set; }
[Required] [MaxLength(256)] public string Lot { get; set; }
[Required] [MaxLength(256)] public string Series { get; set; }
[Required] public int QuantityAvailable { get; set; }

public string FlightCode { get; set; }
[ForeignKey("FlightCode")] public Flight Flight { get; set; }

public ICollection<WarMaterialAndSpecialEquipmentAssignmentFormatExplosive>
WarMaterialAndSpecialEquipmentAssignmentFormatExplosives { get; set; } =
new HashSet<WarMaterialAndSpecialEquipmentAssignmentFormatExplosive>();
Expand All @@ -41,7 +45,7 @@ public void Update(string type, string caliber, string mark, string lot, string
Caliber = caliber;
Mark = mark;
Lot = lot;
Series = series;
Serial = series;
QuantityAvailable = quantityAvailable;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Armory.Armament.Explosives.Domain
public interface IExplosivesRepository
{
Task Save(Explosive explosive);
Task<Explosive> Find(string code, bool noTracking);
Task<Explosive> Find(string code);
Task<Explosive> Find(string serial, bool noTracking);
Task<Explosive> Find(string serial);
Task<IEnumerable<Explosive>> SearchAll(bool noTracking);
Task<IEnumerable<Explosive>> SearchAll();
Task<bool> Any(Expression<Func<Explosive, bool>> predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public async Task Save(Explosive explosive)
await _context.SaveChangesAsync();
}

public async Task<Explosive> Find(string code, bool noTracking)
public async Task<Explosive> Find(string serial, bool noTracking)
{
var query = noTracking ? _context.Explosives.AsNoTracking() : _context.Explosives.AsTracking();

return await query.FirstOrDefaultAsync(e => e.Code == code);
return await query.FirstOrDefaultAsync(e => e.Serial == serial);
}

public async Task<Explosive> Find(string code)
public async Task<Explosive> Find(string serial)
{
return await Find(code, true);
return await Find(serial, true);
}

public async Task<IEnumerable<Explosive>> SearchAll(bool noTracking)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class ExplosiveAndQuantity
{
public string ExplosiveCode { get; init; }
public string ExplosiveSerial { get; init; }
public int Quantity { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<int> Handle(CreateWarMaterialAndSpecialEquipmentAssignmentForm
request.Weapons,
request.Ammunition.ToDictionary(c => c.AmmunitionCode, c => c.Quantity),
request.Equipments.ToDictionary(c => c.EquipmentSeries, c => c.Quantity),
request.Explosives.ToDictionary(c => c.ExplosiveCode, c => c.Quantity));
request.Explosives.ToDictionary(c => c.ExplosiveSerial, c => c.Quantity));

return format.Id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private int MakeSpecialEquipmentAndExplosivesInfo(IXLWorksheet worksheet,
var explosive = format.Explosives.ElementAt(i);
var explosiveFormat =
format.WarMaterialAndSpecialEquipmentAssignmentFormatExplosives.First(x =>
x.ExplosiveCode == explosive.Code);
x.ExplosiveSerial == explosive.Serial);

_worksheetManager.SetRangeValues(worksheet.Range($"H{previousEnd + i}:M{previousEnd + i}"),
new List<string>
Expand All @@ -237,7 +237,7 @@ private int MakeSpecialEquipmentAndExplosivesInfo(IXLWorksheet worksheet,
explosive.Caliber,
explosive.Mark,
explosive.Lot,
explosive.Series,
explosive.Serial,
explosiveFormat.Quantity.ToString()
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public static WarMaterialAndSpecialEquipmentAssignmentFormat Create(string code,
WarMaterialAndSpecialEquipmentAssignmentFormatEquipment.Create(format, equipmentSeries, quantity));
}

foreach (var (explosiveCode, quantity) in explosives)
foreach (var (explosiveSerial, quantity) in explosives)
{
format.WarMaterialAndSpecialEquipmentAssignmentFormatExplosives.Add(
WarMaterialAndSpecialEquipmentAssignmentFormatExplosive.Create(format, explosiveCode, quantity));
WarMaterialAndSpecialEquipmentAssignmentFormatExplosive.Create(format, explosiveSerial, quantity));
}

format.Record(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace Armory.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Domain
public class WarMaterialAndSpecialEquipmentAssignmentFormatExplosive
{
public WarMaterialAndSpecialEquipmentAssignmentFormatExplosive(
WarMaterialAndSpecialEquipmentAssignmentFormat format, string explosiveCode, int quantity)
WarMaterialAndSpecialEquipmentAssignmentFormat format, string explosiveSerial, int quantity)
{
Format = format;
ExplosiveCode = explosiveCode;
ExplosiveSerial = explosiveSerial;
Quantity = quantity;
}

Expand All @@ -22,15 +22,15 @@ private WarMaterialAndSpecialEquipmentAssignmentFormatExplosive()
[ForeignKey("WarMaterialAndSpecialEquipmentAssignmentFormatId")]
public WarMaterialAndSpecialEquipmentAssignmentFormat Format { get; set; }

public string ExplosiveCode { get; set; }
[ForeignKey("ExplosiveCode")] public Explosive Explosive { get; set; }
public string ExplosiveSerial { get; set; }
[ForeignKey("ExplosiveSerial")] public Explosive Explosive { get; set; }

public int Quantity { get; set; }

public static WarMaterialAndSpecialEquipmentAssignmentFormatExplosive Create(
WarMaterialAndSpecialEquipmentAssignmentFormat format, string explosiveCode, int quantity)
WarMaterialAndSpecialEquipmentAssignmentFormat format, string explosiveSerial, int quantity)
{
return new WarMaterialAndSpecialEquipmentAssignmentFormatExplosive(format, explosiveCode, quantity);
return new WarMaterialAndSpecialEquipmentAssignmentFormatExplosive(format, explosiveSerial, quantity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<int> Handle(CreateWarMaterialDeliveryCertificateFormatCommand
request.Weapons,
request.Ammunition.ToDictionary(c => c.AmmunitionCode, c => c.Quantity),
request.Equipments.ToDictionary(c => c.EquipmentSeries, c => c.Quantity),
request.Explosives.ToDictionary(c => c.ExplosiveCode, c => c.Quantity));
request.Explosives.ToDictionary(c => c.ExplosiveSerial, c => c.Quantity));

return format.Id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private int MakeSpecialEquipmentAndExplosivesInfo(IXLWorksheet worksheet,
var explosive = format.Explosives.ElementAt(i);
var explosiveFormat =
format.WarMaterialDeliveryCertificateFormatExplosives.First(x =>
x.ExplosiveCode == explosive.Code);
x.ExplosiveSerial == explosive.Serial);

_worksheetManager.SetRangeValues(worksheet.Range($"H{previousEnd + i}:M{previousEnd + i}"),
new List<string>
Expand All @@ -211,7 +211,7 @@ private int MakeSpecialEquipmentAndExplosivesInfo(IXLWorksheet worksheet,
explosive.Caliber,
explosive.Mark,
explosive.Lot,
explosive.Series,
explosive.Serial,
explosiveFormat.Quantity.ToString()
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public static WarMaterialDeliveryCertificateFormat Create(string code, DateTime
WarMaterialDeliveryCertificateFormatEquipment.Create(format, equipmentSeries, quantity));
}

foreach (var (explosiveCode, quantity) in explosives)
foreach (var (explosiveSerial, quantity) in explosives)
{
format.WarMaterialDeliveryCertificateFormatExplosives.Add(
WarMaterialDeliveryCertificateFormatExplosive.Create(format, explosiveCode, quantity));
WarMaterialDeliveryCertificateFormatExplosive.Create(format, explosiveSerial, quantity));
}

return format;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace Armory.Formats.WarMaterialDeliveryCertificateFormats.Domain
public class WarMaterialDeliveryCertificateFormatExplosive
{
public WarMaterialDeliveryCertificateFormatExplosive(WarMaterialDeliveryCertificateFormat format,
string explosiveCode, int quantity)
string explosiveSerial, int quantity)
{
Format = format;
ExplosiveCode = explosiveCode;
ExplosiveSerial = explosiveSerial;
Quantity = quantity;
}

Expand All @@ -22,15 +22,15 @@ private WarMaterialDeliveryCertificateFormatExplosive()
[ForeignKey("WarMaterialDeliveryCertificateFormatId")]
public WarMaterialDeliveryCertificateFormat Format { get; set; }

public string ExplosiveCode { get; set; }
[ForeignKey("ExplosiveCode")] public Explosive Explosive { get; set; }
public string ExplosiveSerial { get; set; }
[ForeignKey("ExplosiveSerial")] public Explosive Explosive { get; set; }

public int Quantity { get; set; }

public static WarMaterialDeliveryCertificateFormatExplosive Create(WarMaterialDeliveryCertificateFormat format,
string explosiveCode, int quantity)
string explosiveSerial, int quantity)
{
return new WarMaterialDeliveryCertificateFormatExplosive(format, explosiveCode, quantity);
return new WarMaterialDeliveryCertificateFormatExplosive(format, explosiveSerial, quantity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class WarMaterialAndSpecialEquipmentAssignmentFormatExplosiveConfiguratio
{
public void Configure(EntityTypeBuilder<WarMaterialAndSpecialEquipmentAssignmentFormatExplosive> builder)
{
builder.HasKey(f => new { f.WarMaterialAndSpecialEquipmentAssignmentFormatId, f.ExplosiveCode });
builder.HasKey(f => new
{ f.WarMaterialAndSpecialEquipmentAssignmentFormatId, ExplosiveCode = f.ExplosiveSerial });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class
{
public void Configure(EntityTypeBuilder<WarMaterialDeliveryCertificateFormatExplosive> builder)
{
builder.HasKey(f => new { f.WarMaterialDeliveryCertificateFormatId, f.ExplosiveCode });
builder.HasKey(f => new { f.WarMaterialDeliveryCertificateFormatId, ExplosiveCode = f.ExplosiveSerial });
}
}
}

0 comments on commit 4280f1a

Please sign in to comment.