-
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.
feat(degrees): implement degree update
- Loading branch information
1 parent
277c93d
commit 797b3aa
Showing
10 changed files
with
148 additions
and
1 deletion.
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/Degrees/Requests/UpdateDegreeRequest.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.Degrees.Requests | ||
{ | ||
public class UpdateDegreeRequest | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
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
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.Degrees.Domain; | ||
using Armory.Shared.Domain.Persistence.EntityFramework; | ||
|
||
namespace Armory.Degrees.Application.Update | ||
{ | ||
public class DegreeUpdater | ||
{ | ||
private readonly IUnitWork _unitWork; | ||
|
||
public DegreeUpdater(IUnitWork unitWork) | ||
{ | ||
_unitWork = unitWork; | ||
} | ||
|
||
public async Task Update(Degree degree, string newName) | ||
{ | ||
degree.Name = newName; | ||
await _unitWork.SaveChanges(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Armory/Degrees/Application/Update/UpdateDegreeCommand.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,10 @@ | ||
using Armory.Shared.Domain.Bus.Command; | ||
|
||
namespace Armory.Degrees.Application.Update | ||
{ | ||
public class UpdateDegreeCommand : Command | ||
{ | ||
public int Id { get; init; } | ||
public string Name { get; init; } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Armory/Degrees/Application/Update/UpdateDegreeCommandHandler.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.Degrees.Application.Find; | ||
using Armory.Degrees.Domain; | ||
using Armory.Shared.Domain.Bus.Command; | ||
|
||
namespace Armory.Degrees.Application.Update | ||
{ | ||
public class UpdateDegreeCommandHandler : CommandHandler<UpdateDegreeCommand> | ||
{ | ||
private readonly DegreeFinder _finder; | ||
private readonly DegreeUpdater _updater; | ||
|
||
public UpdateDegreeCommandHandler(DegreeFinder finder, DegreeUpdater updater) | ||
{ | ||
_finder = finder; | ||
_updater = updater; | ||
} | ||
|
||
protected override async Task Handle(UpdateDegreeCommand request, CancellationToken cancellationToken) | ||
{ | ||
var degree = await _finder.Find(request.Id, false); | ||
if (degree is null) | ||
{ | ||
throw new DegreeNotFoundException(); | ||
} | ||
|
||
await _updater.Update(degree, 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.Degrees.Domain | ||
{ | ||
/// <summary> | ||
/// Represents error that occur when degree is not found | ||
/// </summary> | ||
public class DegreeNotFoundException : 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