Skip to content

Commit

Permalink
Fix potential duplicate issue when saving notification settings (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofux authored Nov 26, 2024
1 parent ed37aa5 commit c8bb587
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ public Optional<NotificationSettings.Project> getNotificationSettingsForProject(
@Override
@Transactional
public void saveNotificationSettingsForProject(UserId userId, NotificationSettings.Project settings) {
notificationSettingsForProjectRepository.save(NotificationSettingsForProjectEntity.of(userId, settings));
final var entity = notificationSettingsForProjectRepository
.findById(new NotificationSettingsForProjectEntity.PrimaryKey(userId.value(), settings.projectId().value()))
.map(e -> {
e.setOnGoodFirstIssueAdded(settings.onGoodFirstIssueAdded().orElse(null));
return e;
})
.orElseGet(() -> NotificationSettingsForProjectEntity.of(userId, settings));
notificationSettingsForProjectRepository.save(entity);
}

@Override
Expand Down

0 comments on commit c8bb587

Please sign in to comment.