Skip to content

Commit

Permalink
Move repositories to shared
Browse files Browse the repository at this point in the history
  • Loading branch information
Atralupus committed Feb 18, 2025
1 parent 4730b6e commit 2fa76f3
Show file tree
Hide file tree
Showing 108 changed files with 632 additions and 214 deletions.
63 changes: 63 additions & 0 deletions ArenaService.Admin/Controllers/SeasonManagingController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace ArenaService.Controllers;

using ArenaService.Shared.Dtos;
using ArenaService.Shared.Exceptions;
using ArenaService.Shared.Repositories;
using ArenaService.Shared.Services;
using Libplanet.Crypto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;

[Route("manage-seasons")]
[ApiController]
public class SeasonManagingController : ControllerBase
{
private readonly ISeasonRepository _seasonRepo;
private readonly IRoundRepository _roundRepo;
private readonly ISeasonPreparationService _seasonPreparationService;
private readonly IRoundPreparationService _roundPreparationService;

public SeasonManagingController(
ISeasonRepository seasonRepo,
IRoundRepository roundRepo,
ISeasonPreparationService seasonPreparationService,
IRoundPreparationService roundPreparationService
)
{
_seasonRepo = seasonRepo;
_roundRepo = roundRepo;
_seasonPreparationService = seasonPreparationService;
_roundPreparationService = roundPreparationService;
}

[HttpPost("initialize-season")]
[SwaggerResponse(
StatusCodes.Status200OK,
"SeasonAndRoundResponse",
typeof(SeasonAndRoundResponse)
)]
[SwaggerResponse(StatusCodes.Status404NotFound, "Status404NotFound")]
public async Task<ActionResult> InitializeSeason(int seasonId)
{
var season = await _seasonRepo.GetSeasonAsync(seasonId, q => q.Include(s => s.Rounds));

await _seasonPreparationService.PrepareSeasonAsync(
(season, season.Rounds.OrderBy(r => r.StartBlock).First())
);

return Ok();
}

[HttpPost("prepare-next-round")]
[SwaggerResponse(StatusCodes.Status200OK, "Ok")]
[SwaggerResponse(StatusCodes.Status404NotFound, "Status404NotFound")]
public async Task<ActionResult> PrepareNextRound(int roundId)
{
var round = await _roundRepo.GetRoundAsync(roundId, q => q.Include(r => r.Season));

await _roundPreparationService.PrepareNextRoundWithSnapshotAsync((round!.Season, round));

return Ok();
}
}
8 changes: 8 additions & 0 deletions ArenaService.Admin/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace ArenaService.Admin;

using ArenaService.Admin.Options;
using ArenaService.Shared.Data;
using ArenaService.Shared.Repositories;
using ArenaService.Shared.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -77,6 +79,12 @@ public void ConfigureServices(IServiceCollection services)
);
});

services.AddScoped<ISeasonRepository, SeasonRepository>();
services.AddScoped<IRoundRepository, RoundRepository>();

services.AddScoped<ISeasonPreparationService, SeasonPreparationService>();
services.AddScoped<IRoundPreparationService, RoundPreparationService>();

services.AddHealthChecks();
}

Expand Down
2 changes: 1 addition & 1 deletion ArenaService.IntegrationTests/Repositories/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ArenaService.IntegrationTests.Fixtures;
using ArenaService.Repositories;
using ArenaService.Shared.Repositories;
using StackExchange.Redis;

