@Test public void findRequestsForUser() { Principal user = mock(Principal.class, RETURNS_DEEP_STUBS); List<Request> requests = singletonList(RequestMother.freeCodeCampNoUserStories().build()); when(requestRepository.findRequestsUserIsWatching(user.getName())).thenReturn(requests); List<String> addresses = Collections.singletonList("0x0"); when(profileService.getUserProfile(user).getEtherAddresses()).thenReturn(addresses); List<Request> fundedRequests = singletonList(RequestMother.fundRequestArea51().build()); when(requestRepository.findRequestsUserHasFunded(user.getName(), addresses)).thenReturn(fundedRequests); HashSet<Request> userRequets = new HashSet<>(); userRequets.addAll(requests); userRequets.addAll(fundedRequests); List<RequestDto> expectedRequests = Arrays.asList(RequestDtoMother.freeCodeCampNoUserStories(), RequestDtoMother.fundRequestArea51()); when(mappers.mapList(Request.class, RequestDto.class, userRequets)).thenReturn(expectedRequests); List<RequestDto> result = requestService.findRequestsForUser(user); assertThat(result).isEqualTo(expectedRequests); }
@Override @Transactional(readOnly = true) public List<RequestDto> findRequestsForUser(Principal principal) { Set<Request> result = new HashSet<>(); List<String> etherAddresses = profileService.getUserProfile(principal).getEtherAddresses(); result.addAll(requestRepository.findRequestsUserIsWatching(principal.getName())); List<String> userAddresses = etherAddresses.stream().map(String::toLowerCase).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(userAddresses)) { result.addAll(requestRepository.findRequestsUserHasFunded(principal.getName(), userAddresses)); } return mappers.mapList(Request.class, RequestDto.class, result); }
RequestServiceImpl implements RequestService { @Override @Transactional(readOnly = true) public List<RequestDto> findRequestsForUser(Principal principal) { Set<Request> result = new HashSet<>(); List<String> etherAddresses = profileService.getUserProfile(principal).getEtherAddresses(); result.addAll(requestRepository.findRequestsUserIsWatching(principal.getName())); List<String> userAddresses = etherAddresses.stream().map(String::toLowerCase).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(userAddresses)) { result.addAll(requestRepository.findRequestsUserHasFunded(principal.getName(), userAddresses)); } return mappers.mapList(Request.class, RequestDto.class, result); } }
RequestServiceImpl implements RequestService { @Override @Transactional(readOnly = true) public List<RequestDto> findRequestsForUser(Principal principal) { Set<Request> result = new HashSet<>(); List<String> etherAddresses = profileService.getUserProfile(principal).getEtherAddresses(); result.addAll(requestRepository.findRequestsUserIsWatching(principal.getName())); List<String> userAddresses = etherAddresses.stream().map(String::toLowerCase).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(userAddresses)) { result.addAll(requestRepository.findRequestsUserHasFunded(principal.getName(), userAddresses)); } return mappers.mapList(Request.class, RequestDto.class, result); } RequestServiceImpl(final RequestRepository requestRepository,
                              final Mappers mappers,
                              final GithubPlatformIdParser githubLinkParser,
                              final ProfileService profileService,
                              final ClaimRepository claimRepository,
                              final GithubGateway githubGateway,
                              final GithubClaimResolver githubClaimResolver,
                              final ApplicationEventPublisher eventPublisher,
                              final Erc67Generator erc67Generator,
                              final Environment environment); }
