public async Task <string> Handle(RunParticipationCommand request, CancellationToken cancellationToken) { var participation = await _participationsSessionsRepository.FindByIdAsync(new ParticipationId(request.ParticipationId)); if (participation is null) { throw new NotFoundException(request.ParticipationId.ToString(), "ParticipationSession"); } participation.ValidateProcessStart(_currentUserService.UserId); var step = await _readStepRepository.GetOneStepNavigationById(participation.StepEntity.Id.Value); if (step is null) { throw new NotFoundException(participation.StepEntity.Id.Value.ToString(), "ParticipationSessionStep"); } var language = await _readProgrammingLanguageRepository.GetOneLanguageNavigationByIdAsync(step.LanguageId); if (language is null) { throw new NotFoundException(step.LanguageId.ToString(), "ParticipationSessionStepLanguage"); } var tests = await _readTestRepository.GetAllTestNavigationByStepId(participation.StepEntity.Id.Value); var runTestDto = new RunParticipationTestsDto( participation.Id.Value, language.Name, step.HeaderCode, tests.Select(t => new RunParticipationTestsDto.Test(t.Id, t.Name, t.OutputValidator, t.InputGenerator)) .ToList(), participation.Functions .Where(f => f.Order is not null) .Select(f => new RunParticipationTestsDto.Function(f.Id.Value, f.Code, f.Order !.Value)) .ToList() ); participation.StartProcess(_timeService.Now()); _participationExecutionService.Dispatch(runTestDto); await _participationsSessionsRepository.SetAsync(participation); return(await Task.FromResult(request.ParticipationId.ToString())); }
public async Task <ParticipationSessionAggregate?> FindByIdAsync(ParticipationId id) { var cacheParticipation = await _cache.GetCache <ParticipationSession>(id); if (cacheParticipation is not null) { return(ToAggregate(cacheParticipation)); } var participation = await _participationRepository.FindByIdAsync(id); if (participation is null) { return(null); } var tests = await _readTestRepository.GetAllTestNavigationByStepId(participation.StepEntity.Id.Value); var participationSession = ToAggregate(participation, tests); await _cache.SetCache(ToModel(participationSession), participationSession.Id.Value, _settings.ParticipationSecondDuration); return(participationSession); }