-
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.
Merge remote-tracking branch 'origin/main'
# Conflicts: # src/dotnetLab.Database.SampleDb/dotnetLab.Database.SampleDb.csproj # src/dotnetLab.Repository/dotnetLab.Repository.csproj # src/dotnetLab.WebApi/dotnetLab.WebApi.csproj
- Loading branch information
Showing
15 changed files
with
204 additions
and
15 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/dotnetLab.DomainEntity/Events/SimpleDocumentDescriptionUpdatedEvent.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 Mediator; | ||
|
||
namespace dotnetLab.DomainEntity.Events; | ||
|
||
public record SimpleDocumentDescriptionUpdatedEvent : INotification | ||
{ | ||
public int SerialId { get; set; } | ||
public string? OldDescription { get; set; } | ||
public string? NewDescription { 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
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
17 changes: 17 additions & 0 deletions
17
src/dotnetLab.UseCase/SimpleDocument/Commands/UpdateSimpleDocumentDescriptionCommand.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,17 @@ | ||
namespace dotnetLab.UseCase.SimpleDocument.Commands; | ||
|
||
/// <summary> | ||
/// sample command | ||
/// </summary> | ||
public class UpdateSimpleDocumentDescriptionCommand : IRequest<bool> | ||
{ | ||
/// <summary> | ||
/// 序號 | ||
/// </summary> | ||
public int SerialId { get; set; } | ||
|
||
/// <summary> | ||
/// 敘述 | ||
/// </summary> | ||
public string? Description { get; set; } | ||
} |
40 changes: 40 additions & 0 deletions
40
...otnetLab.UseCase/SimpleDocument/Commands/UpdateSimpleDocumentDescriptionCommandHandler.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,40 @@ | ||
using dotnetLab.UseCase.SimpleDocument.Ports.Out; | ||
|
||
namespace dotnetLab.UseCase.SimpleDocument.Commands; | ||
|
||
/// <summary> | ||
/// command handler | ||
/// </summary> | ||
public class UpdateSimpleDocumentDescriptionCommandHandler : IRequestHandler<UpdateSimpleDocumentDescriptionCommand, bool> | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly ISimpleDocumentRepository _simpleDocumentRepository; | ||
|
||
public UpdateSimpleDocumentDescriptionCommandHandler( | ||
ISimpleDocumentRepository simpleDocumentRepository, | ||
IMediator mediator) | ||
{ | ||
this._simpleDocumentRepository = simpleDocumentRepository; | ||
this._mediator = mediator; | ||
} | ||
|
||
/// <summary>Handles a request</summary> | ||
/// <param name="request">The request</param> | ||
/// <param name="cancellationToken">Cancellation token</param> | ||
/// <returns>Response from the request</returns> | ||
public async ValueTask<bool> Handle(UpdateSimpleDocumentDescriptionCommand request, CancellationToken cancellationToken) | ||
{ | ||
var simpleDocumentEntity = await this._simpleDocumentRepository.GetAsync(request.SerialId); | ||
|
||
if (simpleDocumentEntity is null) | ||
{ | ||
return false; | ||
} | ||
|
||
var @event = simpleDocumentEntity.UpdateDescription(request.Description); | ||
|
||
await this._mediator.Publish(@event, cancellationToken); | ||
|
||
return await this._simpleDocumentRepository.UpdateAsync(simpleDocumentEntity); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/dotnetLab.UseCase/SimpleDocument/Events/PublishUpdatedInformation.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 dotnetLab.DomainEntity.Events; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace dotnetLab.UseCase.SimpleDocument.Events; | ||
|
||
public class PublishUpdatedInformation : INotificationHandler<SimpleDocumentDescriptionUpdatedEvent> | ||
{ | ||
private readonly ILogger<PublishUpdatedInformation> _logger; | ||
|
||
public PublishUpdatedInformation(ILogger<PublishUpdatedInformation> logger) | ||
{ | ||
this._logger = logger; | ||
} | ||
|
||
public ValueTask Handle(SimpleDocumentDescriptionUpdatedEvent notification, CancellationToken cancellationToken) | ||
{ | ||
this._logger.LogInformation($"{DateTime.Now} Simple Document Description was updated!"); | ||
return ValueTask.CompletedTask; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/dotnetLab.UseCase/SimpleDocument/Events/SimpleDocDescUpdatedEventHandler.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 dotnetLab.DomainEntity.Events; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace dotnetLab.UseCase.SimpleDocument.Events; | ||
|
||
public class SimpleDocDescUpdatedEventHandler : INotificationHandler<SimpleDocumentDescriptionUpdatedEvent> | ||
{ | ||
private readonly ILogger<SimpleDocDescUpdatedEventHandler> _logger; | ||
|
||
public SimpleDocDescUpdatedEventHandler(ILogger<SimpleDocDescUpdatedEventHandler> logger) | ||
{ | ||
this._logger = logger; | ||
} | ||
|
||
public ValueTask Handle(SimpleDocumentDescriptionUpdatedEvent notification, CancellationToken cancellationToken) | ||
{ | ||
this._logger.LogInformation($"{DateTime.Now} Simple Document Description was updated!"); | ||
return ValueTask.CompletedTask; | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...dotnetLab.WebApi/Controllers/Validator/UpdateSimpleDocumentDescriptionCommandValidator.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,16 @@ | ||
using dotnetLab.UseCase.SimpleDocument.Commands; | ||
using FluentValidation; | ||
|
||
namespace dotnetLab.WebApi.Controllers.Validator; | ||
|
||
/// <summary> | ||
/// UpdateSimpleDocumentDescriptionCommand 的參數驗證器 | ||
/// </summary> | ||
public class UpdateSimpleDocumentDescriptionCommandValidator : AbstractValidator<UpdateSimpleDocumentDescriptionCommand> | ||
{ | ||
public UpdateSimpleDocumentDescriptionCommandValidator() | ||
{ | ||
this.RuleFor(o => o.Description) | ||
.NotEmpty(); | ||
} | ||
} |