Skip to content

make token options retrieval asynchronous - #74

Open
9ajia wants to merge 1 commit into
developmentfrom
tokenrequest
Open

make token options retrieval asynchronous#74
9ajia wants to merge 1 commit into
developmentfrom
tokenrequest

Conversation

@9ajia

@9ajia 9ajia commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Updates the token-options endpoint to use asynchronous database queries, following the project's usual async endpoint approach.

Changes

  • Makes GET /api/v1/tokens/options asynchronous.
  • Uses EF Core ToListAsync() for the token-option queries.
  • Updates the gateway and use-case interfaces.
  • Updates the related controller, use-case and gateway tests to await the async methods.
  • Leaves the existing GET /api/v1/tokens endpoint unchanged.

Testing

  • All 103 tests pass.
  • The route and response format remain unchanged.

@9ajia 9ajia self-assigned this Sep 2, 2026
@9ajia
9ajia requested review from a team as code owners September 2, 2026 12:45

@Duslerke Duslerke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, considering this PR is about async, the architecture violation can be left as is.

So for changes that need to be addressing - the Async method name suffixes need to be dropped.

Meanwhile the architecture violation should be addressed in a follow up PR in the spirit of keeping PRs small and to the point.

[ProducesResponseType(typeof(TokenOptionsResponse), StatusCodes.Status200OK)]
[HttpGet("options")]
public IActionResult GetTokenOptions()
public async Task<IActionResult> GetTokenOptionsAsync()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're not a Nuget package developer that needs to maintain Sync and Async versions of exposed methods, there's no value in suffixing our method names with Async.

It only makes code harder to read, meanwhile the async nature is obvious from the interface definition (Task return type), and async declaration within method signatures of implementation. And when it comes to actual method calls, we have await indicating async'ness.

int GenerateToken(TokenRequestObject tokenRequestObject);
int? UpdateToken(int tokenId, bool enabled);
TokenOptionsResponse GetTokenOptions();
Task<TokenOptionsResponse> GetTokenOptionsAsync();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in above comment, not need for Async suffix.

}

public TokenOptionsResponse GetTokenOptions()
public async Task<TokenOptionsResponse> GetTokenOptionsAsync()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described in above comments, the Async method name suffix is not needed.

public Task<TokenOptionsResponse> ExecuteAsync()
{
return _gateway.GetTokenOptions();
return _gateway.GetTokenOptionsAsync();

@Duslerke Duslerke Sep 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... just noticed this while I was looking at the lack of await on the gateway call.

You're using the using TokenAdministrationApi.V1.Boundary.Response; model within use case and the gateway.

That's a Hackney architecture no violation. In doing this loose coupling through the response (presentation layer) model, the presentation, domain, and the entity layers get mangled together.

Even when models stay the same between the layers, based on our architecture they should still be separated out as separate classes. So you should have the TokenOptionsEntity that the gateway uses for its internal logic. Then before returning that to the usecase, your GW would map this model to TokenOptions (domain implied) domain model (use case should only ever be aware of domain level models). Then the use case returns the domain model to the controller (presentation layer). Lastly, the controller, maps the domain object to presentation layer TokenOptionsResponse model that it returns as a response to the consumer (as in the model's name).

But this violation can be addressed in the follow up PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Async suffixes need to be dropped here and corresponding interface as well.

}

public TokenOptionsResponse Execute()
public Task<TokenOptionsResponse> ExecuteAsync()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this is not async as it does not perform any async logic, nor the method is marked as async. What this actually does is synchronously return the async gateway call's Task. To make this async, you need to await the GW call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants