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));
        }
        public SearchRecordsForArtistIdHandlerTests(TestsInitializer testsInitializer)
        {
            _testsInitializer = testsInitializer;

            _request  = _testsInitializer.Fixture.Create <SearchRecordsForArtistByIdRequestDto>();
            _mediator = new Mock <IMediator>();
            _handler  = new SearchRecordsForArtistIdHandler(_mediator.Object);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SearchAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "music/search/records/artist/{artistId}")]
                                                      HttpRequest request, string artistId)
        {
            var correlationId          = request.GetHeaderValue("correlationId");
            var searchArtistRequestDto = new SearchRecordsForArtistByIdRequestDto
            {
                CorrelationId = correlationId,
                ArtistId      = artistId
            };

            var operation = await _mediator.Send(searchArtistRequestDto);

            return(_responseFormatter.GetActionResult(operation));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> SearchAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "myapp/music/artist")]
                                                      HttpRequest request)
        {
            var correlationId = request.GetHeaderValue("correlationId");
            var artistName    = request.GetQueryStringValue("name");

            var searchArtistRequest = new SearchArtistByNameRequestDto
            {
                CorrelationId = correlationId,
                ArtistName    = artistName
            };

            var artistSearchOperation = await _mediator.Send(searchArtistRequest);

            if (!artistSearchOperation.Status)
            {
                return(_artistResponseFormatter.GetActionResult(artistSearchOperation));
            }

            var artists = artistSearchOperation.Data.Artists;

            if (artists.Count > 1)
            {
                return(_artistResponseFormatter.GetActionResult(artistSearchOperation));
            }

            var artistId            = artists.First().ArtistId;
            var getRecordsForArtist = new SearchRecordsForArtistByIdRequestDto
            {
                CorrelationId = correlationId,
                ArtistId      = artistId
            };

            var getRecordsForArtistOperation = await _mediator.Send(getRecordsForArtist);

            var records = getRecordsForArtistOperation.Status ? getRecordsForArtistOperation.Data.Records : new List <RecordDto>();

            var response = new SearchArtistByNameResponse
            {
                ArtistId   = artistId,
                ArtistName = artistName,
                Records    = records
            };

            return(new OkObjectResult(response));
        }
 public SearchRecordsForArtistByIdRequestDtoValidatorTests(TestsInitializer testsInitializer)
 {
     _validator = new SearchRecordsForArtistByIdRequestDtoValidator();
     _request   = testsInitializer.Fixture.Create <SearchRecordsForArtistByIdRequestDto>();
 }