Skip to content

Commit 53d1312

Browse files
evandonovaevandonova
andauthored
Added endpoint for getting contest participants' emails (#1532)
Add old judge endpoint to alpha judge Closes SoftUni-Internal/exam-systems-issues#1587 --------- Co-authored-by: evandonova <evelina.andonova@softuni.bg>
1 parent 4fbfe35 commit 53d1312

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

Servers/UI/OJS.Servers.Ui/Controllers/ContestsController.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
using OJS.Services.Infrastructure.Extensions;
1010
using OJS.Services.Ui.Business;
1111
using OJS.Services.Ui.Models.Contests;
12+
using System.Collections.Generic;
13+
using System.ComponentModel.DataAnnotations;
1214
using System.Threading.Tasks;
1315
using static Microsoft.AspNetCore.Http.StatusCodes;
16+
using static OJS.Servers.Infrastructure.ServerConstants.Authorization;
1417

1518
public class ContestsController : BaseApiController
1619
{
@@ -89,4 +92,17 @@ public async Task<IActionResult> GetParticipatedByUser(
8992
.GetParticipatedByUserByFiltersAndSorting(username, model?.Map<ContestFiltersServiceModel>())
9093
.Map<PagedResultResponse<ContestForListingResponseModel>>()
9194
.ToOkResult();
95+
96+
/// <summary>
97+
/// Gets the emails of all participants in a given contest.
98+
/// </summary>
99+
/// <param name="contestId">The id of the contest.</param>
100+
/// <returns>Results in json format.</returns>
101+
[HttpGet]
102+
[ProducesResponseType(typeof(IEnumerable<string?>), Status200OK)]
103+
[Authorize(ApiKeyPolicyName)]
104+
public async Task<IActionResult> GetEmailsOfParticipantsInContest([Required] int contestId)
105+
=> await this.contestsBusinessService
106+
.GetEmailsOfParticipantsInContest(contestId)
107+
.ToOkResult();
92108
}

Services/UI/OJS.Services.Ui.Business/IContestsBusinessService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ Task<PagedResult<ContestForListingServiceModel>> PrepareActivityAndResults(
3939

4040
Task<Dictionary<int, List<ParticipantResultServiceModel>>> GetUserParticipantResultsForContestInPage(
4141
ICollection<int> contestIds);
42+
43+
Task<IEnumerable<string?>> GetEmailsOfParticipantsInContest(int contestId);
4244
}
4345
}

Services/UI/OJS.Services.Ui.Business/Implementations/ContestsBusinessService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ await pagedContests.Items.ForEachAsync(c =>
516516
return pagedContests;
517517
}
518518

519+
public async Task<IEnumerable<string?>> GetEmailsOfParticipantsInContest(int contestId)
520+
=> await this.participantsData
521+
.GetAllOfficialByContest(contestId)
522+
.Select(participant => participant.User.Email!)
523+
.ToListAsync();
524+
519525
private static async Task<Dictionary<int, List<ParticipantResultServiceModel>>> MapParticipationResultsToContestsInPage(
520526
IQueryable<Participant> participants)
521527
=> await participants

Services/UI/OJS.Services.Ui.Data/IParticipantsDataService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public interface IParticipantsDataService : IDataService<Participant>
2020

2121
IQueryable<Participant> GetAllByContestWithScoresAndProblems(int contestId);
2222

23+
IQueryable<Participant> GetAllOfficialByContest(int contestId);
24+
2325
Task<bool> ExistsByContestByUserAndIsOfficial(int contestId, string userId, bool isOfficial);
2426

2527
Task<IDictionary<int, int>> GetParticipantsCountInContests(IEnumerable<int> contestIds, bool isOfficial);

Services/UI/OJS.Services.Ui.Data/Implementations/ParticipantsDataService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public IQueryable<Participant> GetAllByContestWithScoresAndProblems(int contestI
4747
.ThenInclude(s => s.Problem)
4848
.ThenInclude(p => p.ProblemGroup);
4949

50+
public IQueryable<Participant> GetAllOfficialByContest(int contestId)
51+
=> this.GetAllByContest(contestId)
52+
.Where(p => p.IsOfficial);
53+
5054
public Task<bool> ExistsByContestByUserAndIsOfficial(int contestId, string userId, bool isOfficial)
5155
=> this.GetAllByContestByUserAndIsOfficial(contestId, userId, isOfficial)
5256
.AnyAsync();

0 commit comments

Comments
 (0)