RequestServiceImpl implements RequestService { @Override @Transactional(readOnly = true) public List<RequestDto> findRequestsForUser(Principal principal) { Set<Request> result = new HashSet<>(); List<String> etherAddresses = profileService.getUserProfile(principal).getEtherAddresses(); result.addAll(requestRepository.findRequestsUserIsWatching(principal.getName())); List<String> userAddresses = etherAddresses.stream().map(String::toLowerCase).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(userAddresses)) { result.addAll(requestRepository.findRequestsUserHasFunded(principal.getName(), userAddresses)); } return mappers.mapList(Request.class, RequestDto.class, result); } RequestServiceImpl(final RequestRepository requestRepository,
                              final Mappers mappers,
                              final GithubPlatformIdParser githubLinkParser,
                              final ProfileService profileService,
                              final ClaimRepository claimRepository,
                              final GithubGateway githubGateway,
                              final GithubClaimResolver githubClaimResolver,
                              final ApplicationEventPublisher eventPublisher,
                              final Erc67Generator erc67Generator,
                              final Environment environment); @Override @Transactional(readOnly = true) List<RequestDto> findAll(); @Transactional(readOnly = true) List<RequestDto> findAllFor(final List<String> projects, final List<String> technologies, final Long lastUpdatedSinceDays); @Override @Transactional(readOnly = true) List<RequestDto> findAll(Iterable<Long> ids); @Override @Transactional(readOnly = true) @Cacheable(value = "technologies", key = "'all'") Set<String> findAllTechnologies(); @Override @Transactional(readOnly = true) @Cacheable(value = "projects", key = "'all'") Set<String> findAllProjects(); @Override @Transactional UserClaimableDto getUserClaimableResult(final Principal principal, final Long requestId); @Override @Transactional ClaimableResultDto getClaimableResult(final Long requestId); @Override @Transactional(readOnly = true) List<RequestDto> findRequestsForUser(Principal principal); @Override @Transactional(readOnly = true) RequestDto findRequest(Long id); @Override @Transactional(readOnly = true) List<CommentDto> getComments(Long requestId); @Override @Transactional(readOnly = true) RequestDto findRequest(Platform platform, String platformId); @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") Long createRequest(CreateRequestCommand command); @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") Request requestClaimed(RequestClaimedCommand command); @Override @Transactional(readOnly = true) SignedClaim signClaimRequest(Principal user, UserClaimRequest userClaimRequest); @Override @Transactional(readOnly = true) Boolean canClaim(Principal user, CanClaimRequest canClaimRequest); @Override @Transactional void addWatcherToRequest(Principal principal, Long requestId); @Override @Transactional void removeWatcherFromRequest(Principal principal, Long requestId); @Override String generateERC67(final CreateERC67FundRequest createERC67FundRequest); @Override void update(final UpdateRequestStatusCommand command); }
RequestServiceImpl implements RequestService { @Override @Transactional(readOnly = true) public List<RequestDto> findRequestsForUser(Principal principal) { Set<Request> result = new HashSet<>(); List<String> etherAddresses = profileService.getUserProfile(principal).getEtherAddresses(); result.addAll(requestRepository.findRequestsUserIsWatching(principal.getName())); List<String> userAddresses = etherAddresses.stream().map(String::toLowerCase).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(userAddresses)) { result.addAll(requestRepository.findRequestsUserHasFunded(principal.getName(), userAddresses)); } return mappers.mapList(Request.class, RequestDto.class, result); } RequestServiceImpl(final RequestRepository requestRepository,
                              final Mappers mappers,
                              final GithubPlatformIdParser githubLinkParser,
                              final ProfileService profileService,
                              final ClaimRepository claimRepository,
                              final GithubGateway githubGateway,
                              final GithubClaimResolver githubClaimResolver,
                              final ApplicationEventPublisher eventPublisher,
                              final Erc67Generator erc67Generator,
                              final Environment environment); @Override @Transactional(readOnly = true) List<RequestDto> findAll(); @Transactional(readOnly = true) List<RequestDto> findAllFor(final List<String> projects, final List<String> technologies, final Long lastUpdatedSinceDays); @Override @Transactional(readOnly = true) List<RequestDto> findAll(Iterable<Long> ids); @Override @Transactional(readOnly = true) @Cacheable(value = "technologies", key = "'all'") Set<String> findAllTechnologies(); @Override @Transactional(readOnly = true) @Cacheable(value = "projects", key = "'all'") Set<String> findAllProjects(); @Override @Transactional UserClaimableDto getUserClaimableResult(final Principal principal, final Long requestId); @Override @Transactional ClaimableResultDto getClaimableResult(final Long requestId); @Override @Transactional(readOnly = true) List<RequestDto> findRequestsForUser(Principal principal); @Override @Transactional(readOnly = true) RequestDto findRequest(Long id); @Override @Transactional(readOnly = true) List<CommentDto> getComments(Long requestId); @Override @Transactional(readOnly = true) RequestDto findRequest(Platform platform, String platformId); @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") Long createRequest(CreateRequestCommand command); @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") Request requestClaimed(RequestClaimedCommand command); @Override @Transactional(readOnly = true) SignedClaim signClaimRequest(Principal user, UserClaimRequest userClaimRequest); @Override @Transactional(readOnly = true) Boolean canClaim(Principal user, CanClaimRequest canClaimRequest); @Override @Transactional void addWatcherToRequest(Principal principal, Long requestId); @Override @Transactional void removeWatcherFromRequest(Principal principal, Long requestId); @Override String generateERC67(final CreateERC67FundRequest createERC67FundRequest); @Override void update(final UpdateRequestStatusCommand command);  }