Skip to content

Commit

Permalink
refactor: 將 IGameExistenceInquiry 中的方法改為非同步並更新對應實作
Browse files Browse the repository at this point in the history
  • Loading branch information
aa89227 committed Sep 26, 2024
1 parent 3d8eb00 commit 61edbe0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public record Request(string GameId) : BaseRequest;

public record Response(bool IsExist) : Common.Response;

public override Task ExecuteAsync(Request request,
public override async Task ExecuteAsync(Request request,
IPresenter<Response> presenter,
CancellationToken cancellationToken = default)
{
var isExist = inquiry.CheckGameExistence(request.GameId);
return presenter.PresentAsync(new Response(isExist), cancellationToken);
var isExist = await inquiry.CheckGameExistenceAsync(request.GameId);
await presenter.PresentAsync(new Response(isExist), cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
namespace Monopoly.ApplicationLayer.Application.MonopolyUsecases.Queries.Interfaces;

/// <summary>
/// 用來確認遊戲是否存在的查詢介面
/// </summary>
public interface IGameExistenceInquiry
{
bool CheckGameExistence(string gameId);
/// <summary>
/// 確認遊戲是否存在
/// </summary>
/// <param name="gameId">遊戲 Id</param>
/// <returns>當遊戲存在則回傳 true</returns>
Task<bool> CheckGameExistenceAsync(string gameId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Monopoly.InterfaceAdapterLayer.Server.Repositories.Inquiries;
/// <inheritdoc />
internal class GameExistenceInquiry(FakeInMemoryDatabase<MonopolyAggregate> database) : IGameExistenceInquiry
{
public bool CheckGameExistence(string gameId)
public async Task<bool> CheckGameExistenceAsync(string gameId)
{
var monopoly = database.FindByIdAsync(gameId);
var monopoly = await database.FindByIdAsync(gameId);
return monopoly is not null;
}
}

0 comments on commit 61edbe0

Please sign in to comment.