From 611f790b6a4cc2ac9d4c518b2d7f8d33ff02aea1 Mon Sep 17 00:00:00 2001
From: David Darras <117278497+davdarras@users.noreply.github.com>
Date: Fri, 7 Jun 2024 09:34:00 +0200
Subject: [PATCH] fix: add survey units unique constraints in DB (#250)
---
pom.xml | 2 +-
.../surveyunit/service/CommentApiService.java | 2 +
.../surveyunit/service/DataApiService.java | 3 ++
.../service/StateDataApiService.java | 2 +
.../db/changelog/600_unique_constraints.xml | 50 +++++++++++++++++++
.../src/main/resources/db/master.xml | 1 +
6 files changed, 59 insertions(+), 1 deletion(-)
create mode 100644 queen-infra-db/src/main/resources/db/changelog/600_unique_constraints.xml
diff --git a/pom.xml b/pom.xml
index 71d1f4bb..543141be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
Modules for queen back-office
- 4.3.3
+ 4.3.4
21
21
diff --git a/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/CommentApiService.java b/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/CommentApiService.java
index a1f8b665..7c87e186 100644
--- a/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/CommentApiService.java
+++ b/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/CommentApiService.java
@@ -5,6 +5,7 @@
import fr.insee.queen.domain.surveyunit.gateway.SurveyUnitRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
@Service
@AllArgsConstructor
@@ -19,6 +20,7 @@ public ObjectNode getComment(String surveyUnitId) {
}
@Override
+ @Transactional
public void updateComment(String surveyUnitId, ObjectNode commentValue) {
surveyUnitRepository.saveComment(surveyUnitId, commentValue);
}
diff --git a/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/DataApiService.java b/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/DataApiService.java
index 06740bbc..74e76cd4 100644
--- a/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/DataApiService.java
+++ b/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/DataApiService.java
@@ -6,6 +6,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
@Service
@Slf4j
@@ -21,11 +22,13 @@ public ObjectNode getData(String surveyUnitId) {
}
@Override
+ @Transactional
public void saveData(String surveyUnitId, ObjectNode dataValue) {
surveyUnitRepository.saveData(surveyUnitId, dataValue);
}
@Override
+ @Transactional
public void updateCollectedData(String surveyUnitId, ObjectNode collectedData) {
surveyUnitRepository.updateCollectedData(surveyUnitId, collectedData);
}
diff --git a/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/StateDataApiService.java b/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/StateDataApiService.java
index 2f4a79a5..97fe8a5e 100644
--- a/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/StateDataApiService.java
+++ b/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/StateDataApiService.java
@@ -7,6 +7,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
@@ -27,6 +28,7 @@ public StateData getStateData(String surveyUnitId) {
}
@Override
+ @Transactional
public void saveStateData(String surveyUnitId, StateData stateData) throws StateDataInvalidDateException {
Optional previousStateData = stateDataRepository.find(surveyUnitId);
if (previousStateData.isEmpty()) {
diff --git a/queen-infra-db/src/main/resources/db/changelog/600_unique_constraints.xml b/queen-infra-db/src/main/resources/db/changelog/600_unique_constraints.xml
new file mode 100644
index 00000000..daec52a1
--- /dev/null
+++ b/queen-infra-db/src/main/resources/db/changelog/600_unique_constraints.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/queen-infra-db/src/main/resources/db/master.xml b/queen-infra-db/src/main/resources/db/master.xml
index f2d613a6..ccd0ae03 100644
--- a/queen-infra-db/src/main/resources/db/master.xml
+++ b/queen-infra-db/src/main/resources/db/master.xml
@@ -19,4 +19,5 @@
+
\ No newline at end of file