Exemplo n.º 1
0
        public async Task <Result <SearchArtistByNameResponseDto> > Handle(SearchArtistByNameRequestDto request, CancellationToken cancellationToken)
        {
            var getArtistByNameRequest = new GetArtistByNameRequest
            {
                CorrelationId = request.CorrelationId,
                Name          = request.ArtistName
            };

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

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

            var artists = operation.Data?.Artists;

            if (artists == null || !artists.Any())
            {
                return(Result <SearchArtistByNameResponseDto> .Failure(ErrorCodes.ArtistNotFound, "Artist not found."));
            }

            var artistDtos = artists.Select(x => new ArtistDto
            {
                ArtistId   = x.ArtistId,
                ArtistName = x.ArtistName
            }).ToList();

            var response = new SearchArtistByNameResponseDto
            {
                Artists = artistDtos
            };

            return(Result <SearchArtistByNameResponseDto> .Success(response));
        }
        public async Task <IActionResult> SearchAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "music/search/artist")]
                                                      HttpRequest request)
        {
            var correlationId          = request.GetHeaderValue("correlationId");
            var artistName             = request.GetQueryStringValue("name");
            var searchArtistRequestDto = new SearchArtistByNameRequestDto
            {
                CorrelationId = correlationId,
                ArtistName    = artistName
            };

            var operation = await _mediator.Send(searchArtistRequestDto);

            return(_responseFormatter.GetActionResult(operation));
        }
Exemplo n.º 3
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 SearchArtistByNameRequestDtoValidatorTests(TestsInitializer testsInitializer)
 {
     _validator = new SearchArtistByNameRequestDtoValidator();
     _request   = testsInitializer.Fixture.Create <SearchArtistByNameRequestDto>();
 }