Exemple #1
0
        public async Task <Result <GetRecordsForArtistByIdResponse> > Handle(GetRecordsForArtistByIdRequest request, CancellationToken cancellationToken)
        {
            var searchRecordsForArtistRequest = new SearchRecordsForArtistByIdRequest
            {
                CorrelationId = request.CorrelationId,
                ArtistId      = request.ArtistId
            };

            var operation = await _mediator.Send(searchRecordsForArtistRequest, cancellationToken);

            if (!operation.Status)
            {
                return(Result <GetRecordsForArtistByIdResponse> .Failure(operation.ErrorCode, operation.Validation));
            }

            var records = operation.Data?.Records?.ToList() ?? new List <Record>();

            if (!records.Any())
            {
                return(Result <GetRecordsForArtistByIdResponse> .Failure(ErrorCodes.ArtistRecordsNotFound, "No records found for the artist."));
            }

            var recordModels = records.Select(x => new Responses.Record
            {
                Id   = x.Id,
                Name = x.Title
            }).ToList();

            return(Result <GetRecordsForArtistByIdResponse> .Success(new GetRecordsForArtistByIdResponse
            {
                Records = recordModels
            }));
        }
        public async Task <Result <SearchRecordsForArtistByIdResponseDto> > Handle(SearchRecordsForArtistByIdRequestDto request, CancellationToken cancellationToken)
        {
            var getRecordsForArtistIdRequest = new GetRecordsForArtistByIdRequest
            {
                CorrelationId = request.CorrelationId,
                ArtistId      = request.ArtistId
            };

            var operation = await _mediator.Send(getRecordsForArtistIdRequest, cancellationToken);

            if (!operation.Status)
            {
                return(Result <SearchRecordsForArtistByIdResponseDto> .Failure(operation.ErrorCode, operation.Validation));
            }

            var records = operation.Data.Records;

            if (records == null || !records.Any())
            {
                return(Result <SearchRecordsForArtistByIdResponseDto> .Failure(ErrorCodes.ArtistRecordsNotFound, "Records for the artist were not found."));
            }

            var recordDtos = records.Select(x => new RecordDto
            {
                Id    = x.Id,
                Title = x.Name,
            }).ToList();

            var response = new SearchRecordsForArtistByIdResponseDto
            {
                Records = recordDtos
            };

            return(Result <SearchRecordsForArtistByIdResponseDto> .Success(response));
        }
Exemple #3
0
 public GetRecordsForArtistByIdRequestValidatorTests(TestsInitializer testsInitializer)
 {
     _validator = new GetRecordsForArtistByIdRequestValidator();
     _request   = testsInitializer.Fixture.Create <GetRecordsForArtistByIdRequest>();
 }