-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83dad59
commit aee511b
Showing
10 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Armory.Api/Controllers/Ranks/Requests/UpdateRankRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Armory.Api.Controllers.Ranks.Requests | ||
{ | ||
public class UpdateRankRequest | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Armory.Api/Controllers/Ranks/Validators/UpdateRankRequestValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Armory.Api.Controllers.Ranks.Requests; | ||
using FluentValidation; | ||
|
||
namespace Armory.Api.Controllers.Ranks.Validators | ||
{ | ||
public class UpdateRankRequestValidator : AbstractValidator<UpdateRankRequest> | ||
{ | ||
public UpdateRankRequestValidator() | ||
{ | ||
RuleFor(m => m.Id) | ||
.NotNull(); | ||
|
||
RuleFor(m => m.Name) | ||
.NotNull() | ||
.NotEmpty() | ||
.MaximumLength(256) | ||
.WithName("Nombre"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Threading.Tasks; | ||
using Armory.Ranks.Domain; | ||
using Armory.Shared.Domain.Persistence.EntityFramework; | ||
|
||
namespace Armory.Ranks.Application.Update | ||
{ | ||
public class RankUpdater | ||
{ | ||
private readonly IUnitWork _unitWork; | ||
|
||
public RankUpdater(IUnitWork unitWork) | ||
{ | ||
_unitWork = unitWork; | ||
} | ||
|
||
public async Task Update(Rank rank, string newName) | ||
{ | ||
rank.Name = newName; | ||
await _unitWork.SaveChanges(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Armory.Shared.Domain.Bus.Command; | ||
|
||
namespace Armory.Ranks.Application.Update | ||
{ | ||
public class UpdateRankCommand : Command | ||
{ | ||
public int Id { get; init; } | ||
public string Name { get; init; } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Armory/Ranks/Application/Update/UpdateRankCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Armory.Ranks.Application.Find; | ||
using Armory.Ranks.Domain; | ||
using Armory.Shared.Domain.Bus.Command; | ||
|
||
namespace Armory.Ranks.Application.Update | ||
{ | ||
public class UpdateRankCommandHandler : CommandHandler<UpdateRankCommand> | ||
{ | ||
private readonly RankFinder _finder; | ||
private readonly RankUpdater _updater; | ||
|
||
public UpdateRankCommandHandler(RankFinder finder, RankUpdater updater) | ||
{ | ||
_finder = finder; | ||
_updater = updater; | ||
} | ||
|
||
protected override async Task Handle(UpdateRankCommand request, CancellationToken cancellationToken) | ||
{ | ||
var rank = await _finder.Find(request.Id); | ||
if (rank is null) | ||
{ | ||
throw new RankNotFoundException(); | ||
} | ||
|
||
await _updater.Update(rank, request.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Armory.Shared.Domain; | ||
|
||
namespace Armory.Ranks.Domain | ||
{ | ||
/// <summary> | ||
/// Represents errors that occur when rank is not found | ||
/// </summary> | ||
public class RankNotFoundException : ArmoryException | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters