From 2f07ec4fc8db1e10c9fd1e470fcbb175bc99d00c Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Thu, 10 Oct 2024 10:31:51 +0300 Subject: [PATCH 1/4] Done. --- dao/src/main/java/greencity/enums/EmailPreference.java | 3 ++- .../main/java/greencity/message/SendReportEmailMessage.java | 4 ++-- .../src/main/java/greencity/service/EmailServiceImpl.java | 4 ++-- .../src/main/java/greencity/service/UserServiceImpl.java | 6 +++--- .../test/java/greencity/service/EmailServiceImplTest.java | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/dao/src/main/java/greencity/enums/EmailPreference.java b/dao/src/main/java/greencity/enums/EmailPreference.java index ae0d979fb..488e796bd 100644 --- a/dao/src/main/java/greencity/enums/EmailPreference.java +++ b/dao/src/main/java/greencity/enums/EmailPreference.java @@ -4,5 +4,6 @@ public enum EmailPreference { SYSTEM, LIKES, COMMENTS, - INVITES + INVITES, + PLACES } diff --git a/service-api/src/main/java/greencity/message/SendReportEmailMessage.java b/service-api/src/main/java/greencity/message/SendReportEmailMessage.java index 5bd95712e..875aacfa2 100644 --- a/service-api/src/main/java/greencity/message/SendReportEmailMessage.java +++ b/service-api/src/main/java/greencity/message/SendReportEmailMessage.java @@ -3,7 +3,7 @@ import greencity.dto.category.CategoryDto; import greencity.dto.place.PlaceNotificationDto; import greencity.dto.user.SubscriberDto; -import greencity.enums.EmailNotification; +import greencity.enums.EmailPreferencePeriodicity; import java.util.List; import java.util.Map; import lombok.AllArgsConstructor; @@ -18,5 +18,5 @@ public class SendReportEmailMessage { private List subscribers; private Map> categoriesDtoWithPlacesDtoMap; - private EmailNotification emailNotification; + private EmailPreferencePeriodicity emailPreferencePeriodicity; } diff --git a/service/src/main/java/greencity/service/EmailServiceImpl.java b/service/src/main/java/greencity/service/EmailServiceImpl.java index e04a3f780..98ec7a47d 100644 --- a/service/src/main/java/greencity/service/EmailServiceImpl.java +++ b/service/src/main/java/greencity/service/EmailServiceImpl.java @@ -85,11 +85,11 @@ public void sendChangePlaceStatusEmail(ChangePlaceStatusDto changePlaceStatus) { @Override public void sendAddedNewPlacesReportEmail(SendReportEmailMessage message) { log.info(LogMessage.IN_SEND_ADDED_NEW_PLACES_REPORT_EMAIL, message.getSubscribers(), - message.getCategoriesDtoWithPlacesDtoMap(), message.getEmailNotification()); + message.getCategoriesDtoWithPlacesDtoMap(), message.getEmailPreferencePeriodicity()); Map sharedModel = new HashMap<>(); sharedModel.put(EmailConstants.CLIENT_LINK, clientLink); sharedModel.put(EmailConstants.RESULT, message.getCategoriesDtoWithPlacesDtoMap()); - sharedModel.put(EmailConstants.REPORT_TYPE, message.getEmailNotification().name()); + sharedModel.put(EmailConstants.REPORT_TYPE, message.getEmailPreferencePeriodicity().name()); for (SubscriberDto user : message.getSubscribers()) { Map model = new HashMap<>(sharedModel); diff --git a/service/src/main/java/greencity/service/UserServiceImpl.java b/service/src/main/java/greencity/service/UserServiceImpl.java index 63ff705e7..83e3f8987 100644 --- a/service/src/main/java/greencity/service/UserServiceImpl.java +++ b/service/src/main/java/greencity/service/UserServiceImpl.java @@ -610,7 +610,8 @@ private void setNotificationPreferencesForUser(User user, UserProfileDtoRequest Set userPreferences = user.getNotificationPreferences(); Set newPreferences = userProfileDtoRequest.getEmailPreferences(); Set existingPreferences = userPreferences.stream() - .map(UserNotificationPreference::getEmailPreference).collect(Collectors.toSet()); + .map(UserNotificationPreference::getEmailPreference) + .collect(Collectors.toSet()); Set preferencesToAdd = newPreferences.stream() .filter(preferenceDto -> !existingPreferences.contains(preferenceDto.getEmailPreference())) .map(preferenceDto -> UserNotificationPreference.builder() @@ -620,8 +621,7 @@ private void setNotificationPreferencesForUser(User user, UserProfileDtoRequest .build()) .collect(Collectors.toSet()); - Set preferences = userPreferences - .stream() + Set preferences = userPreferences.stream() .map(preference -> { for (UserNotificationPreferenceDto preferenceDto : newPreferences) { if (preferenceDto.getEmailPreference().equals(preference.getEmailPreference())) { diff --git a/service/src/test/java/greencity/service/EmailServiceImplTest.java b/service/src/test/java/greencity/service/EmailServiceImplTest.java index 29e405181..892cd5903 100644 --- a/service/src/test/java/greencity/service/EmailServiceImplTest.java +++ b/service/src/test/java/greencity/service/EmailServiceImplTest.java @@ -9,7 +9,7 @@ import greencity.dto.user.UserActivationDto; import greencity.dto.user.UserDeactivationReasonDto; import greencity.dto.violation.UserViolationMailDto; -import greencity.enums.EmailNotification; +import greencity.enums.EmailPreferencePeriodicity; import greencity.enums.PlaceStatus; import greencity.exception.exceptions.WrongEmailException; import greencity.message.ChangePlaceStatusDto; @@ -92,7 +92,7 @@ void sendAddedNewPlacesReportEmailTest() { .name("Hotels") .build()) .build()))) - .emailNotification(EmailNotification.WEEKLY) + .emailPreferencePeriodicity(EmailPreferencePeriodicity.WEEKLY) .build(); service.sendAddedNewPlacesReportEmail(sendReportEmailMessage); verify(javaMailSender).createMimeMessage(); From 348fa1de0e09b17a6f7a036cd92c4efe40ff0cfd Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Thu, 10 Oct 2024 17:25:24 +0300 Subject: [PATCH 2/4] Remove change place status email. --- .../java/greencity/config/SecurityConfig.java | 8 +- .../greencity/controller/EmailController.java | 15 --- .../email/change-place-status-email-page.html | 114 ------------------ .../controller/EmailControllerTest.java | 20 --- .../greencity/constant/EmailConstants.java | 4 - .../message/ChangePlaceStatusDto.java | 30 ----- .../greencity/message/CommentMessage.java | 42 ------- .../message/GeneralEmailMessage.java | 19 --- .../HabitAssignNotificationMessage.java | 34 ------ .../message/UserReceivedCommentMessage.java | 19 --- .../UserReceivedCommentReplyMessage.java | 30 ----- .../message/UserTaggedInCommentMessage.java | 19 --- .../java/greencity/service/EmailService.java | 8 -- .../greencity/service/EmailServiceImpl.java | 20 --- .../service/EmailServiceImplTest.java | 18 --- 15 files changed, 1 insertion(+), 399 deletions(-) delete mode 100644 core/src/main/resources/templates/email/change-place-status-email-page.html delete mode 100644 service-api/src/main/java/greencity/message/ChangePlaceStatusDto.java delete mode 100644 service-api/src/main/java/greencity/message/CommentMessage.java delete mode 100644 service-api/src/main/java/greencity/message/GeneralEmailMessage.java delete mode 100644 service-api/src/main/java/greencity/message/HabitAssignNotificationMessage.java delete mode 100644 service-api/src/main/java/greencity/message/UserReceivedCommentMessage.java delete mode 100644 service-api/src/main/java/greencity/message/UserReceivedCommentReplyMessage.java delete mode 100644 service-api/src/main/java/greencity/message/UserTaggedInCommentMessage.java diff --git a/core/src/main/java/greencity/config/SecurityConfig.java b/core/src/main/java/greencity/config/SecurityConfig.java index 72cdc387c..01a3788ce 100644 --- a/core/src/main/java/greencity/config/SecurityConfig.java +++ b/core/src/main/java/greencity/config/SecurityConfig.java @@ -200,13 +200,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti "/ownSecurity/register", "/email/sendReport", "/email/sendHabitNotification", - "/email/sendInterestingEcoNews", - "/email/changePlaceStatus", - "/email/general/notification", - "/email/sendHabitAssignNotification", - "/email/taggedUserInComment/notification", - "/email/userReceivedComment/notification", - "/email/userReceivedCommentReply/notification") + "/email/sendInterestingEcoNews") .hasAnyRole(ADMIN) .requestMatchers(HttpMethod.PATCH, "/user/status", diff --git a/core/src/main/java/greencity/controller/EmailController.java b/core/src/main/java/greencity/controller/EmailController.java index de176c3cc..4ed41a6fe 100644 --- a/core/src/main/java/greencity/controller/EmailController.java +++ b/core/src/main/java/greencity/controller/EmailController.java @@ -45,21 +45,6 @@ public ResponseEntity sendReport(@RequestBody SendReportEmailMessage mes return ResponseEntity.ok().build(); } - /** - * Method for sending simple notification to {@code User} about status change. - * - * @param message - object with all necessary data for sending email - */ - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = HttpStatuses.OK), - @ApiResponse(responseCode = "400", description = HttpStatuses.BAD_REQUEST), - }) - @PostMapping("/changePlaceStatus") - public ResponseEntity changePlaceStatus(@RequestBody @Valid ChangePlaceStatusDto message) { - emailService.sendChangePlaceStatusEmail(message); - return ResponseEntity.ok().build(); - } - /** * Sends email notification about not marked habits during 3 last days. * diff --git a/core/src/main/resources/templates/email/change-place-status-email-page.html b/core/src/main/resources/templates/email/change-place-status-email-page.html deleted file mode 100644 index 6f1453135..000000000 --- a/core/src/main/resources/templates/email/change-place-status-email-page.html +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/core/src/test/java/greencity/controller/EmailControllerTest.java b/core/src/test/java/greencity/controller/EmailControllerTest.java index 5c6a5eec7..cd6373d46 100644 --- a/core/src/test/java/greencity/controller/EmailControllerTest.java +++ b/core/src/test/java/greencity/controller/EmailControllerTest.java @@ -5,7 +5,6 @@ import greencity.dto.econews.InterestingEcoNewsDto; import greencity.dto.violation.UserViolationMailDto; import greencity.message.ScheduledEmailMessage; -import greencity.message.ChangePlaceStatusDto; import greencity.message.SendHabitNotification; import greencity.message.SendReportEmailMessage; import greencity.service.EmailService; @@ -118,25 +117,6 @@ void sendReport() throws Exception { verify(emailService).sendAddedNewPlacesReportEmail(message); } - @Test - void changePlaceStatus() throws Exception { - String content = """ - {\ - "authorEmail":"string",\ - "authorFirstName":"string",\ - "placeName":"string",\ - "placeStatus":"APPROVED",\ - "authorLanguage":"en"\ - }\ - """; - - mockPerform(content, "/changePlaceStatus"); - - ChangePlaceStatusDto message = new ObjectMapper().readValue(content, ChangePlaceStatusDto.class); - - verify(emailService).sendChangePlaceStatusEmail(message); - } - @Test void changePlaceStatusInvalidPlaceStatus() throws Exception { String content = """ diff --git a/service-api/src/main/java/greencity/constant/EmailConstants.java b/service-api/src/main/java/greencity/constant/EmailConstants.java index 4ec2af15c..27a02b4b5 100644 --- a/service-api/src/main/java/greencity/constant/EmailConstants.java +++ b/service-api/src/main/java/greencity/constant/EmailConstants.java @@ -5,7 +5,6 @@ @UtilityClass public class EmailConstants { // subjects - public static final String CHANGE_PLACE_STATUS = "change.place.status.subject"; public static final String NEW_PLACES = "New places"; public static final String INTERESTING_ECO_NEWS = "interesting.news.subject"; public static final String VERIFY_EMAIL = "verify.email"; @@ -23,8 +22,6 @@ public class EmailConstants { public static final String VERIFY_ADDRESS = "verifyAddress"; public static final String RESTORE_PASS = "restorePassword"; public static final String APPROVE_REGISTRATION = "approveRegistration"; - public static final String PLACE_NAME = "placeName"; - public static final String STATUS = "status"; public static final String RESULT = "result"; public static final String REPORT_TYPE = "reportType"; public static final String UNSUBSCRIBE_LINK = "unsubscribeLink"; @@ -42,7 +39,6 @@ public class EmailConstants { public static final String CRETE_PASSWORD_PAGE = "create-employee-password-page"; public static final String SUCCESS_RESTORED_PASSWORD_PAGE = "success-restored-password-page"; public static final String USER_APPROVAL_EMAIL_PAGE = "user-approval-email-page"; - public static final String CHANGE_PLACE_STATUS_EMAIL_PAGE = "change-place-status-email-page"; public static final String NEW_PLACES_REPORT_EMAIL_PAGE = "new-places-report-email-page"; public static final String REASONS_OF_DEACTIVATION_PAGE = "user-reasons-of-deactivation-page"; public static final String ACTIVATION_PAGE = "user-activation-page"; diff --git a/service-api/src/main/java/greencity/message/ChangePlaceStatusDto.java b/service-api/src/main/java/greencity/message/ChangePlaceStatusDto.java deleted file mode 100644 index 91c897a89..000000000 --- a/service-api/src/main/java/greencity/message/ChangePlaceStatusDto.java +++ /dev/null @@ -1,30 +0,0 @@ -package greencity.message; - -import greencity.annotations.ValidPlaceStatus; -import greencity.enums.PlaceStatus; -import jakarta.validation.constraints.NotEmpty; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class ChangePlaceStatusDto { - @NotEmpty(message = "Author's first name cannot be empty") - private String authorFirstName; - - @NotEmpty(message = "Author's language cannot be empty") - private String authorLanguage; - - @NotEmpty(message = "Place name cannot be empty") - private String placeName; - - @ValidPlaceStatus - private PlaceStatus placeStatus; - - @NotEmpty(message = "Author's email cannot be empty") - private String authorEmail; -} diff --git a/service-api/src/main/java/greencity/message/CommentMessage.java b/service-api/src/main/java/greencity/message/CommentMessage.java deleted file mode 100644 index ddffecb42..000000000 --- a/service-api/src/main/java/greencity/message/CommentMessage.java +++ /dev/null @@ -1,42 +0,0 @@ -package greencity.message; - -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; -import java.io.Serializable; -import java.time.LocalDateTime; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Getter -@SuperBuilder -public abstract class CommentMessage implements Serializable { - @NotEmpty(message = "Receiver name cannot be empty") - private String receiverName; - - @NotEmpty(message = "Receiver email cannot be empty") - private String receiverEmail; - - @NotEmpty(message = "Language cannot be empty") - private String language; - - @NotEmpty(message = "Name of element cannot be null") - private String elementName; - - @NotEmpty(message = "Comment cannot be empty") - private String commentText; - - @NotNull(message = "Date cannot be null") - private LocalDateTime creationDate; - - @NotNull(message = "Element ID cannot be null") - private Long commentedElementId; - - @NotEmpty(message = "Base link cannot be null") - private String baseLink; -} diff --git a/service-api/src/main/java/greencity/message/GeneralEmailMessage.java b/service-api/src/main/java/greencity/message/GeneralEmailMessage.java deleted file mode 100644 index 6f8fd0cf9..000000000 --- a/service-api/src/main/java/greencity/message/GeneralEmailMessage.java +++ /dev/null @@ -1,19 +0,0 @@ -package greencity.message; - -import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; - -@Getter -@ToString -@AllArgsConstructor -@NoArgsConstructor -@Builder -public class GeneralEmailMessage implements Serializable { - private String email; - private String subject; - private String message; -} diff --git a/service-api/src/main/java/greencity/message/HabitAssignNotificationMessage.java b/service-api/src/main/java/greencity/message/HabitAssignNotificationMessage.java deleted file mode 100644 index 3d851e8d7..000000000 --- a/service-api/src/main/java/greencity/message/HabitAssignNotificationMessage.java +++ /dev/null @@ -1,34 +0,0 @@ -package greencity.message; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@AllArgsConstructor -@NoArgsConstructor -@Data -@Builder -public class HabitAssignNotificationMessage { - @NotEmpty(message = "Sender name cannot be empty") - private String senderName; - - @NotEmpty(message = "Receiver name cannot be empty") - private String receiverName; - - @NotEmpty(message = "Receiver email cannot be empty") - @Email(message = "Receiver email should be valid") - private String receiverEmail; - - @NotEmpty(message = "Habit name cannot be empty") - private String habitName; - - @NotEmpty(message = "Language cannot be empty") - private String language; - - @NotNull(message = "Habit assign ID cannot be null") - private Long habitAssignId; -} diff --git a/service-api/src/main/java/greencity/message/UserReceivedCommentMessage.java b/service-api/src/main/java/greencity/message/UserReceivedCommentMessage.java deleted file mode 100644 index 55cecc521..000000000 --- a/service-api/src/main/java/greencity/message/UserReceivedCommentMessage.java +++ /dev/null @@ -1,19 +0,0 @@ -package greencity.message; - -import jakarta.validation.constraints.NotEmpty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; -import java.io.Serializable; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@Getter -public class UserReceivedCommentMessage extends CommentMessage implements Serializable { - @NotEmpty(message = "Author name cannot be empty") - private String authorName; -} \ No newline at end of file diff --git a/service-api/src/main/java/greencity/message/UserReceivedCommentReplyMessage.java b/service-api/src/main/java/greencity/message/UserReceivedCommentReplyMessage.java deleted file mode 100644 index 7cb3753ed..000000000 --- a/service-api/src/main/java/greencity/message/UserReceivedCommentReplyMessage.java +++ /dev/null @@ -1,30 +0,0 @@ -package greencity.message; - -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; -import java.io.Serializable; -import java.time.LocalDateTime; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@Getter -public class UserReceivedCommentReplyMessage extends CommentMessage implements Serializable { - @NotEmpty(message = "Author name cannot be empty") - private String authorName; - - @NotEmpty(message = "Parent comment cannot be empty") - private String parentCommentText; - - @NotEmpty(message = "Parent comment author name cannot be empty") - private String parentCommentAuthorName; - - @NotNull(message = "Parent comment creation date cannot be null") - private LocalDateTime parentCommentCreationDate; -} diff --git a/service-api/src/main/java/greencity/message/UserTaggedInCommentMessage.java b/service-api/src/main/java/greencity/message/UserTaggedInCommentMessage.java deleted file mode 100644 index c40cf645f..000000000 --- a/service-api/src/main/java/greencity/message/UserTaggedInCommentMessage.java +++ /dev/null @@ -1,19 +0,0 @@ -package greencity.message; - -import jakarta.validation.constraints.NotEmpty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; -import java.io.Serializable; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@SuperBuilder -@Getter -public class UserTaggedInCommentMessage extends CommentMessage implements Serializable { - @NotEmpty(message = "Tagger name cannot be empty") - private String taggerName; -} \ No newline at end of file diff --git a/service-api/src/main/java/greencity/service/EmailService.java b/service-api/src/main/java/greencity/service/EmailService.java index 152df20d0..161b72db4 100644 --- a/service-api/src/main/java/greencity/service/EmailService.java +++ b/service-api/src/main/java/greencity/service/EmailService.java @@ -5,7 +5,6 @@ import greencity.dto.user.UserDeactivationReasonDto; import greencity.dto.violation.UserViolationMailDto; import greencity.message.ScheduledEmailMessage; -import greencity.message.ChangePlaceStatusDto; import greencity.message.SendReportEmailMessage; /** @@ -28,13 +27,6 @@ public interface EmailService { */ void sendInterestingEcoNews(InterestingEcoNewsDto interestingEcoNews); - /** - * Method for sending simple notification to {@code User} about change status. - * - * @param changePlaceStatus dto with all information. - */ - void sendChangePlaceStatusEmail(ChangePlaceStatusDto changePlaceStatus); - /** * Method for sending verification email to {@code User}. * diff --git a/service/src/main/java/greencity/service/EmailServiceImpl.java b/service/src/main/java/greencity/service/EmailServiceImpl.java index 98ec7a47d..efd4081d4 100644 --- a/service/src/main/java/greencity/service/EmailServiceImpl.java +++ b/service/src/main/java/greencity/service/EmailServiceImpl.java @@ -7,7 +7,6 @@ import greencity.dto.user.UserActivationDto; import greencity.dto.user.UserDeactivationReasonDto; import greencity.dto.violation.UserViolationMailDto; -import greencity.message.ChangePlaceStatusDto; import greencity.message.ScheduledEmailMessage; import greencity.message.SendReportEmailMessage; import greencity.validator.EmailAddressValidator; @@ -60,25 +59,6 @@ public EmailServiceImpl(JavaMailSender javaMailSender, this.messageSource = messageSource; } - /** - * {@inheritDoc} - */ - @Override - public void sendChangePlaceStatusEmail(ChangePlaceStatusDto changePlaceStatus) { - log.info(LogMessage.IN_SEND_CHANGE_PLACE_STATUS_EMAIL, changePlaceStatus.getPlaceName()); - Map model = new HashMap<>(); - model.put(EmailConstants.CLIENT_LINK, clientLink); - model.put(EmailConstants.LANGUAGE, changePlaceStatus.getAuthorLanguage()); - model.put(EmailConstants.USER_NAME, changePlaceStatus.getAuthorFirstName()); - model.put(EmailConstants.PLACE_NAME, changePlaceStatus.getPlaceName()); - model.put(EmailConstants.STATUS, changePlaceStatus.getPlaceStatus().name()); - model.put(EmailConstants.PROFILE_LINK, getProfileLink()); - - String template = createEmailTemplate(model, EmailConstants.CHANGE_PLACE_STATUS_EMAIL_PAGE); - sendEmail(changePlaceStatus.getAuthorEmail(), messageSource.getMessage(EmailConstants.CHANGE_PLACE_STATUS, null, - getLocale(changePlaceStatus.getAuthorLanguage())), template); - } - /** * {@inheritDoc} */ diff --git a/service/src/test/java/greencity/service/EmailServiceImplTest.java b/service/src/test/java/greencity/service/EmailServiceImplTest.java index 892cd5903..a8ae8c35a 100644 --- a/service/src/test/java/greencity/service/EmailServiceImplTest.java +++ b/service/src/test/java/greencity/service/EmailServiceImplTest.java @@ -10,9 +10,7 @@ import greencity.dto.user.UserDeactivationReasonDto; import greencity.dto.violation.UserViolationMailDto; import greencity.enums.EmailPreferencePeriodicity; -import greencity.enums.PlaceStatus; import greencity.exception.exceptions.WrongEmailException; -import greencity.message.ChangePlaceStatusDto; import greencity.message.ScheduledEmailMessage; import greencity.message.SendReportEmailMessage; import jakarta.mail.Session; @@ -61,22 +59,6 @@ public void setup() { when(templateEngine.process(any(String.class), any(Context.class))).thenReturn(""); } - @Test - void sendChangePlaceStatusEmailTest() { - ChangePlaceStatusDto changePlaceStatusDto = ChangePlaceStatusDto.builder() - .placeStatus(PlaceStatus.APPROVED) - .authorEmail("useremail@gmail.com") - .placeName("test place name") - .authorFirstName("test author first name") - .authorLanguage("en") - .build(); - when(messageSource.getMessage(EmailConstants.CHANGE_PLACE_STATUS, null, - getLocale(changePlaceStatusDto.getAuthorLanguage()))) - .thenReturn("Change place status"); - service.sendChangePlaceStatusEmail(changePlaceStatusDto); - verify(javaMailSender).createMimeMessage(); - } - @Test void sendAddedNewPlacesReportEmailTest() { SendReportEmailMessage sendReportEmailMessage = SendReportEmailMessage.builder() From 7ed50e91ffbee539c58dfdef09f94b9a5be55821 Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Fri, 11 Oct 2024 10:06:30 +0300 Subject: [PATCH 3/4] Change name. --- .../main/java/greencity/message/SendReportEmailMessage.java | 2 +- service/src/main/java/greencity/service/EmailServiceImpl.java | 4 ++-- .../src/test/java/greencity/service/EmailServiceImplTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/service-api/src/main/java/greencity/message/SendReportEmailMessage.java b/service-api/src/main/java/greencity/message/SendReportEmailMessage.java index 875aacfa2..4c4fddffd 100644 --- a/service-api/src/main/java/greencity/message/SendReportEmailMessage.java +++ b/service-api/src/main/java/greencity/message/SendReportEmailMessage.java @@ -18,5 +18,5 @@ public class SendReportEmailMessage { private List subscribers; private Map> categoriesDtoWithPlacesDtoMap; - private EmailPreferencePeriodicity emailPreferencePeriodicity; + private EmailPreferencePeriodicity periodicity; } diff --git a/service/src/main/java/greencity/service/EmailServiceImpl.java b/service/src/main/java/greencity/service/EmailServiceImpl.java index efd4081d4..1fe5fd22d 100644 --- a/service/src/main/java/greencity/service/EmailServiceImpl.java +++ b/service/src/main/java/greencity/service/EmailServiceImpl.java @@ -65,11 +65,11 @@ public EmailServiceImpl(JavaMailSender javaMailSender, @Override public void sendAddedNewPlacesReportEmail(SendReportEmailMessage message) { log.info(LogMessage.IN_SEND_ADDED_NEW_PLACES_REPORT_EMAIL, message.getSubscribers(), - message.getCategoriesDtoWithPlacesDtoMap(), message.getEmailPreferencePeriodicity()); + message.getCategoriesDtoWithPlacesDtoMap(), message.getPeriodicity()); Map sharedModel = new HashMap<>(); sharedModel.put(EmailConstants.CLIENT_LINK, clientLink); sharedModel.put(EmailConstants.RESULT, message.getCategoriesDtoWithPlacesDtoMap()); - sharedModel.put(EmailConstants.REPORT_TYPE, message.getEmailPreferencePeriodicity().name()); + sharedModel.put(EmailConstants.REPORT_TYPE, message.getPeriodicity().name()); for (SubscriberDto user : message.getSubscribers()) { Map model = new HashMap<>(sharedModel); diff --git a/service/src/test/java/greencity/service/EmailServiceImplTest.java b/service/src/test/java/greencity/service/EmailServiceImplTest.java index a8ae8c35a..1d486434f 100644 --- a/service/src/test/java/greencity/service/EmailServiceImplTest.java +++ b/service/src/test/java/greencity/service/EmailServiceImplTest.java @@ -74,7 +74,7 @@ void sendAddedNewPlacesReportEmailTest() { .name("Hotels") .build()) .build()))) - .emailPreferencePeriodicity(EmailPreferencePeriodicity.WEEKLY) + .periodicity(EmailPreferencePeriodicity.WEEKLY) .build(); service.sendAddedNewPlacesReportEmail(sendReportEmailMessage); verify(javaMailSender).createMimeMessage(); From c88949916c398df936b037db4a0592cc9fc3d541 Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Fri, 11 Oct 2024 15:03:40 +0300 Subject: [PATCH 4/4] Fix tests. --- .../controller/EmailControllerTest.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/core/src/test/java/greencity/controller/EmailControllerTest.java b/core/src/test/java/greencity/controller/EmailControllerTest.java index cd6373d46..c5eafe73e 100644 --- a/core/src/test/java/greencity/controller/EmailControllerTest.java +++ b/core/src/test/java/greencity/controller/EmailControllerTest.java @@ -99,7 +99,7 @@ void sendReport() throws Exception { } ] }, - "emailNotification": "WEEKLY", + "periodicity": "WEEKLY", "subscribers": [ { "email": "string", @@ -117,23 +117,6 @@ void sendReport() throws Exception { verify(emailService).sendAddedNewPlacesReportEmail(message); } - @Test - void changePlaceStatusInvalidPlaceStatus() throws Exception { - String content = """ - {\ - "authorEmail":"string",\ - "authorFirstName":"string",\ - "placeName":"string",\ - "placeStatus":"ggggggg"\ - }\ - """; - - mockMvc.perform(post(LINK + "/changePlaceStatus") - .content(content) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void sendHabitNotification() throws Exception { String content = """