Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace OJS.Services.Ui.Business.Implementations;
using OJS.Services.Infrastructure.Constants;
using OJS.Services.Infrastructure.Extensions;
using OJS.Services.Infrastructure.Models;
using OJS.Services.Infrastructure;
using OJS.Services.Ui.Business.Cache;
using OJS.Services.Ui.Business.Validations.Implementations.Contests;
using OJS.Services.Ui.Data;
Expand All @@ -34,7 +35,8 @@ public class ContestsBusinessService(
IContestParticipantsCacheService contestParticipantsCacheService,
IContestsCacheService contestsCacheService,
ILecturersInContestsCacheService lecturersInContestsCache,
IContestDetailsValidationService contestDetailsValidationService)
IContestDetailsValidationService contestDetailsValidationService,
IDatesService datesService)
: IContestsBusinessService
{
public async Task<ServiceResult<ContestDetailsServiceModel>> GetContestDetails(int id)
Expand Down Expand Up @@ -328,6 +330,8 @@ public async Task<ContestSearchServiceResultModel> GetSearchContestsByName(
.MapCollection<ContestForListingServiceModel>()
.ToPagedListAsync(model.PageNumber, model.ItemsPerPage);

this.SetContestVisibility(searchContests);

modelResult.Contests = searchContests;
modelResult.TotalContestsCount = allContestsQueryable.Count();

Expand All @@ -344,6 +348,8 @@ public async Task<PagedResult<ContestForListingServiceModel>> GetAllByFiltersAnd
var pagedContests =
await contestsData.GetAllAsPageByFiltersAndSorting<ContestForListingServiceModel>(model, includeHidden);

this.SetContestVisibility(pagedContests.Items);

var participantResultsByContest = new Dictionary<int, List<ParticipantResultServiceModel>>();
if (user.IsAuthenticated)
{
Expand Down Expand Up @@ -390,6 +396,8 @@ public async Task<PagedResult<ContestForListingServiceModel>> GetParticipatedByU
participatedContests,
sortAndFilterModel);

this.SetContestVisibility(participatedContestsInPage.Items);

var participantResultsByContest = new Dictionary<int, List<ParticipantResultServiceModel>>();
var loggedInUser = userProviderService.GetCurrentUser();

Expand Down Expand Up @@ -499,10 +507,16 @@ await pagedContests.Items.ForEachAsync(c =>
.ToListAsync();

public async Task<IEnumerable<ContestForListingServiceModel>> GetAllParticipatedContests(string username)
=> await contestsData
.GetLatestForParticipantByUsername(username)
.MapCollection<ContestForListingServiceModel>()
.ToListAsync();
{
var contests = await contestsData
.GetLatestForParticipantByUsername(username)
.MapCollection<ContestForListingServiceModel>()
.ToListAsync();

this.SetContestVisibility(contests);

return contests;
}

private static async Task<Dictionary<int, List<ParticipantResultServiceModel>>> MapParticipationResultsToContestsInPage(
IQueryable<Participant> participants)
Expand Down Expand Up @@ -565,4 +579,13 @@ private async Task<ContestFiltersServiceModel> GetNestedFilterCategoriesIfAny(Co
official,
isUserAdminOrLecturerInContest);
}

private void SetContestVisibility(IEnumerable<ContestForListingServiceModel> contests)
{
var now = datesService.GetUtcNow();
foreach (var contest in contests)
{
contest.IsVisible = contest.IsVisible || contest.VisibleFrom <= now;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ public void RegisterMappings(IProfileExpression configuration)
.SelectMany(pg => pg.Problems)
.Where(x => !x.IsDeleted)
.Sum(pr => pr.MaximumPoints)))
.ForMember(
c => c.IsVisible,
opt => opt.MapFrom(s => s.IsVisible || s.VisibleFrom <= DateTime.UtcNow))
// For online contests:
// In a problem group with multiple problems, compete points are derived from a single problem,
// unlike practice mode where points can be accumulated from all problems across groups.
Expand Down
Loading