namespace ArenaService.IntegrationTests.Repositories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using ArenaService.IntegrationTests.Fixtures;
using ArenaService.Repositories;
using ArenaService.Shared.Repositories;
using Libplanet.Crypto;
using StackExchange.Redis;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using ArenaService.IntegrationTests.Fixtures;
using ArenaService.Repositories;
using ArenaService.Shared.Repositories;
using Libplanet.Crypto;
using StackExchange.Redis;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using ArenaService.IntegrationTests.Fixtures;
using ArenaService.Repositories;
using ArenaService.Shared.Repositories;
using Libplanet.Crypto;
using StackExchange.Redis;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ArenaService.IntegrationTests.Fixtures;
using ArenaService.Constants;
using ArenaService.Repositories;
using ArenaService.Shared.Constants;
using ArenaService.Shared.Repositories;
using Libplanet.Crypto;
using StackExchange.Redis;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ArenaService.IntegrationTests.Fixtures;
using ArenaService.Constants;
using ArenaService.Repositories;
using ArenaService.Shared.Constants;
using ArenaService.Shared.Repositories;
using Libplanet.Crypto;
using StackExchange.Redis;
using Xunit;
Expand Down
2 changes: 1 addition & 1 deletion ArenaService.IntegrationTests/Services/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ArenaService.IntegrationTests.Fixtures;
using ArenaService.Repositories;
using ArenaService.Shared.Repositories;
using StackExchange.Redis;

namespace ArenaService.IntegrationTests.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ArenaService.IntegrationTests.Fixtures;
using ArenaService.Repositories;
using ArenaService.Shared.Repositories;

namespace ArenaService.IntegrationTests.Services.RankingServiceTests;

Expand Down
6 changes: 6 additions & 0 deletions ArenaService.Shared/ArenaService.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@

<ItemGroup>
<PackageReference Include="EFCore.NamingConventions" Version="8.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Libplanet.Crypto" Version="5.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="7.2.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.24" />
<PackageReference Include="Libplanet.Types" Version="5.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Constants;
namespace ArenaService.Shared.Constants;

public static class ArenaServiceConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Constants;
namespace ArenaService.Shared.Constants;

using System.Collections.Generic;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Constants;
namespace ArenaService.Shared.Constants;

public enum RankingStatus
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class ArenaInfoResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using ArenaService.Shared.Models;
using Libplanet.Crypto;
using Newtonsoft.Json;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class AvailableOpponentResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using ArenaService.Shared.Models;
using ArenaService.Shared.Models.Enums;
using Libplanet.Crypto;
using Libplanet.Types.Tx;
using Newtonsoft.Json;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class BattleResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using ArenaService.Shared.Models;
using ArenaService.Shared.Models.Enums;
using Libplanet.Types.Tx;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class BattleRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

using ArenaService.Shared.Models;
using ArenaService.Shared.Models.BattleTicket;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class BattleTokenResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class ClanLeaderboardResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using Newtonsoft.Json;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class ClanResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using Swashbuckle.AspNetCore.Annotations;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class ClassifyByBlockMedalsResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class MedalResponse
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Libplanet.Types.Tx;
using Swashbuckle.AspNetCore.Annotations;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class PurchaseTicketRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

using ArenaService.Shared.Models;
using ArenaService.Shared.Models.RefreshTicket;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class RoundResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class SeasonAndRoundResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using ArenaService.Constants;
using ArenaService.Shared.Constants;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class SeasonResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Libplanet.Crypto;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class SeasonsResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class TicketPolicyResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ArenaService.Shared.Models.Enums;
using Libplanet.Types.Tx;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class TicketPurchaseLogResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

using ArenaService.Shared.Models;
using ArenaService.Shared.Models.BattleTicket;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class UserRegisterRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Libplanet.Crypto;
using Newtonsoft.Json;

namespace ArenaService.Dtos;
namespace ArenaService.Shared.Dtos;

public class UserResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Exceptions;
namespace ArenaService.Shared.Exceptions;

public class CacheUnavailableException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Exceptions;
namespace ArenaService.Shared.Exceptions;

public class CalcAOFailedException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Exceptions;
namespace ArenaService.Shared.Exceptions;

public class NotEnoughMedalException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Exceptions;
namespace ArenaService.Shared.Exceptions;

public class NotFoundSeasonException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ArenaService.Exceptions;
namespace ArenaService.Shared.Exceptions;

public class NotRankedException : Exception
{
Expand Down
Loading

0 comments on commit 2fa76f3

Please sign in to comment.