From 540b84757c4609b43ce5183b246eda1609f637d0 Mon Sep 17 00:00:00 2001 From: davdarras Date: Mon, 7 Oct 2024 14:48:12 +0200 Subject: [PATCH] fix: allow no date when updating visibility --- pom.xml | 2 +- .../dto/input/VisibilityCampaignUpdateDto.java | 2 -- .../campaign/dto/input/VisibilityUpdateDto.java | 2 -- ...LeastOneDateCampaignVisibilityValidator.java | 13 ------------- .../api/web/annotation/AtLeastOneDateValid.java | 17 ----------------- .../AtLeastOneDateVisibilityValidator.java | 13 ------------- .../CampaignControllerUpdateTest.java | 11 ----------- .../controller/VisibilityControllerTest.java | 14 -------------- 8 files changed, 1 insertion(+), 73 deletions(-) delete mode 100644 src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateCampaignVisibilityValidator.java delete mode 100644 src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateValid.java delete mode 100644 src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateVisibilityValidator.java diff --git a/pom.xml b/pom.xml index 7d351203..b0655726 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ fr.insee.pearljam pearljam-back-office - 5.1.7 + 5.1.8 Pearl-Jam-Back-Office Back-office services for PearlJam diff --git a/src/main/java/fr/insee/pearljam/api/campaign/dto/input/VisibilityCampaignUpdateDto.java b/src/main/java/fr/insee/pearljam/api/campaign/dto/input/VisibilityCampaignUpdateDto.java index 25227f66..54599052 100644 --- a/src/main/java/fr/insee/pearljam/api/campaign/dto/input/VisibilityCampaignUpdateDto.java +++ b/src/main/java/fr/insee/pearljam/api/campaign/dto/input/VisibilityCampaignUpdateDto.java @@ -1,7 +1,6 @@ package fr.insee.pearljam.api.campaign.dto.input; import com.fasterxml.jackson.annotation.JsonInclude; -import fr.insee.pearljam.api.web.annotation.AtLeastOneDateValid; import fr.insee.pearljam.domain.campaign.model.Visibility; import jakarta.validation.constraints.NotBlank; import org.springframework.lang.NonNull; @@ -19,7 +18,6 @@ * @param endDate End date of the visibility */ @JsonInclude(JsonInclude.Include.NON_NULL) -@AtLeastOneDateValid public record VisibilityCampaignUpdateDto( Long managementStartDate, Long interviewerStartDate, diff --git a/src/main/java/fr/insee/pearljam/api/campaign/dto/input/VisibilityUpdateDto.java b/src/main/java/fr/insee/pearljam/api/campaign/dto/input/VisibilityUpdateDto.java index 355d1f7f..83dcfda0 100644 --- a/src/main/java/fr/insee/pearljam/api/campaign/dto/input/VisibilityUpdateDto.java +++ b/src/main/java/fr/insee/pearljam/api/campaign/dto/input/VisibilityUpdateDto.java @@ -1,7 +1,6 @@ package fr.insee.pearljam.api.campaign.dto.input; import com.fasterxml.jackson.annotation.JsonInclude; -import fr.insee.pearljam.api.web.annotation.AtLeastOneDateValid; import fr.insee.pearljam.domain.campaign.model.Visibility; import lombok.NonNull; @@ -16,7 +15,6 @@ * @param endDate End date of the visibility */ @JsonInclude(JsonInclude.Include.NON_NULL) -@AtLeastOneDateValid public record VisibilityUpdateDto( Long managementStartDate, Long interviewerStartDate, diff --git a/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateCampaignVisibilityValidator.java b/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateCampaignVisibilityValidator.java deleted file mode 100644 index 70572a8f..00000000 --- a/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateCampaignVisibilityValidator.java +++ /dev/null @@ -1,13 +0,0 @@ -package fr.insee.pearljam.api.web.annotation; - -import fr.insee.pearljam.api.campaign.dto.input.VisibilityCampaignUpdateDto; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; - -public class AtLeastOneDateCampaignVisibilityValidator implements ConstraintValidator { - @Override - public boolean isValid(VisibilityCampaignUpdateDto dto, ConstraintValidatorContext context) { - return dto.managementStartDate() != null || dto.interviewerStartDate() != null || dto.identificationPhaseStartDate() != null || - dto.collectionStartDate() != null || dto.collectionEndDate() != null || dto.endDate() != null; - } -} diff --git a/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateValid.java b/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateValid.java deleted file mode 100644 index 89bb220c..00000000 --- a/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateValid.java +++ /dev/null @@ -1,17 +0,0 @@ -package fr.insee.pearljam.api.web.annotation; - -import jakarta.validation.Constraint; -import jakarta.validation.Payload; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Constraint(validatedBy = {AtLeastOneDateCampaignVisibilityValidator.class, AtLeastOneDateVisibilityValidator.class}) -@Target({ ElementType.TYPE }) -@Retention(RetentionPolicy.RUNTIME) -public @interface AtLeastOneDateValid { - String message() default "At least one date must be provided for a visibility"; - Class[] groups() default {}; - Class[] payload() default {}; -} diff --git a/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateVisibilityValidator.java b/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateVisibilityValidator.java deleted file mode 100644 index 64f3e74e..00000000 --- a/src/main/java/fr/insee/pearljam/api/web/annotation/AtLeastOneDateVisibilityValidator.java +++ /dev/null @@ -1,13 +0,0 @@ -package fr.insee.pearljam.api.web.annotation; - -import fr.insee.pearljam.api.campaign.dto.input.VisibilityUpdateDto; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; - -public class AtLeastOneDateVisibilityValidator implements ConstraintValidator { - @Override - public boolean isValid(VisibilityUpdateDto dto, ConstraintValidatorContext context) { - return dto.managementStartDate() != null || dto.interviewerStartDate() != null || dto.identificationPhaseStartDate() != null || - dto.collectionStartDate() != null || dto.collectionEndDate() != null || dto.endDate() != null; - } -} diff --git a/src/test/java/fr/insee/pearljam/api/campaign/controller/CampaignControllerUpdateTest.java b/src/test/java/fr/insee/pearljam/api/campaign/controller/CampaignControllerUpdateTest.java index 8d94399c..8f89f971 100644 --- a/src/test/java/fr/insee/pearljam/api/campaign/controller/CampaignControllerUpdateTest.java +++ b/src/test/java/fr/insee/pearljam/api/campaign/controller/CampaignControllerUpdateTest.java @@ -107,17 +107,6 @@ void testUpdateCampaign05() throws Exception { testUpdateExceptions(HttpStatus.NOT_FOUND, VisibilityNotFoundException.MESSAGE); } - @Test - @DisplayName("Should return bad request when visibility has no date set") - void testUpdateCampaign06() throws Exception { - VisibilityCampaignUpdateDto visibility = generateVisibility("ou-id", - null, null, - null, null, - null, null, - true, "mail", "tel"); - testUpdateExceptions(visibility, HttpStatus.BAD_REQUEST, ExceptionControllerAdvice.INVALID_PARAMETERS_MESSAGE); - } - @Test @DisplayName("Should return conflict when invalidating update") void testUpdateCampaign07() throws Exception { diff --git a/src/test/java/fr/insee/pearljam/api/campaign/controller/VisibilityControllerTest.java b/src/test/java/fr/insee/pearljam/api/campaign/controller/VisibilityControllerTest.java index aacd9324..a4684bfd 100644 --- a/src/test/java/fr/insee/pearljam/api/campaign/controller/VisibilityControllerTest.java +++ b/src/test/java/fr/insee/pearljam/api/campaign/controller/VisibilityControllerTest.java @@ -7,7 +7,6 @@ import fr.insee.pearljam.api.utils.JsonTestHelper; import fr.insee.pearljam.api.utils.MockMvcTestUtils; import fr.insee.pearljam.api.utils.dummy.AuthenticationUserFakeService; -import fr.insee.pearljam.api.web.exception.ExceptionControllerAdvice; import fr.insee.pearljam.domain.campaign.model.Visibility; import fr.insee.pearljam.domain.exception.CampaignNotFoundException; import fr.insee.pearljam.domain.exception.VisibilityHasInvalidDatesException; @@ -137,19 +136,6 @@ void testUpdateVisibility03() throws Exception { .andExpect(MockMvcTestUtils.apiErrorMatches(HttpStatus.CONFLICT, updatePath, VisibilityHasInvalidDatesException.MESSAGE)); } - @Test - @DisplayName("Should return bad request when visibility has no date set") - void testUpdateVisibility04() throws Exception { - VisibilityUpdateDto visibility = generateUpdateVisibility( - null, null, - null, null, - null, null); - mockMvc.perform(put(updatePath) - .content(JsonTestHelper.toJson(visibility)) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcTestUtils.apiErrorMatches(HttpStatus.BAD_REQUEST, updatePath, ExceptionControllerAdvice.INVALID_PARAMETERS_MESSAGE)); - } - private VisibilityUpdateDto generateUpdateVisibility() { return generateUpdateVisibility(1721683250000L, 1721683251000L, 1721683252000L, 1721683253000L,