From c629554fad9fd552d8b4ec2eb2e04f817872ae57 Mon Sep 17 00:00:00 2001 From: Benjamin Seber Date: Wed, 3 Jul 2024 22:39:30 +0200 Subject: [PATCH] add timeClock logging --- .../timeclock/TimeClockService.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/focusshift/zeiterfassung/timeclock/TimeClockService.java b/src/main/java/de/focusshift/zeiterfassung/timeclock/TimeClockService.java index 8c22c129..6e032a3f 100644 --- a/src/main/java/de/focusshift/zeiterfassung/timeclock/TimeClockService.java +++ b/src/main/java/de/focusshift/zeiterfassung/timeclock/TimeClockService.java @@ -108,6 +108,9 @@ public TimeClock updateTimeClock(UserId userId, TimeClockUpdate timeClockUpdate) final TimeClockEntity timeClockEntity = toEntity(timeClock); + LOG.info("Updating TimeClock for user {}", userId.value()); + LOG.debug("Next TimeClock: {}", timeClock); + return toTimeClock(timeClockRepository.save(timeClockEntity)); } @@ -121,14 +124,16 @@ void stopTimeClock(UserId userId) { .map(entity -> timeClockEntityWithStoppedAt(entity, ZonedDateTime.now(userSettingsProvider.zoneId()))) .map(timeClockRepository::save) .map(TimeClockService::toTimeClock) - .ifPresent(timeClock -> { - - final ZonedDateTime start = timeClock.startedAt(); - final ZonedDateTime end = timeClock.stoppedAt() - .orElseThrow(() -> new IllegalStateException("expected stoppedAt to contain a value.")); - - timeEntryService.createTimeEntry(userId, timeClock.comment(), start, end, timeClock.isBreak()); - }); + .ifPresentOrElse( + timeClock -> { + final ZonedDateTime start = timeClock.startedAt(); + final ZonedDateTime end = timeClock.stoppedAt() + .orElseThrow(() -> new IllegalStateException("expected stoppedAt to contain a value.")); + + LOG.info("Stopping TimeClock={} for user={} and creating TimeEntry for it.", timeClock.id(), userId.value()); + timeEntryService.createTimeEntry(userId, timeClock.comment(), start, end, timeClock.isBreak()); + }, + () -> LOG.info("Not stopping TimeClock for user {} since nothing found. No TimeEntry created.", userId.value())); } private static TimeClockEntity toEntity(TimeClock timeClock) {