-
Notifications
You must be signed in to change notification settings - Fork 3
Add admin REST API endpoints for backoffice operations #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
longfin
wants to merge
8
commits into
main
Choose a base branch
from
worktree-silly-stirring-tiger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
02b2345
Add admin REST API endpoints for backoffice operations
longfin 1387723
Address PR review feedback from Copilot
longfin dafe636
Address second round of PR review feedback
longfin 47796bb
Address third round of PR review feedback
longfin 462fded
Address fourth round of PR review feedback
longfin 65e0737
Fix validation inconsistencies and unused using
longfin 6679d66
Address sixth round of PR review feedback
longfin 0d216b8
Use typed Range attribute for long fields to avoid double precision i…
longfin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,120 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using ArenaService.Shared.Constants; | ||
|
|
||
| namespace ArenaService.Shared.Dtos; | ||
|
|
||
| public class CreateSeasonRequest | ||
| { | ||
| [Range(typeof(long), "0", "9223372036854775807")] | ||
| public long StartBlock { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int RoundInterval { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int RoundCount { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int SeasonGroupId { get; set; } | ||
|
|
||
| [EnumDataType(typeof(ArenaType))] | ||
| public ArenaType ArenaType { get; set; } | ||
|
|
||
| [Range(0, int.MaxValue)] | ||
| public int RequiredMedalCount { get; set; } | ||
|
|
||
| [Range(0, int.MaxValue)] | ||
| public int TotalPrize { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int BattleTicketPolicyId { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int RefreshTicketPolicyId { get; set; } | ||
| } | ||
|
|
||
| public class UpdateSeasonRequest | ||
| { | ||
| [Range(1, int.MaxValue)] | ||
| public int SeasonGroupId { get; set; } | ||
|
|
||
| [EnumDataType(typeof(ArenaType))] | ||
| public ArenaType ArenaType { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int RoundInterval { get; set; } | ||
|
|
||
| [Range(0, int.MaxValue)] | ||
| public int RequiredMedalCount { get; set; } | ||
|
|
||
| [Range(0, int.MaxValue)] | ||
| public int TotalPrize { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int BattleTicketPolicyId { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int RefreshTicketPolicyId { get; set; } | ||
| } | ||
|
|
||
| public class AdjustEndBlockRequest | ||
| { | ||
| [Range(typeof(long), "0", "9223372036854775807")] | ||
| public long NewEndBlock { get; set; } | ||
| } | ||
|
|
||
| public class CreateBattleTicketPolicyRequest | ||
| { | ||
| [Required] | ||
| public required string Name { get; set; } | ||
|
|
||
| [Range(0, int.MaxValue)] | ||
| public int DefaultTicketsPerRound { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int MaxPurchasableTicketsPerRound { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int MaxPurchasableTicketsPerSeason { get; set; } | ||
|
|
||
| [Required] | ||
| [MinLength(1)] | ||
| public List<decimal> PurchasePrices { get; set; } = new(); | ||
| } | ||
|
|
||
| public class CreateRefreshTicketPolicyRequest | ||
| { | ||
| [Required] | ||
| public required string Name { get; set; } | ||
|
|
||
| [Range(0, int.MaxValue)] | ||
| public int DefaultTicketsPerRound { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int MaxPurchasableTicketsPerRound { get; set; } | ||
|
|
||
| [Required] | ||
| [MinLength(1)] | ||
| public List<decimal> PurchasePrices { get; set; } = new(); | ||
| } | ||
|
longfin marked this conversation as resolved.
|
||
|
|
||
| public class InitializeSeasonRequest | ||
| { | ||
| [Range(typeof(long), "0", "9223372036854775807")] | ||
| public long BlockIndex { get; set; } | ||
| } | ||
|
Comment on lines
+101
to
+105
|
||
|
|
||
| public class PrepareNextRoundRequest | ||
| { | ||
| [Range(typeof(long), "0", "9223372036854775807")] | ||
| public long BlockIndex { get; set; } | ||
| } | ||
|
longfin marked this conversation as resolved.
Comment on lines
+107
to
+111
|
||
|
|
||
| public class InitializeRankingCacheRequest | ||
| { | ||
| [Range(1, int.MaxValue)] | ||
| public int SeasonId { get; set; } | ||
|
|
||
| [Range(1, int.MaxValue)] | ||
| public int RoundId { get; set; } | ||
| } | ||
This file contains hidden or 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,55 @@ | ||
| using ArenaService.Shared.Models.Enums; | ||
| using Libplanet.Types.Tx; | ||
|
|
||
| namespace ArenaService.Shared.Dtos; | ||
|
|
||
| public class AdminBattleReviewResponse | ||
| { | ||
| public int Id { get; set; } | ||
| public string AvatarAddress { get; set; } = null!; | ||
| public int SeasonId { get; set; } | ||
| public int RoundId { get; set; } | ||
| public BattleStatus BattleStatus { get; set; } | ||
| public TxId? TxId { get; set; } | ||
| public TxStatus? TxStatus { get; set; } | ||
| public string? ExceptionNames { get; set; } | ||
| public bool? Reviewed { get; set; } | ||
| } | ||
|
|
||
| public class AdminTicketPurchaseReviewResponse | ||
| { | ||
| public int Id { get; set; } | ||
| public string AvatarAddress { get; set; } = null!; | ||
| public int SeasonId { get; set; } | ||
| public int RoundId { get; set; } | ||
| public PurchaseStatus PurchaseStatus { get; set; } | ||
| public TxId? TxId { get; set; } | ||
| public TxStatus? TxStatus { get; set; } | ||
| public string? ExceptionNames { get; set; } | ||
| public bool? Reviewed { get; set; } | ||
| } | ||
|
|
||
| public class AdminTicketPurchaseReviewListResponse | ||
| { | ||
| public List<AdminTicketPurchaseReviewResponse> BattleTicketPurchases { get; set; } = new(); | ||
| public List<AdminTicketPurchaseReviewResponse> RefreshTicketPurchases { get; set; } = new(); | ||
| } | ||
|
|
||
| public class AdminPreparationResponse | ||
| { | ||
| public string Message { get; set; } = null!; | ||
| public int? SeasonId { get; set; } | ||
| public int? RoundId { get; set; } | ||
| } | ||
|
|
||
| public class AdminLeaderboardEntryResponse | ||
| { | ||
| public string AvatarAddress { get; set; } = null!; | ||
| public string AgentAddress { get; set; } = null!; | ||
| public string NameWithHash { get; set; } = null!; | ||
| public int Rank { get; set; } | ||
| public int Score { get; set; } | ||
| public int TotalWin { get; set; } | ||
| public int TotalLose { get; set; } | ||
| public int Level { get; set; } | ||
| } |
This file contains hidden or 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
67 changes: 67 additions & 0 deletions
67
ArenaService.Tests/Controllers/AdminLeaderboardControllerTests.cs
This file contains hidden or 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,67 @@ | ||
| using ArenaService.Controllers; | ||
| using ArenaService.Shared.Models; | ||
| using ArenaService.Shared.Repositories; | ||
| using Libplanet.Crypto; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Moq; | ||
|
|
||
| namespace ArenaService.Tests.Controllers; | ||
|
|
||
| public class AdminLeaderboardControllerTests | ||
| { | ||
| private readonly AdminLeaderboardController _controller; | ||
| private readonly Mock<ILeaderboardRepository> _leaderboardRepoMock; | ||
|
|
||
| public AdminLeaderboardControllerTests() | ||
| { | ||
| _leaderboardRepoMock = new Mock<ILeaderboardRepository>(); | ||
| _controller = new AdminLeaderboardController(_leaderboardRepoMock.Object); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetLeaderboard_ReturnsOk() | ||
| { | ||
| var address = new Address("0x0000000000000000000000000000000000000000"); | ||
| var participant = new Participant | ||
| { | ||
| AvatarAddress = address, | ||
| SeasonId = 1, | ||
| Score = 1200, | ||
| TotalWin = 10, | ||
| TotalLose = 5, | ||
| User = new User | ||
| { | ||
| AvatarAddress = address, | ||
| AgentAddress = address, | ||
| NameWithHash = "TestUser#1234", | ||
| Level = 100, | ||
| PortraitId = 1, | ||
| Cp = 5000L | ||
| } | ||
| }; | ||
|
|
||
| var leaderboard = new List<(Participant Participant, int Score, int Rank)> | ||
| { | ||
| (participant, 1200, 1) | ||
| }; | ||
| _leaderboardRepoMock.Setup(x => x.GetLeaderboardAsync(1)).ReturnsAsync(leaderboard); | ||
|
|
||
| var result = await _controller.GetLeaderboard(1); | ||
|
|
||
| Assert.IsType<OkObjectResult>(result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task DownloadLeaderboardCsv_ReturnsFile() | ||
| { | ||
| var csvBytes = "avatar_address,agent_address\ntest,test"u8.ToArray(); | ||
| _leaderboardRepoMock.Setup(x => x.GenerateLeaderboardCsvAsync(1)).ReturnsAsync(csvBytes); | ||
|
|
||
| var result = await _controller.DownloadLeaderboardCsv(1); | ||
|
|
||
| var fileResult = Assert.IsType<FileContentResult>(result); | ||
| Assert.Equal("text/csv", fileResult.ContentType); | ||
| Assert.Equal("leaderboard_season_1.csv", fileResult.FileDownloadName); | ||
| Assert.Equal(csvBytes, fileResult.FileContents); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.