public async Task <IActionResult> GetArtifacts(string ids = null, string title = null, ArtifactType?type = null, ArtifactStatus?status = null, int?memberId = null, int?communityId = null, int page = 1, int pageSize = 20) { var criteriaModel = new ArtifactCriteriaModel { Ids = ids?.SafeSplit(), Title = title, Type = type, Status = status, MemberId = memberId, CommunityId = communityId, Page = page, PageSize = pageSize }; var validationResults = _criteriaValidator.Validate(criteriaModel); if (validationResults.IsValid) { return(Ok(await _artifactService.GetArtifacts(criteriaModel).ConfigureAwait(false))); } validationResults.AddToModelState(ModelState, null); return(BadRequest(ModelState)); }
public async Task <ArtifactResponseModel> GetArtifacts(ArtifactCriteriaModel criteriaModel) { var artifactCriteria = _modelFactory.CreateArtifactCrtieria(criteriaModel); var resultCount = await _artifactDao.CountArtifact(artifactCriteria).ConfigureAwait(false); var artifactResponse = new ArtifactResponse { Links = CreateLinks(artifactCriteria.Page, artifactCriteria.PageSize, resultCount), Results = await CreateResults(artifactCriteria, resultCount).ConfigureAwait(false) }; return(_modelFactory.CreateArtifactResponseModel(artifactResponse)); }
public ArtifactCriteria CreateArtifactCrtieria(ArtifactCriteriaModel criteriaModel) { return(new ArtifactCriteria { Ids = criteriaModel.Ids?.Select(int.Parse), Title = criteriaModel.Title, Type = criteriaModel.Type, Status = criteriaModel.Status, CommunityId = criteriaModel.CommunityId, MemberId = criteriaModel.MemberId, Page = criteriaModel.Page, PageSize = criteriaModel.PageSize }); }
public void Should_not_return_Artifacts_When_page_do_not_exist() { _artifactDao.CountArtifact(Arg.Any <ArtifactCriteria>()).ReturnsForAnyArgs(50); _artifactDao.GetArtifacts(Arg.Any <ArtifactCriteria>()) .ReturnsForAnyArgs(_fixture.CreateMany <Artifact>(50)); var criteria = new ArtifactCriteriaModel { Page = 10, PageSize = 20 }; var results = _artifactRepo.GetArtifacts(criteria).Result; results.Results.Should().BeEmpty(); }
public void Should_validate_criteria_when_no_filter_was_specified() { var criteria = new ArtifactCriteriaModel { Ids = null, Status = null, Title = null, Type = null, PageSize = 20, Page = 1 }; _validator.ShouldNotHaveValidationErrorFor(x => x.Ids, criteria); _validator.ShouldNotHaveValidationErrorFor(x => x.Status, criteria); _validator.ShouldNotHaveValidationErrorFor(x => x.Title, criteria); _validator.ShouldNotHaveValidationErrorFor(x => x.Type, criteria); _validator.ShouldNotHaveValidationErrorFor(x => x.PageSize, criteria); _validator.ShouldNotHaveValidationErrorFor(x => x.Page, criteria); }
public async Task <ArtifactResponseModel> GetArtifacts(ArtifactCriteriaModel criteriaModel) { return(await _artifactRepo.GetArtifacts(criteriaModel).ConfigureAwait(false)); }