Skip to content

Commit 2c2a315

Browse files
bseberderTobsch
authored andcommitted
return time entries for every asked userLocalId
1 parent 7f57af1 commit 2c2a315

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/main/java/de/focusshift/zeiterfassung/timeentry/TimeEntryServiceImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,17 @@ public Map<UserLocalId, List<TimeEntry>> getEntriesByUserLocalIds(LocalDate from
115115

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

118-
final List<TimeEntryEntity> result = timeEntryRepository
119-
.findAllByOwnerIsInAndStartGreaterThanEqualAndStartLessThan(userIdValues, fromInstant, toInstant);
120-
121-
return result
118+
final Map<UserLocalId, List<TimeEntry>> result = timeEntryRepository
119+
.findAllByOwnerIsInAndStartGreaterThanEqualAndStartLessThan(userIdValues, fromInstant, toInstant)
122120
.stream()
123121
.map(TimeEntryServiceImpl::toTimeEntry)
124-
// TODO add empty list entry for users without time entries
125122
.collect(groupingBy(timeEntry -> userLocalIdById.get(timeEntry.userId())));
123+
124+
for (UserLocalId userLocalId : userLocalIds) {
125+
result.computeIfAbsent(userLocalId, (unused) -> List.of());
126+
}
127+
128+
return result;
126129
}
127130

128131
@Override

src/test/java/de/focusshift/zeiterfassung/timeentry/TimeEntryServiceImplTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,27 @@ void ensureGetEntriesByUserLocalIds() {
847847
});
848848
}
849849

850+
@Test
851+
void ensureGetEntriesByUserLocalIdsReturnsValuesForEveryAskedUserLocalId() {
852+
853+
final UserLocalId batmanLocalId = new UserLocalId(1L);
854+
855+
when(userManagementService.findAllUsersByLocalIds(List.of(batmanLocalId))).thenReturn(List.of());
856+
857+
final LocalDate from = LocalDate.of(2023, 1, 1);
858+
final LocalDate toExclusive = LocalDate.of(2023, 2, 1);
859+
860+
when(timeEntryRepository.findAllByOwnerIsInAndStartGreaterThanEqualAndStartLessThan(List.of(), from.atStartOfDay(UTC).toInstant(), toExclusive.atStartOfDay(UTC).toInstant()))
861+
.thenReturn(List.of());
862+
863+
final Map<UserLocalId, List<TimeEntry>> actual = sut.getEntriesByUserLocalIds(from, toExclusive, List.of(batmanLocalId));
864+
865+
assertThat(actual).hasSize(1);
866+
assertThat(actual).hasEntrySatisfying(batmanLocalId, timeEntries -> {
867+
assertThat(timeEntries).isEmpty();
868+
});
869+
}
870+
850871
@Test
851872
void ensureGetEntriesSortedByStart_NewestFirst() {
852873

0 commit comments

Comments
 (0)