diff --git a/Api/Controllers/v1/CustomEventsController.cs b/Api/Controllers/v1/CustomEventsController.cs index 4655570..09a165e 100644 --- a/Api/Controllers/v1/CustomEventsController.cs +++ b/Api/Controllers/v1/CustomEventsController.cs @@ -34,17 +34,16 @@ namespace Api.Controllers.v1 } [HttpGet("Alliance/{allianceId:guid}")] - public async Task>> GetAllianceCustomEvents(Guid allianceId, - [FromQuery] int take, CancellationToken cancellationToken) + public async Task>> GetAllianceCustomEvents(Guid allianceId, CancellationToken cancellationToken, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10) { try { var allianceCustomEventsResult = - await customEventRepository.GetAllianceCustomEventsAsync(allianceId, take, cancellationToken); + await customEventRepository.GetAllianceCustomEventsAsync(allianceId, pageNumber, pageSize, cancellationToken); if (allianceCustomEventsResult.IsFailure) return BadRequest(allianceCustomEventsResult.Error); - return allianceCustomEventsResult.Value.Count > 0 + return allianceCustomEventsResult.Value.Data.Count > 0 ? Ok(allianceCustomEventsResult.Value) : NoContent(); } diff --git a/Api/Controllers/v1/DesertStormsController.cs b/Api/Controllers/v1/DesertStormsController.cs index 6ffb902..5fedac8 100644 --- a/Api/Controllers/v1/DesertStormsController.cs +++ b/Api/Controllers/v1/DesertStormsController.cs @@ -34,17 +34,16 @@ namespace Api.Controllers.v1 } [HttpGet("Alliance/{allianceId:guid}")] - public async Task>> GetAllianceDesertStorms(Guid allianceId, - [FromQuery] int take, CancellationToken cancellationToken) + public async Task>> GetAllianceDesertStorms(Guid allianceId, CancellationToken cancellationToken, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10) { try { var allianceDesertStormsResult = - await desertStormRepository.GetAllianceDesertStormsAsync(allianceId, take, cancellationToken); + await desertStormRepository.GetAllianceDesertStormsAsync(allianceId, pageNumber, pageSize, cancellationToken); if (allianceDesertStormsResult.IsFailure) return BadRequest(allianceDesertStormsResult.Error); - return allianceDesertStormsResult.Value.Count > 0 + return allianceDesertStormsResult.Value.Data.Count > 0 ? Ok(allianceDesertStormsResult.Value) : NoContent(); } diff --git a/Api/Controllers/v1/MarshalGuardsController.cs b/Api/Controllers/v1/MarshalGuardsController.cs index 17abfd0..79f4fa2 100644 --- a/Api/Controllers/v1/MarshalGuardsController.cs +++ b/Api/Controllers/v1/MarshalGuardsController.cs @@ -34,17 +34,16 @@ namespace Api.Controllers.v1 } [HttpGet("Alliance/{allianceId:guid}")] - public async Task>> GetAllianceMarshalGuards(Guid allianceId, [FromQuery] int take, - CancellationToken cancellationToken) + public async Task>> GetAllianceMarshalGuards(Guid allianceId, CancellationToken cancellationToken, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10) { try { var allianceMarshalGuardsResult = - await marshalGuardRepository.GetAllianceMarshalGuardsAsync(allianceId, take, cancellationToken); + await marshalGuardRepository.GetAllianceMarshalGuardsAsync(allianceId, pageNumber, pageSize, cancellationToken); if (allianceMarshalGuardsResult.IsFailure) return BadRequest(allianceMarshalGuardsResult.Error); - return allianceMarshalGuardsResult.Value.Count > 0 + return allianceMarshalGuardsResult.Value.Data.Count > 0 ? Ok(allianceMarshalGuardsResult.Value) : NoContent(); } diff --git a/Api/Controllers/v1/PlayersController.cs b/Api/Controllers/v1/PlayersController.cs index 79500bf..26a9bc7 100644 --- a/Api/Controllers/v1/PlayersController.cs +++ b/Api/Controllers/v1/PlayersController.cs @@ -1,4 +1,5 @@ -using Application.DataTransferObjects.ExcelImport; +using Application.DataTransferObjects; +using Application.DataTransferObjects.ExcelImport; using Application.DataTransferObjects.Player; using Application.Errors; using Application.Interfaces; @@ -55,16 +56,16 @@ namespace Api.Controllers.v1 } [HttpGet("Alliance/dismiss/{allianceId:guid}")] - public async Task>> GetAllianceDismissPlayers(Guid allianceId, CancellationToken cancellationToken) + public async Task>> GetAllianceDismissPlayers(Guid allianceId, CancellationToken cancellationToken, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10) { try { var allianceDismissPlayersResult = - await playerRepository.GetAllianceDismissPlayersAsync(allianceId, cancellationToken); + await playerRepository.GetAllianceDismissPlayersAsync(allianceId, pageNumber, pageSize, cancellationToken); if (allianceDismissPlayersResult.IsFailure) return BadRequest(allianceDismissPlayersResult.Error); - return allianceDismissPlayersResult.Value.Count > 0 + return allianceDismissPlayersResult.Value.Data.Count > 0 ? Ok(allianceDismissPlayersResult.Value) : NoContent(); } diff --git a/Api/Controllers/v1/VsDuelsController.cs b/Api/Controllers/v1/VsDuelsController.cs index b1a65dd..ae2b0e1 100644 --- a/Api/Controllers/v1/VsDuelsController.cs +++ b/Api/Controllers/v1/VsDuelsController.cs @@ -1,4 +1,5 @@ -using Application.DataTransferObjects.VsDuel; +using Application.DataTransferObjects; +using Application.DataTransferObjects.VsDuel; using Application.Errors; using Application.Interfaces; using Asp.Versioning; @@ -32,17 +33,16 @@ namespace Api.Controllers.v1 } [HttpGet("Alliance/{allianceId:guid}")] - public async Task>> GetAllianceVsDuels(Guid allianceId, [FromQuery] int take, - CancellationToken cancellationToken) + public async Task>> GetAllianceVsDuels(Guid allianceId, CancellationToken cancellationToken, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10) { try { var allianceVsDuelsResult = - await vsDuelRepository.GetAllianceVsDuelsAsync(allianceId, take, cancellationToken); + await vsDuelRepository.GetAllianceVsDuelsAsync(allianceId, pageNumber, pageSize, cancellationToken); if (allianceVsDuelsResult.IsFailure) return BadRequest(allianceVsDuelsResult.Error); - return allianceVsDuelsResult.Value.Count > 0 + return allianceVsDuelsResult.Value.Data.Count > 0 ? Ok(allianceVsDuelsResult.Value) : NoContent(); } diff --git a/Api/Controllers/v1/ZombieSiegesController.cs b/Api/Controllers/v1/ZombieSiegesController.cs index 17e84ff..bcd8e08 100644 --- a/Api/Controllers/v1/ZombieSiegesController.cs +++ b/Api/Controllers/v1/ZombieSiegesController.cs @@ -1,4 +1,5 @@ -using Application.DataTransferObjects.ZombieSiege; +using Application.DataTransferObjects; +using Application.DataTransferObjects.ZombieSiege; using Application.Errors; using Application.Interfaces; using Asp.Versioning; @@ -34,17 +35,17 @@ namespace Api.Controllers.v1 } [HttpGet("Alliance/{allianceId:guid}")] - public async Task>> GetAllianceZombieSieges(Guid allianceId, [FromQuery] int take, - CancellationToken cancellationToken) + public async Task>> GetAllianceZombieSieges(Guid allianceId, CancellationToken cancellationToken, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10) { try { var allianceZombieSiegesResult = - await zombieSiegeRepository.GetAllianceZombieSiegesAsync(allianceId, take, cancellationToken); + await zombieSiegeRepository.GetAllianceZombieSiegesAsync(allianceId, pageNumber, pageSize, + cancellationToken); if (allianceZombieSiegesResult.IsFailure) return BadRequest(allianceZombieSiegesResult.Error); - return allianceZombieSiegesResult.Value.Count > 0 + return allianceZombieSiegesResult.Value.TotalRecords > 0 ? Ok(allianceZombieSiegesResult.Value) : NoContent(); } diff --git a/Application/DataTransferObjects/PagedResponseDto.cs b/Application/DataTransferObjects/PagedResponseDto.cs new file mode 100644 index 0000000..e579571 --- /dev/null +++ b/Application/DataTransferObjects/PagedResponseDto.cs @@ -0,0 +1,12 @@ +namespace Application.DataTransferObjects; + +public class PagedResponseDto +{ + public int TotalRecords { get; set; } + + public int PageSize { get; set; } + + public int PageNumber { get; set; } + + public List Data { get; set; } = []; +} \ No newline at end of file diff --git a/Application/DataTransferObjects/ZombieSiege/ZombieSiegeDto.cs b/Application/DataTransferObjects/ZombieSiege/ZombieSiegeDto.cs index 80870a1..54ba658 100644 --- a/Application/DataTransferObjects/ZombieSiege/ZombieSiegeDto.cs +++ b/Application/DataTransferObjects/ZombieSiege/ZombieSiegeDto.cs @@ -8,6 +8,8 @@ public class ZombieSiegeDto public int TotalLevel20Players { get; set; } + public int TotalWavesSurvived { get; set; } + public Guid AllianceId { get; set; } public DateTime EventDate { get; set; } diff --git a/Application/Interfaces/ICustomEventRepository.cs b/Application/Interfaces/ICustomEventRepository.cs index c2c25c9..0511415 100644 --- a/Application/Interfaces/ICustomEventRepository.cs +++ b/Application/Interfaces/ICustomEventRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.CustomEvent; namespace Application.Interfaces; @@ -9,7 +10,7 @@ public interface ICustomEventRepository Task> GetCustomEventDetailAsync(Guid customEventId, CancellationToken cancellationToken); - Task>> GetAllianceCustomEventsAsync(Guid allianceId, int take, CancellationToken cancellationToken); + Task>> GetAllianceCustomEventsAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken); Task> CreateCustomEventAsync(CreateCustomEventDto createCustomEventDto, string createdBy, CancellationToken cancellationToken); diff --git a/Application/Interfaces/IDesertStormRepository.cs b/Application/Interfaces/IDesertStormRepository.cs index c37611e..f12a029 100644 --- a/Application/Interfaces/IDesertStormRepository.cs +++ b/Application/Interfaces/IDesertStormRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.DesertStorm; namespace Application.Interfaces; @@ -7,7 +8,7 @@ public interface IDesertStormRepository { Task> GetDesertStormAsync(Guid desertStormId, CancellationToken cancellationToken); - Task>> GetAllianceDesertStormsAsync(Guid allianceId, int take, CancellationToken cancellationToken); + Task>> GetAllianceDesertStormsAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken); Task> GetDesertStormDetailAsync(Guid desertStormId, CancellationToken cancellationToken); diff --git a/Application/Interfaces/IMarshalGuardRepository.cs b/Application/Interfaces/IMarshalGuardRepository.cs index 24c7f87..0383c0c 100644 --- a/Application/Interfaces/IMarshalGuardRepository.cs +++ b/Application/Interfaces/IMarshalGuardRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.MarshalGuard; namespace Application.Interfaces; @@ -9,7 +10,7 @@ public interface IMarshalGuardRepository Task> GetMarshalGuardDetailAsync(Guid marshalGuardId, CancellationToken cancellationToken); - Task>> GetAllianceMarshalGuardsAsync(Guid allianceId, int take, CancellationToken cancellationToken); + Task>> GetAllianceMarshalGuardsAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken); Task> CreateMarshalGuardsAsync(CreateMarshalGuardDto createMarshalGuardDto, string createdBy, CancellationToken cancellationToken); diff --git a/Application/Interfaces/IPlayerRepository.cs b/Application/Interfaces/IPlayerRepository.cs index f4ab013..c38bb77 100644 --- a/Application/Interfaces/IPlayerRepository.cs +++ b/Application/Interfaces/IPlayerRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.Player; namespace Application.Interfaces; @@ -9,7 +10,7 @@ public interface IPlayerRepository Task>> GetAlliancePlayersAsync(Guid allianceId, CancellationToken cancellationToken); - Task>> GetAllianceDismissPlayersAsync(Guid allianceId, CancellationToken cancellationToken); + Task>> GetAllianceDismissPlayersAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken); Task>> GetAlliancePlayersMvp(Guid allianceId, CancellationToken cancellationToken); diff --git a/Application/Interfaces/IVsDuelRepository.cs b/Application/Interfaces/IVsDuelRepository.cs index 3ca0d90..6a691c1 100644 --- a/Application/Interfaces/IVsDuelRepository.cs +++ b/Application/Interfaces/IVsDuelRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.VsDuel; namespace Application.Interfaces; @@ -9,7 +10,7 @@ public interface IVsDuelRepository Task> GetVsDuelDetailAsync(Guid vsDuelId, CancellationToken cancellationToken); - Task>> GetAllianceVsDuelsAsync(Guid allianceId, int take, CancellationToken cancellationToken); + Task>> GetAllianceVsDuelsAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken); Task> CreateVsDuelAsync(CreateVsDuelDto createVsDuelDto, string createdBy, CancellationToken cancellationToken); diff --git a/Application/Interfaces/IZombieSiegeRepository.cs b/Application/Interfaces/IZombieSiegeRepository.cs index eebb450..74083e4 100644 --- a/Application/Interfaces/IZombieSiegeRepository.cs +++ b/Application/Interfaces/IZombieSiegeRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.ZombieSiege; namespace Application.Interfaces; @@ -9,7 +10,7 @@ public interface IZombieSiegeRepository Task> GetZombieSiegeDetailAsync(Guid zombieSiegeId, CancellationToken cancellationToken); - Task>> GetAllianceZombieSiegesAsync(Guid allianceId, int take, CancellationToken cancellationToken); + Task>> GetAllianceZombieSiegesAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken); Task> CreateZombieSiegeAsync(CreateZombieSiegeDto createZombieSiegeDto, string createdBy, CancellationToken cancellationToken); diff --git a/Application/Profiles/ZombieSiegeProfile.cs b/Application/Profiles/ZombieSiegeProfile.cs index d4ac486..26a93f3 100644 --- a/Application/Profiles/ZombieSiegeProfile.cs +++ b/Application/Profiles/ZombieSiegeProfile.cs @@ -9,10 +9,14 @@ public class ZombieSiegeProfile : Profile public ZombieSiegeProfile() { CreateMap() + .ForMember(des => des.TotalWavesSurvived, + opt => opt.MapFrom(scr => scr.ZombieSiegeParticipants.Sum(p => p.SurvivedWaves))) .ForMember(des => des.TotalLevel20Players, opt => opt.MapFrom(src => src.ZombieSiegeParticipants.Count(p => p.SurvivedWaves == 20))); CreateMap() + .ForMember(des => des.TotalWavesSurvived, + opt => opt.MapFrom(scr => scr.ZombieSiegeParticipants.Sum(p => p.SurvivedWaves))) .ForMember(des => des.TotalLevel20Players, opt => opt.MapFrom(src => src.ZombieSiegeParticipants.Count(p => p.SurvivedWaves == 20))); diff --git a/Application/Repositories/CustomEventRepository.cs b/Application/Repositories/CustomEventRepository.cs index 5eb9d67..cd38c86 100644 --- a/Application/Repositories/CustomEventRepository.cs +++ b/Application/Repositories/CustomEventRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.CustomEvent; using Application.Errors; using Application.Interfaces; @@ -37,17 +38,28 @@ public class CustomEventRepository(ApplicationContext context, IMapper mapper, I : Result.Success(customEventDetail); } - public async Task>> GetAllianceCustomEventsAsync(Guid allianceId, int take, CancellationToken cancellationToken) + public async Task>> GetAllianceCustomEventsAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken) { - var allianceCustomEvents = await context.CustomEvents + var query = context.CustomEvents .Where(customEvent => customEvent.AllianceId == allianceId) - .ProjectTo(mapper.ConfigurationProvider) - .AsNoTracking() .OrderByDescending(customEvent => customEvent.EventDate) - .Take(take) + .AsNoTracking(); + + var totalRecord = await query.CountAsync(cancellationToken); + + var pagedCustomEvents = await query + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ProjectTo(mapper.ConfigurationProvider) .ToListAsync(cancellationToken); - return Result.Success(allianceCustomEvents); + return Result.Success(new PagedResponseDto + { + Data = pagedCustomEvents, + TotalRecords = totalRecord, + PageSize = pageSize, + PageNumber = pageNumber + }); } public async Task> CreateCustomEventAsync(CreateCustomEventDto createCustomEventDto, string createdBy, diff --git a/Application/Repositories/DesertStormRepository.cs b/Application/Repositories/DesertStormRepository.cs index a40fd21..daa5f17 100644 --- a/Application/Repositories/DesertStormRepository.cs +++ b/Application/Repositories/DesertStormRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.DesertStorm; using Application.Errors; using Application.Interfaces; @@ -25,17 +26,28 @@ public class DesertStormRepository(ApplicationContext context, IMapper mapper, I : Result.Success(desertStormById); } - public async Task>> GetAllianceDesertStormsAsync(Guid allianceId, int take, CancellationToken cancellationToken) + public async Task>> GetAllianceDesertStormsAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken) { - var allianceDesertStorms = await context.DesertStorms + var query = context.DesertStorms .Where(desertStorm => desertStorm.AllianceId == allianceId) - .ProjectTo(mapper.ConfigurationProvider) - .AsNoTracking() .OrderByDescending(desertStorm => desertStorm.EventDate) - .Take(take) + .AsNoTracking(); + + var totalRecord = await query.CountAsync(cancellationToken); + + var pagedDesertStorms = await query + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ProjectTo(mapper.ConfigurationProvider) .ToListAsync(cancellationToken); - return Result.Success(allianceDesertStorms); + return Result.Success(new PagedResponseDto + { + Data = pagedDesertStorms, + TotalRecords = totalRecord, + PageSize = pageSize, + PageNumber = pageNumber + }); } public async Task> GetDesertStormDetailAsync(Guid desertStormId, CancellationToken cancellationToken) diff --git a/Application/Repositories/MarshalGuardRepository.cs b/Application/Repositories/MarshalGuardRepository.cs index 7150a1e..3515e21 100644 --- a/Application/Repositories/MarshalGuardRepository.cs +++ b/Application/Repositories/MarshalGuardRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.MarshalGuard; using Application.Errors; using Application.Interfaces; @@ -37,17 +38,28 @@ public class MarshalGuardRepository(ApplicationContext context, IMapper mapper, : Result.Success(detailMarshalGuard); } - public async Task>> GetAllianceMarshalGuardsAsync(Guid allianceId, int take, CancellationToken cancellationToken) + public async Task>> GetAllianceMarshalGuardsAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken) { - var allianceMarshalGuards = await context.MarshalGuards + var query = context.MarshalGuards .Where(marshalGuard => marshalGuard.AllianceId == allianceId) .OrderByDescending(marshalGuard => marshalGuard.EventDate) + .AsNoTracking(); + + var totalRecord = await query.CountAsync(cancellationToken); + + var pagedMarshalGuards = await query + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) .ProjectTo(mapper.ConfigurationProvider) - .AsNoTracking() - .Take(take) .ToListAsync(cancellationToken); - return Result.Success(allianceMarshalGuards); + return Result.Success(new PagedResponseDto + { + Data = pagedMarshalGuards, + TotalRecords = totalRecord, + PageSize = pageSize, + PageNumber = pageNumber + }); } diff --git a/Application/Repositories/PlayerRepository.cs b/Application/Repositories/PlayerRepository.cs index fead25e..9bdbccb 100644 --- a/Application/Repositories/PlayerRepository.cs +++ b/Application/Repositories/PlayerRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.Player; using Application.Errors; using Application.Interfaces; @@ -36,16 +37,30 @@ public class PlayerRepository(ApplicationContext context, IMapper mapper, ILogge return Result.Success(alliancePlayers); } - public async Task>> GetAllianceDismissPlayersAsync(Guid allianceId, CancellationToken cancellationToken) + public async Task>> GetAllianceDismissPlayersAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken) { - var dismissAlliancePlayers = await context.Players + var query = context.Players .IgnoreQueryFilters() - .ProjectTo(mapper.ConfigurationProvider) - .AsNoTracking() .Where(player => player.AllianceId == allianceId && player.IsDismissed) + .OrderByDescending(player => player.DismissedAt) + .AsNoTracking(); + + var totalRecord = await query.CountAsync(cancellationToken); + + var pagedDismissPlayers = await query + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ProjectTo(mapper.ConfigurationProvider) .ToListAsync(cancellationToken); - return Result.Success(dismissAlliancePlayers); + + return Result.Success(new PagedResponseDto + { + Data = pagedDismissPlayers, + TotalRecords = totalRecord, + PageSize = pageSize, + PageNumber = pageNumber + }); } public async Task>> GetAlliancePlayersMvp(Guid allianceId, CancellationToken cancellationToken) diff --git a/Application/Repositories/VsDuelRepository.cs b/Application/Repositories/VsDuelRepository.cs index 1ff4ed5..367ea97 100644 --- a/Application/Repositories/VsDuelRepository.cs +++ b/Application/Repositories/VsDuelRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.VsDuel; using Application.Errors; using Application.Interfaces; @@ -37,17 +38,28 @@ public class VsDuelRepository(ApplicationContext context, IMapper mapper, ILogge : Result.Success(vsDuelDetail); } - public async Task>> GetAllianceVsDuelsAsync(Guid allianceId, int take, CancellationToken cancellationToken) + public async Task>> GetAllianceVsDuelsAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken) { - var allianceVsDuels = await context.VsDuels + var query = context.VsDuels .Where(vsDuel => vsDuel.AllianceId == allianceId) - .ProjectTo(mapper.ConfigurationProvider) .OrderByDescending(vsDuel => vsDuel.EventDate) - .Take(take) - .AsNoTracking() + .AsNoTracking(); + + var totalRecord = await query.CountAsync(cancellationToken); + + var pagedVsDuels = await query + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ProjectTo(mapper.ConfigurationProvider) .ToListAsync(cancellationToken); - return Result.Success(allianceVsDuels); + return Result.Success(new PagedResponseDto + { + Data = pagedVsDuels, + TotalRecords = totalRecord, + PageSize = pageSize, + PageNumber = pageNumber + }); } public async Task> CreateVsDuelAsync(CreateVsDuelDto createVsDuelDto, string createdBy, CancellationToken cancellationToken) diff --git a/Application/Repositories/ZombieSiegeRepository.cs b/Application/Repositories/ZombieSiegeRepository.cs index d507083..25a4dd4 100644 --- a/Application/Repositories/ZombieSiegeRepository.cs +++ b/Application/Repositories/ZombieSiegeRepository.cs @@ -1,4 +1,5 @@ using Application.Classes; +using Application.DataTransferObjects; using Application.DataTransferObjects.ZombieSiege; using Application.Errors; using Application.Interfaces; @@ -37,17 +38,28 @@ public class ZombieSiegeRepository(ApplicationContext context, IMapper mapper, I : Result.Success(zombieSiegeDetail); } - public async Task>> GetAllianceZombieSiegesAsync(Guid allianceId, int take, CancellationToken cancellationToken) + public async Task>> GetAllianceZombieSiegesAsync(Guid allianceId, int pageNumber, int pageSize, CancellationToken cancellationToken) { - var allianceZombieSieges = await context.ZombieSieges + var query = context.ZombieSieges .Where(zombieSiege => zombieSiege.AllianceId == allianceId) .OrderByDescending(zombieSiege => zombieSiege.EventDate) + .AsNoTracking(); + + var totalRecord = await query.CountAsync(cancellationToken); + + var pagedZombieSieges = await query + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) .ProjectTo(mapper.ConfigurationProvider) - .AsNoTracking() - .Take(take) .ToListAsync(cancellationToken); - return Result.Success(allianceZombieSieges); + return Result.Success(new PagedResponseDto + { + Data = pagedZombieSieges, + TotalRecords = totalRecord, + PageSize = pageSize, + PageNumber = pageNumber + }); } public async Task> CreateZombieSiegeAsync(CreateZombieSiegeDto createZombieSiegeDto, string createdBy, diff --git a/README.md b/README.md index bbd31d6..8f27ae5 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ This project is currently in the **Beta Phase**. --- +### **[0.6.0-beta]** - *2025-01-28* +#### ✨ Added +- **Pagination**: Implemented and adjusted for all tables. +- **Zombie Siege**: Expanded the table to display all waves survived by the entire alliance. + +#### 🛠️ Fixed +- *(N/A)* + ### **[0.5.1-beta]** - *2025-01-27* #### ✨ Added - *(N/A)* diff --git a/Ui/src/app/models/pagedResponse.model.ts b/Ui/src/app/models/pagedResponse.model.ts new file mode 100644 index 0000000..dde566c --- /dev/null +++ b/Ui/src/app/models/pagedResponse.model.ts @@ -0,0 +1,6 @@ +export interface PagedResponseModel { + totalRecords: number; + pageNumber: number; + pageSize: number; + data: T[] +} diff --git a/Ui/src/app/models/zombieSiege.model.ts b/Ui/src/app/models/zombieSiege.model.ts index 2060fb3..59d2451 100644 --- a/Ui/src/app/models/zombieSiege.model.ts +++ b/Ui/src/app/models/zombieSiege.model.ts @@ -10,6 +10,7 @@ export interface ZombieSiegeModel { allianceSize: number; level: number; totalLevel20Players: number; + totalWavesSurvived: number; } export interface ZombieSiegeDetailModel extends ZombieSiegeModel{ diff --git a/Ui/src/app/pages/custom-event/custom-event.component.html b/Ui/src/app/pages/custom-event/custom-event.component.html index f277ce3..0f915e0 100644 --- a/Ui/src/app/pages/custom-event/custom-event.component.html +++ b/Ui/src/app/pages/custom-event/custom-event.component.html @@ -115,7 +115,7 @@ - @for (customEvent of customEvents; track customEvent.id) { + @for (customEvent of customEvents | paginate: { id: 'customEventTable', itemsPerPage: pageSize, totalItems: totalRecord, currentPage: pageNumber}; track customEvent.id) { {{customEvent.eventDate | date: 'dd.MM.yyyy'}} {{customEvent.name}} @@ -145,6 +145,20 @@ + +
+ + + +
+ + Showing + {{ (pageNumber - 1) * pageSize + 1 }} - {{ pageNumber * pageSize > totalRecord ? totalRecord : pageNumber * pageSize }} + of {{ totalRecord }} results + +
+
} @else { + +
+ + + +
+ + Showing + {{ (pageNumber - 1) * pageSize + 1 }} - {{ pageNumber * pageSize > totalRecord ? totalRecord : pageNumber * pageSize }} + of {{ totalRecord }} results + +
+
} @else { + +
+ - + +
+ + Showing + {{ (pageNumber - 1) * pageSize + 1 }} - {{ pageNumber * pageSize > totalRecord ? totalRecord : pageNumber * pageSize }} + of {{ totalRecord }} results + +
+
} @else { + +
+ + + +
+ + Showing + {{ (pageNumber - 1) * pageSize + 1 }} - {{ pageNumber * pageSize > totalRecord ? totalRecord : pageNumber * pageSize }} + of {{ totalRecord }} results + +
+
} @else { } @else {
-

{{playerParticipated.length}} player(s) selected

+

{{ playerParticipated.length }} player(s) selected

}
- +
- +
} - @if(!isCreateZombieSiege) { + @if (!isCreateZombieSiege) { @if (zombieSieges.length > 0) {
@@ -72,29 +77,39 @@ + - @for (zombieSiege of zombieSieges; track zombieSiege.id) { + @for (zombieSiege of zombieSieges | paginate: { + id: 'zombieSiegeTable', + itemsPerPage: pageSize, + totalItems: totalRecord, + currentPage: pageNumber + }; track zombieSiege.id) { - - - - + + + - + + @@ -102,6 +117,20 @@
Level Alliance Size Survived 20 wavesTotal Waves Survived Creator Action
{{zombieSiege.eventDate | date: 'dd.MM.yyyy'}}{{zombieSiege.level}}{{zombieSiege.allianceSize}}{{zombieSiege.totalLevel20Players}} + {{ zombieSiege.eventDate | date: 'dd.MM.yyyy' }}{{ zombieSiege.level }}{{ zombieSiege.allianceSize }}{{ zombieSiege.totalLevel20Players }} @if (zombieSiege.totalLevel20Players < 20) { } @else { } {{zombieSiege.createdBy}}{{ zombieSiege.totalWavesSurvived }}{{ zombieSiege.createdBy }}
- - - + + +
+ +
+ + + +
+ + Showing + {{ (pageNumber - 1) * pageSize + 1 }} - {{ pageNumber * pageSize > totalRecord ? totalRecord : pageNumber * pageSize }} + of {{ totalRecord }} results + +
+
} @else {