Skip to content

Commit

Permalink
handling string enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Atralupus committed Jan 16, 2025
1 parent 99b27d1 commit e18137d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
6 changes: 3 additions & 3 deletions ArenaService/Constants/ArenaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace ArenaService.Constants;

public enum ArenaType
{
OffSeason,
Season,
Championship,
OFF_SEASON,
SEASON,
CHAMPIONSHIP,
}
13 changes: 6 additions & 7 deletions ArenaService/Controllers/ArenaInfoController.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
namespace ArenaService.Controllers;

using ArenaService.Dtos;
using ArenaService.Extensions;
using ArenaService.Repositories;
using Libplanet.Crypto;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

[Route("info")]
[ApiController]
public class ArenaInfoController : ControllerBase
{
public ArenaInfoController() { }

[HttpGet()]
[ProducesResponseType(typeof(ArenaInfoResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
[HttpGet]
[SwaggerOperation(Summary = "", Description = "")]
[SwaggerResponse(StatusCodes.Status200OK, "ArenaInfoResponse", typeof(ArenaInfoResponse))]
[SwaggerResponse(StatusCodes.Status401Unauthorized, "Status401Unauthorized")]
[SwaggerResponse(StatusCodes.Status404NotFound, "Status404NotFound")]
public async Task<Results<NotFound<string>, Ok>> GetArenaInfo()

Check warning on line 19 in ArenaService/Controllers/ArenaInfoController.cs

View workflow job for this annotation

GitHub Actions / Test (ArenaService.Tests)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
return TypedResults.Ok();
Expand Down
12 changes: 9 additions & 3 deletions ArenaService/Controllers/AvailableOpponentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ArenaService.Controllers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

[Route("available-opponents")]
[ApiController]
Expand Down Expand Up @@ -39,9 +40,14 @@ IBackgroundJobClient jobClient

[HttpGet]
[Authorize(Roles = "User", AuthenticationSchemes = "ES256K")]
[ProducesResponseType(typeof(AvailableOpponentsResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
[SwaggerOperation(Summary = "", Description = "")]
[SwaggerResponse(
StatusCodes.Status200OK,
"AvailableOpponents",
typeof(AvailableOpponentsResponse)
)]
[SwaggerResponse(StatusCodes.Status401Unauthorized, "Status401Unauthorized")]
[SwaggerResponse(StatusCodes.Status503ServiceUnavailable, "Status503ServiceUnavailable")]
public async Task<
Results<UnauthorizedHttpResult, NotFound<string>, StatusCodeHttpResult, Ok>
> GetAvailableOpponents()
Expand Down
9 changes: 8 additions & 1 deletion ArenaService/Setup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace ArenaService;

using System.Text.Json.Serialization;
using ArenaService.Auth;
using ArenaService.Data;
using ArenaService.Options;
Expand Down Expand Up @@ -60,7 +61,11 @@ public void ConfigureServices(IServiceCollection services)
}
);

services.AddControllers();
services
.AddControllers()
.AddJsonOptions(options =>
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())
);

services
.AddAuthentication("ES256K")
Expand Down Expand Up @@ -104,6 +109,8 @@ public void ConfigureServices(IServiceCollection services)
);

options.OperationFilter<AuthorizeCheckOperationFilter>();

options.EnableAnnotations();
});

services.AddScoped<IUserRepository, UserRepository>();
Expand Down

0 comments on commit e18137d

Please sign in to comment.