-
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
6f22e33
commit 84d82c8
Showing
6 changed files
with
92 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
15 changes: 15 additions & 0 deletions
15
src/Spix.Application/Spixers/Delete/DeleteSpixerCommand.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,15 @@ | ||
using Spix.Application.Core; | ||
|
||
namespace Spix.Application.Spixers.Delete; | ||
|
||
public class DeleteSpixerCommand : ICommandBase<DeleteSpixerResponse> | ||
{ | ||
public Guid UserId { get; set; } | ||
public Guid SpixerId { get; set; } | ||
|
||
public DeleteSpixerCommand(Guid userId, Guid spixerId) | ||
{ | ||
UserId = userId; | ||
SpixerId = spixerId; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Spix.Application/Spixers/Delete/DeleteSpixerCommandHandler.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,37 @@ | ||
using Spix.Application.Core; | ||
using Spix.Domain.Spixers; | ||
|
||
namespace Spix.Application.Spixers.Delete; | ||
|
||
public class DeleteSpixerCommandHandler : ICommandHandlerBase<DeleteSpixerCommand, DeleteSpixerResponse> | ||
{ | ||
private readonly ISpixerRepository _spixerRepository; | ||
|
||
public DeleteSpixerCommandHandler(ISpixerRepository spixerRepository) | ||
{ | ||
_spixerRepository = spixerRepository; | ||
} | ||
|
||
public async Task<ResultBase<DeleteSpixerResponse>> Handle(DeleteSpixerCommand request, CancellationToken cancellationToken) | ||
{ | ||
|
||
var spixer = await _spixerRepository.GetByIdAsync(request.SpixerId); | ||
if (spixer == null) | ||
{ | ||
return ResultBaseFactory.Failure<DeleteSpixerResponse>("Spixer not found"); | ||
} | ||
|
||
if (spixer.UserId != request.UserId) | ||
{ | ||
return ResultBaseFactory.Failure<DeleteSpixerResponse>("User not authorized to delete this spixer"); | ||
} | ||
|
||
spixer.Delete(); | ||
await _spixerRepository.UpdateAsync(spixer); | ||
if (!await _spixerRepository.UnitOfWork.CommitAsync(cancellationToken)) | ||
{ | ||
return ResultBaseFactory.Failure<DeleteSpixerResponse>("Error deleting spixer"); | ||
} | ||
return ResultBaseFactory.Successful(new DeleteSpixerResponse { DeletedAt = DateTime.UtcNow }, "Success"); | ||
} | ||
} |
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,6 @@ | ||
namespace Spix.Application.Spixers.Delete; | ||
|
||
public class DeleteSpixerResponse | ||
{ | ||
public DateTime DeletedAt { 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
File renamed without changes.