public async Task <IEnumerable <Apprenticeship.Apprenticeship> > GetApprenticeships(long accountId)
        {
            _logger.Trace($"Getting apprenticeships for employer account {accountId}", accountId: accountId);

            var response = await _mediator.SendAsync(new GetApprenticeshipsRequest
            {
                Caller = new Caller {
                    CallerType = CallerType.Employer, Id = accountId
                }
            });

            _logger.Info($"Retrieved apprenticeships for employer account {accountId}. {response.Apprenticeships.Count} apprenticeships found", accountId: accountId);

            return(_apprenticeshipMapper.MapFromV2(response.Apprenticeships, CallerType.Employer));
        }
Exemple #2
0
        public async Task <ApprenticeshipSearchResponse> GetApprenticeships(long providerId, ApprenticeshipSearchQuery query)
        {
            _logger.Trace($"Getting apprenticeships with filter query for provider {providerId}. Page: {query.PageNumber}, PageSize: {query.PageSize}", providerId: providerId);
            _logger.Info($"Searching for {query.SearchKeyword} by Provider {providerId}", providerId: providerId);

            var response = await _mediator.SendAsync(new GetApprenticeshipsRequest
            {
                Caller = new Caller
                {
                    CallerType = CallerType.Provider,
                    Id         = providerId
                }
            });

            var apiApprenticeships = _apprenticeshipMapper.MapFromV2(response.Apprenticeships, CallerType.Provider).ToList();

            var totalApprenticeshipsBeforeFilter = response.TotalCount - apiApprenticeships.Count(m => m.PaymentStatus == PaymentStatus.PendingApproval);
            var approvedApprenticeships          = apiApprenticeships
                                                   .Where(m => m.PaymentStatus != PaymentStatus.PendingApproval).ToList();

            _logger.Info($"Searching for {query.SearchKeyword} by Provider {providerId}", providerId: providerId);

            var facets = _facetMapper.BuildFacets(approvedApprenticeships, query, Originator.Provider);
            var filteredApprenticeships = _apprenticeshipFilterService.Filter(approvedApprenticeships, query, Originator.Provider);

            _logger.Info($"Retrieved {approvedApprenticeships.Count} apprenticeships with filter query for provider {providerId}. Page: {query.PageNumber}, PageSize: {query.PageSize}", providerId: providerId);

            return(new ApprenticeshipSearchResponse
            {
                Apprenticeships = filteredApprenticeships.PageOfResults,
                SearchKeyword = query.SearchKeyword,
                Facets = facets,
                TotalApprenticeships = filteredApprenticeships.TotalResults,
                TotalApprenticeshipsBeforeFilter = totalApprenticeshipsBeforeFilter,
                PageNumber = filteredApprenticeships.PageNumber,
                PageSize = filteredApprenticeships.PageSize
            });
        }