Skip to content

Commit

Permalink
return time entries for every asked userLocalId
Browse files Browse the repository at this point in the history
  • Loading branch information
bseber committed May 3, 2023
1 parent 190813f commit 3509f64
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ public Map<UserLocalId, List<TimeEntry>> getEntriesByUserLocalIds(LocalDate from

final Map<UserId, UserLocalId> userLocalIdById = users.stream().collect(toMap(User::id, User::localId));

final List<TimeEntryEntity> result = timeEntryRepository
.findAllByOwnerIsInAndStartGreaterThanEqualAndStartLessThan(userIdValues, fromInstant, toInstant);

return result
final Map<UserLocalId, List<TimeEntry>> result = timeEntryRepository
.findAllByOwnerIsInAndStartGreaterThanEqualAndStartLessThan(userIdValues, fromInstant, toInstant)
.stream()
.map(TimeEntryServiceImpl::toTimeEntry)
// TODO add empty list entry for users without time entries
.collect(groupingBy(timeEntry -> userLocalIdById.get(timeEntry.userId())));

for (UserLocalId userLocalId : userLocalIds) {
result.computeIfAbsent(userLocalId, (unused) -> List.of());
}

return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,27 @@ void ensureGetEntriesByUserLocalIds() {
});
}

@Test
void ensureGetEntriesByUserLocalIdsReturnsValuesForEveryAskedUserLocalId() {

final UserLocalId batmanLocalId = new UserLocalId(1L);

when(userManagementService.findAllUsersByLocalIds(List.of(batmanLocalId))).thenReturn(List.of());

final LocalDate from = LocalDate.of(2023, 1, 1);
final LocalDate toExclusive = LocalDate.of(2023, 2, 1);

when(timeEntryRepository.findAllByOwnerIsInAndStartGreaterThanEqualAndStartLessThan(List.of(), from.atStartOfDay(UTC).toInstant(), toExclusive.atStartOfDay(UTC).toInstant()))
.thenReturn(List.of());

final Map<UserLocalId, List<TimeEntry>> actual = sut.getEntriesByUserLocalIds(from, toExclusive, List.of(batmanLocalId));

assertThat(actual).hasSize(1);
assertThat(actual).hasEntrySatisfying(batmanLocalId, timeEntries -> {
assertThat(timeEntries).isEmpty();
});
}

@Test
void ensureGetEntriesSortedByStart_NewestFirst() {

Expand Down

0 comments on commit 3509f64

Please sign in to comment.