[HttpHead] // return the infomation of the server (infomation in the header) to client public IActionResult GetBands([FromQuery] BandResourceParameters bandResourceParameters) // It will automatically map to the query strings? { if (!_propertyMappingService.ValidMappingExists <BandDto, Band>(bandResourceParameters.OrderBy)) { return(BadRequest()); } if (!_propertyValidationService.HasValidProperties <BandDto>(bandResourceParameters.Fields)) { return(BadRequest()); } var bandsFromRepo = _bandAlbumRepository.GetBands(bandResourceParameters); var previousPagePageLink = bandsFromRepo.HasPrevious ? CreateBandsUri(bandResourceParameters, UriType.PreviousPage) : null; var nextPageLink = bandsFromRepo.HasNext ? CreateBandsUri(bandResourceParameters, UriType.NextPage) : null; var metaData = new { totalCount = bandsFromRepo.TotalCount, pageSize = bandsFromRepo.PageSize, currentPage = bandsFromRepo.CurrentPage, totalPages = bandsFromRepo.TotalPages, previousPagePageLink, nextPageLink, }; Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData)); // Adding the Pagination Header to the Response return(Ok(_mapper.Map <IEnumerable <BandDto> >(bandsFromRepo).ShapeData(bandResourceParameters.Fields))); // Serialise the Data to JSON }
public IActionResult GetBands([FromQuery] BandsResourceParameters parameters) { if (!_propertyMappingService.ValidMappingExists <BandDto, Band>(parameters.OrderBy)) { return(BadRequest()); } if (!_propertyValidationService.HasValidProperties <BandDto>(parameters.Fields)) { return(BadRequest()); } PagedList <Band> bands = _bandAlbumRepository.GetBands(parameters); string previousPageLink = bands.HasPrevious ? CreateBandsUri(parameters, UriType.PreviousPage) : null; string nextPageLink = bands.hasNext ? CreateBandsUri(parameters, UriType.NextPage) : null; var metaData = new { totalCount = bands.TotalCount, pageSize = bands.PageSize, currentPage = bands.CurrentPage, totalPages = bands.TotalPages, previousPageLink, nextPageLink }; Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData)); return(Ok(_mapper.Map <IEnumerable <BandDto> >(bands).ShapeData(parameters.Fields))); }
public IActionResult GetServiceInfos([FromQuery] ServiceInfoResourceParameters postResourceParameters) { if (!_propertyMapping.ValidMappingExist <ServiceInfoOutputDto, ServiceInfo>(postResourceParameters.OrderBy)) { return(BadRequest()); } if (!_propertyValidation.HasValidProperties <ServiceInfoOutputDto>(postResourceParameters.Fields)) { return(BadRequest()); } var serviceInfoFromRepo = _serviceInfoRepository.GetServiceInfos(postResourceParameters); var previousPageLink = serviceInfoFromRepo.HasPrevious ? CreateServiceInfosUri(postResourceParameters, UriType.PreviousPage, "GetServiceInfos") : null; var nextPageLink = serviceInfoFromRepo.HasNext ? CreateServiceInfosUri(postResourceParameters, UriType.NextPage, "GetServiceInfos") : null; var metaData = new { totalCount = serviceInfoFromRepo.TotalCount, pageSize = serviceInfoFromRepo.PageSize, currentPage = serviceInfoFromRepo.CurrentPage, totalPages = serviceInfoFromRepo.TotalPages, previousPageLink, nextPageLink, }; Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData)); return(Ok(_mapper.Map <IEnumerable <ServiceInfoOutputDto> >(serviceInfoFromRepo).ShapeData(postResourceParameters.Fields))); }
public async Task <IActionResult> GetCommentsForPost([FromQuery] CommentResourceParameters commentResourceParameters, Guid postId) { if (!_propertyMapping.ValidMappingExist <CommentOutputDto, Comment>(commentResourceParameters.OrderBy)) { return(BadRequest()); } if (!_propertyValidation.HasValidProperties <CommentOutputDto>(commentResourceParameters.Fields)) { return(BadRequest()); } var commentsFromRepo = _commentRepository.GetCommentsForPost(postId, commentResourceParameters); var previousPageLink = commentsFromRepo.HasPrevious ? CreateCommentsUri(commentResourceParameters, UriType.PreviousPage, "GetCommentsForPost") : null; var nextPageLink = commentsFromRepo.HasNext ? CreateCommentsUri(commentResourceParameters, UriType.NextPage, "GetCommentsForPost") : null; var metaData = new { totalCount = commentsFromRepo.TotalCount, pageSize = commentsFromRepo.PageSize, currentPage = commentsFromRepo.CurrentPage, totalPages = commentsFromRepo.TotalPages, previousPageLink, nextPageLink, }; Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData)); return(Ok(_mapper.Map <IEnumerable <CommentOutputDto> >(commentsFromRepo).ShapeData(commentResourceParameters.Fields))); }
public IActionResult GetBands( [FromQuery] BandsResourceParameters bandsResourceParameters) { if (!_propertyMappingService.ValidMappingExists <BandDto, Entities.Band> (bandsResourceParameters.OrderBy)) { return(BadRequest()); } if (!_propertyValidationService.HasValidProperties <BandDto> (bandsResourceParameters.Fields)) { return(BadRequest()); } var bandsFromRepo = _bandAlbumRepository.GetBands(bandsResourceParameters); var metaData = new { totalCount = bandsFromRepo.TotalCount, pageSize = bandsFromRepo.PageSize, currentPage = bandsFromRepo.CurrentPage, totalPages = bandsFromRepo.TotalPages }; Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData)); var links = CreateLinksForBands(bandsResourceParameters, bandsFromRepo.HasNext, bandsFromRepo.HasPrevious); var shapedBands = _mapper.Map <IEnumerable <BandDto> >(bandsFromRepo) .ShapeData(bandsResourceParameters.Fields); var shapedBandsWithLinks = shapedBands.Select(band => { var bandAsDictionary = band as IDictionary <string, object>; var bandLinks = CreateLinksForBand((Guid)bandAsDictionary["Id"], null); bandAsDictionary.Add("links", bandLinks); return(bandAsDictionary); }); var linkedCollectionResource = new { value = shapedBandsWithLinks, links }; return(Ok(linkedCollectionResource)); }
public async Task <IActionResult> GetAllFollowers(Guid userId, [FromQuery] string fields) { if (!_propertyValidation.HasValidProperties <UserBriefOutputDto>(fields)) { return(BadRequest()); } if (userId == Guid.Empty) { userId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)); } var allFollowers = await _userRepository.GetAllFollowers(userId).ConfigureAwait(false); var allFollwersToReturn = _mapper.Map <IEnumerable <UserBriefOutputDto> >(allFollowers); return(Ok(allFollwersToReturn.ShapeData(fields))); }