From ac04dbf3523562283902f601cd29c0daefcac198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Z=C3=B6ller?= Date: Thu, 4 Dec 2025 13:14:30 +0100 Subject: [PATCH] Nice things --- CLAUDE.md | 2 +- .../fitpub/service/PersonalRecordService.java | 82 +++++++++++-------- 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index e1cfc9e..5b9e40d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -777,7 +777,7 @@ For ActivityPub federated posts and thumbnails: - [x] Followers/following lists (ActorDTO, GET /api/users/{username}/followers, GET /api/users/{username}/following) - [x] Follower/following counts (UserController.populateSocialCounts, UserDTO with followersCount/followingCount, frontend displays real counts) - [x] Heart rate chart over time on activity details (Chart.js line chart, elapsed time x-axis, heart rate y-axis) -- [x] Speed/pace chart over time on activity details (Chart.js line chart with smoothing, displays speed in km/h with pace in tooltip) +- [x] Speed/pace chart over time on activity details (Chart.js line chart with smoothin[69287079d5e0a4532ba818ee.fit](src/test/resources/69287079d5e0a4532ba818ee.fit)g, displays speed in km/h with pace in tooltip) - [x] Notifications system (Notification entity, NotificationRepository, NotificationService, NotificationController REST API, notifications.html UI, notification bell in nav with unread count, polling every 30s, mark as read/delete, all/unread filter tabs) - [x] Custom 404 Not Found page (error/404.html with animated compass icon, suggestions, gradient background) - [x] Custom 403 Forbidden page (error/403.html with shield-lock icon, auth-aware login button, gradient background) diff --git a/src/main/java/org/operaton/fitpub/service/PersonalRecordService.java b/src/main/java/org/operaton/fitpub/service/PersonalRecordService.java index dbbdbfc..4f3659d 100644 --- a/src/main/java/org/operaton/fitpub/service/PersonalRecordService.java +++ b/src/main/java/org/operaton/fitpub/service/PersonalRecordService.java @@ -197,24 +197,33 @@ public class PersonalRecordService { .findByUserIdAndActivityTypeAndRecordType(userId, activityType, recordType); if (existingRecord.isEmpty() || value.compareTo(existingRecord.get().getValue()) > 0) { - PersonalRecord newRecord = PersonalRecord.builder() - .userId(userId) - .activityType(activityType) - .recordType(recordType) - .value(value) - .unit(unit) - .activityId(activityId) - .achievedAt(achievedAt) - .build(); + PersonalRecord recordToSave; - existingRecord.ifPresent(record -> { - newRecord.setPreviousValue(record.getValue()); - newRecord.setPreviousAchievedAt(record.getAchievedAt()); - }); + if (existingRecord.isPresent()) { + // Update existing record + PersonalRecord existing = existingRecord.get(); + recordToSave = existing; + recordToSave.setPreviousValue(existing.getValue()); + recordToSave.setPreviousAchievedAt(existing.getAchievedAt()); + recordToSave.setValue(value); + recordToSave.setActivityId(activityId); + recordToSave.setAchievedAt(achievedAt); + } else { + // Create new record + recordToSave = PersonalRecord.builder() + .userId(userId) + .activityType(activityType) + .recordType(recordType) + .value(value) + .unit(unit) + .activityId(activityId) + .achievedAt(achievedAt) + .build(); + } - personalRecordRepository.save(newRecord); - log.info("New personal record set: {} {} - {} {}", activityType, recordType, value, unit); - return newRecord; + personalRecordRepository.save(recordToSave); + log.info("Personal record set: {} {} - {} {}", activityType, recordType, value, unit); + return recordToSave; } return null; @@ -230,24 +239,33 @@ public class PersonalRecordService { .findByUserIdAndActivityTypeAndRecordType(userId, activityType, recordType); if (existingRecord.isEmpty() || value.compareTo(existingRecord.get().getValue()) < 0) { - PersonalRecord newRecord = PersonalRecord.builder() - .userId(userId) - .activityType(activityType) - .recordType(recordType) - .value(value) - .unit(unit) - .activityId(activityId) - .achievedAt(achievedAt) - .build(); + PersonalRecord recordToSave; - existingRecord.ifPresent(record -> { - newRecord.setPreviousValue(record.getValue()); - newRecord.setPreviousAchievedAt(record.getAchievedAt()); - }); + if (existingRecord.isPresent()) { + // Update existing record + PersonalRecord existing = existingRecord.get(); + recordToSave = existing; + recordToSave.setPreviousValue(existing.getValue()); + recordToSave.setPreviousAchievedAt(existing.getAchievedAt()); + recordToSave.setValue(value); + recordToSave.setActivityId(activityId); + recordToSave.setAchievedAt(achievedAt); + } else { + // Create new record + recordToSave = PersonalRecord.builder() + .userId(userId) + .activityType(activityType) + .recordType(recordType) + .value(value) + .unit(unit) + .activityId(activityId) + .achievedAt(achievedAt) + .build(); + } - personalRecordRepository.save(newRecord); - log.info("New personal record set: {} {} - {} {}", activityType, recordType, value, unit); - return newRecord; + personalRecordRepository.save(recordToSave); + log.info("Personal record set: {} {} - {} {}", activityType, recordType, value, unit); + return recordToSave; } return null;