RED-6310: Corrected services so that they use the user id instead of wrongly using the entity id

This commit is contained in:
Viktor Seifert 2023-03-07 13:34:05 +01:00
parent 40d6961742
commit 643ffc8723
2 changed files with 9 additions and 6 deletions

View File

@ -60,14 +60,14 @@ public class NotificationPreferencesPersistenceService {
@Transactional
public void deleteNotificationPreferences(String userId) {
notificationPreferencesRepository.deleteById(userId);
notificationPreferencesRepository.deleteByUserId(userId);
}
@Transactional
public NotificationPreferencesEntity getOrCreateNotificationPreferences(String userId) {
return notificationPreferencesRepository.findById(userId).orElseGet(() -> {
return notificationPreferencesRepository.findByUserId(userId).orElseGet(() -> {
var notificationPreference = new NotificationPreferencesEntity();
notificationPreference.setUserId(userId);
@ -82,9 +82,7 @@ public class NotificationPreferencesPersistenceService {
@Transactional
public void initializePreferencesIfNotExists(String userId) {
if (!notificationPreferencesRepository.existsByUserId(userId)) {
getOrCreateNotificationPreferences(userId);
}
getOrCreateNotificationPreferences(userId);
}

View File

@ -1,11 +1,16 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import com.iqser.red.service.persistence.management.v1.processor.entity.notification.NotificationPreferencesEntity;
public interface NotificationPreferencesRepository extends JpaRepository<NotificationPreferencesEntity, String> {
boolean existsByUserId(String userId);
Optional<NotificationPreferencesEntity> findByUserId(String userId);
void deleteByUserId(String userId);
}