From 891a017d31f0cfb915f40df24009124ec9357a72 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Wed, 20 Sep 2023 10:41:18 +0300 Subject: [PATCH 1/8] Fixed translations table --- .../entity/localization/AchievementTranslation.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/dao/src/main/java/greencity/entity/localization/AchievementTranslation.java b/dao/src/main/java/greencity/entity/localization/AchievementTranslation.java index 17f981c27..f11b6e8a0 100644 --- a/dao/src/main/java/greencity/entity/localization/AchievementTranslation.java +++ b/dao/src/main/java/greencity/entity/localization/AchievementTranslation.java @@ -20,17 +20,10 @@ public class AchievementTranslation { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - private Language language; - @Column(nullable = false, length = 300) - private String title; - - @Column(nullable = false, length = 300) - private String description; - + private String name; @Column(nullable = false, length = 300) - private String message; + private String nameEng; @ManyToOne private Achievement achievement; From b93cfa32c3168afa56ede176f90ea881142c9c78 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Wed, 20 Sep 2023 10:53:20 +0300 Subject: [PATCH 2/8] Fixed translations table --- .../achievement/AchievementTranslationVO.java | 9 ++---- .../mapping/AchievementVOMapper.java | 32 ++++++++----------- .../src/test/java/greencity/ModelUtils.java | 2 +- .../mapping/AchievementVOMapperTest.java | 7 ---- 4 files changed, 17 insertions(+), 33 deletions(-) diff --git a/service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java b/service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java index c679df4b5..5ea3985cd 100644 --- a/service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java +++ b/service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java @@ -16,12 +16,9 @@ @Builder public class AchievementTranslationVO { private Long id; + private Long achievement_id; - private LanguageVO language; + private String name; - private String title; - - private String description; - - private String message; + private String nameEng; } diff --git a/service/src/main/java/greencity/mapping/AchievementVOMapper.java b/service/src/main/java/greencity/mapping/AchievementVOMapper.java index 9656d60cd..f8f14995c 100644 --- a/service/src/main/java/greencity/mapping/AchievementVOMapper.java +++ b/service/src/main/java/greencity/mapping/AchievementVOMapper.java @@ -10,30 +10,24 @@ import java.util.ArrayList; import java.util.List; - @Component public class AchievementVOMapper extends AbstractConverter { @Override protected AchievementVO convert(Achievement achievement) { List list = new ArrayList<>(); - achievement.getTranslations().forEach(achievementTranslation -> list.add(AchievementTranslationVO.builder() - .id(achievementTranslation.getId()) - .title(achievementTranslation.getTitle()) - .description(achievementTranslation.getDescription()) - .message(achievementTranslation.getMessage()) - .language(LanguageVO.builder() - .id(achievementTranslation.getLanguage().getId()) - .code(achievementTranslation.getLanguage().getCode()) - .build()) - .build())); + achievement.getTranslations() + .forEach(achievementTranslation -> list.add(AchievementTranslationVO.builder() + .id(achievementTranslation.getId()) + .name(achievementTranslation.getName()) + .nameEng(achievementTranslation.getNameEng()) + .build())); return AchievementVO.builder() - .id(achievement.getId()) - .translations(list) - .achievementCategory(AchievementCategoryVO.builder() - .id(achievement.getAchievementCategory().getId()) - .name(achievement.getAchievementCategory().getName()) - .build()) - .condition(achievement.getCondition()) - .build(); + .id(achievement.getId()) + .translations(list) + .achievementCategory(AchievementCategoryVO.builder() + .id(achievement.getAchievementCategory().getId()) + .name(achievement.getAchievementCategory().getName()) + .build()) + .build(); } } diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 353386d73..cc28343cc 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -380,7 +380,7 @@ public static AchievementVO getAchievementVO() { } public static AchievementTranslation getAchievementTranslation() { - return new AchievementTranslation(1L, getLanguage(), "Title", "Description", "Message", null); + return new AchievementTranslation(1L, "Title", "Description", getAchievement()); } public static UserAchievement getUserAchievement() { diff --git a/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java b/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java index 23ae4b776..ab3507821 100644 --- a/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java +++ b/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java @@ -29,13 +29,6 @@ void convert() { achievement.getTranslations().forEach(achievementTranslation -> list.add(AchievementTranslationVO.builder() .id(achievementTranslation.getId()) - .title(achievementTranslation.getTitle()) - .description(achievementTranslation.getDescription()) - .message(achievementTranslation.getMessage()) - .language(LanguageVO.builder() - .id(achievementTranslation.getLanguage().getId()) - .code(achievementTranslation.getLanguage().getCode()) - .build()) .build())); AchievementVO expected = AchievementVO.builder() From ed5f5d6ce90328e27a8e4852c930981aec951c40 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Thu, 21 Sep 2023 12:47:35 +0300 Subject: [PATCH 3/8] Deleted unused code --- .../java/greencity/entity/Achievement.java | 12 +++++--- .../greencity/entity/AchievementCategory.java | 4 --- .../greencity/entity/UserAchievement.java | 7 +---- .../localization/AchievementTranslation.java | 30 ------------------- .../greencity/enums/AchievementStatus.java | 6 ---- .../achievement/AchievementTranslationVO.java | 24 --------------- .../dto/achievement/AchievementVO.java | 7 ++--- .../dto/achievement/UserAchievementVO.java | 5 +--- .../greencity/enums/AchievementStatus.java | 6 ---- .../mapping/AchievementVOMapper.java | 29 +++++++----------- .../mapping/UserVOAchievementMapper.java | 1 - .../java/greencity/mapping/UserVOMapper.java | 1 - .../service/AchievementServiceImpl.java | 3 +- .../src/test/java/greencity/ModelUtils.java | 15 +++------- .../mapping/AchievementVOMapperTest.java | 20 ++++--------- .../mapping/UserVOAchievementMapperTest.java | 1 - .../greencity/mapping/UserVOMapperTest.java | 1 - .../service/AchievementServiceImplTest.java | 4 +-- 18 files changed, 35 insertions(+), 141 deletions(-) delete mode 100644 dao/src/main/java/greencity/entity/localization/AchievementTranslation.java delete mode 100644 dao/src/main/java/greencity/enums/AchievementStatus.java delete mode 100644 service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java delete mode 100644 service-api/src/main/java/greencity/enums/AchievementStatus.java diff --git a/dao/src/main/java/greencity/entity/Achievement.java b/dao/src/main/java/greencity/entity/Achievement.java index ee93bddb1..9370f7d99 100644 --- a/dao/src/main/java/greencity/entity/Achievement.java +++ b/dao/src/main/java/greencity/entity/Achievement.java @@ -1,6 +1,5 @@ package greencity.entity; -import greencity.entity.localization.AchievementTranslation; import lombok.*; import javax.persistence.*; @@ -19,8 +18,13 @@ public class Achievement { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "achievement", fetch = FetchType.LAZY) - private List translations; + @Column(nullable = false, length = 300) + private String title; + + @Column(nullable = false, length = 300) + private String name; + @Column(nullable = false, length = 300) + private String nameEng; @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "achievement", fetch = FetchType.LAZY) private List userAchievements; @@ -30,4 +34,4 @@ public class Achievement { @Column(nullable = false) private Integer condition; -} +} \ No newline at end of file diff --git a/dao/src/main/java/greencity/entity/AchievementCategory.java b/dao/src/main/java/greencity/entity/AchievementCategory.java index 52a85265f..80de48ed3 100644 --- a/dao/src/main/java/greencity/entity/AchievementCategory.java +++ b/dao/src/main/java/greencity/entity/AchievementCategory.java @@ -20,10 +20,6 @@ public class AchievementCategory { @Column(nullable = false, unique = true, length = 100) private String name; - @OneToMany(mappedBy = "achievementCategory") private List achievementList; - - @OneToMany(mappedBy = "achievementCategory") - private List userActions; } diff --git a/dao/src/main/java/greencity/entity/UserAchievement.java b/dao/src/main/java/greencity/entity/UserAchievement.java index e30923d5e..b56f313f6 100644 --- a/dao/src/main/java/greencity/entity/UserAchievement.java +++ b/dao/src/main/java/greencity/entity/UserAchievement.java @@ -1,18 +1,17 @@ package greencity.entity; -import greencity.enums.AchievementStatus; import lombok.*; import javax.persistence.*; @Entity @Data -@Table(name = "user_achievements") @NoArgsConstructor @AllArgsConstructor @Builder @EqualsAndHashCode @ToString(exclude = {"user", "achievement"}) +@Table(name = "user_achievements") public class UserAchievement { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -24,10 +23,6 @@ public class UserAchievement { @ManyToOne(fetch = FetchType.LAZY) private Achievement achievement; - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - private AchievementStatus achievementStatus = AchievementStatus.INACTIVE; - @Column private boolean notified; } diff --git a/dao/src/main/java/greencity/entity/localization/AchievementTranslation.java b/dao/src/main/java/greencity/entity/localization/AchievementTranslation.java deleted file mode 100644 index f11b6e8a0..000000000 --- a/dao/src/main/java/greencity/entity/localization/AchievementTranslation.java +++ /dev/null @@ -1,30 +0,0 @@ -package greencity.entity.localization; - -import greencity.entity.Achievement; -import greencity.entity.Language; -import lombok.*; -import lombok.experimental.SuperBuilder; - -import javax.persistence.*; - -@Entity -@Table(name = "achievement_translations") -@SuperBuilder -@EqualsAndHashCode(exclude = "achievement") -@NoArgsConstructor -@Getter -@Setter -@AllArgsConstructor -public class AchievementTranslation { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false, length = 300) - private String name; - @Column(nullable = false, length = 300) - private String nameEng; - - @ManyToOne - private Achievement achievement; -} diff --git a/dao/src/main/java/greencity/enums/AchievementStatus.java b/dao/src/main/java/greencity/enums/AchievementStatus.java deleted file mode 100644 index 01b8ea298..000000000 --- a/dao/src/main/java/greencity/enums/AchievementStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package greencity.enums; - -public enum AchievementStatus { - INACTIVE, - ACTIVE -} diff --git a/service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java b/service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java deleted file mode 100644 index 5ea3985cd..000000000 --- a/service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java +++ /dev/null @@ -1,24 +0,0 @@ -package greencity.dto.achievement; - -import greencity.dto.language.LanguageVO; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Setter -@EqualsAndHashCode -@Builder -public class AchievementTranslationVO { - private Long id; - private Long achievement_id; - - private String name; - - private String nameEng; -} diff --git a/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java b/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java index 2141a20f9..6e3b7a11d 100644 --- a/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java +++ b/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java @@ -15,11 +15,10 @@ @Builder public class AchievementVO { private Long id; + private String title; - private List translations; - - private List userAchievements; - + private String name; + private String nameEng; @NotEmpty private AchievementCategoryVO achievementCategory; diff --git a/service-api/src/main/java/greencity/dto/achievement/UserAchievementVO.java b/service-api/src/main/java/greencity/dto/achievement/UserAchievementVO.java index 79259a314..811518d08 100644 --- a/service-api/src/main/java/greencity/dto/achievement/UserAchievementVO.java +++ b/service-api/src/main/java/greencity/dto/achievement/UserAchievementVO.java @@ -1,7 +1,7 @@ package greencity.dto.achievement; import greencity.dto.user.UserVO; -import greencity.enums.AchievementStatus; + import lombok.*; import javax.validation.constraints.NotEmpty; @@ -21,9 +21,6 @@ public class UserAchievementVO { @NotEmpty private AchievementVO achievement; - @NotEmpty - private AchievementStatus achievementStatus; - @NotEmpty private boolean notified; } diff --git a/service-api/src/main/java/greencity/enums/AchievementStatus.java b/service-api/src/main/java/greencity/enums/AchievementStatus.java deleted file mode 100644 index 01b8ea298..000000000 --- a/service-api/src/main/java/greencity/enums/AchievementStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package greencity.enums; - -public enum AchievementStatus { - INACTIVE, - ACTIVE -} diff --git a/service/src/main/java/greencity/mapping/AchievementVOMapper.java b/service/src/main/java/greencity/mapping/AchievementVOMapper.java index f8f14995c..ffad2ab68 100644 --- a/service/src/main/java/greencity/mapping/AchievementVOMapper.java +++ b/service/src/main/java/greencity/mapping/AchievementVOMapper.java @@ -1,33 +1,26 @@ package greencity.mapping; -import greencity.dto.achievement.AchievementTranslationVO; import greencity.dto.achievement.AchievementVO; import greencity.dto.achievementcategory.AchievementCategoryVO; -import greencity.dto.language.LanguageVO; import greencity.entity.Achievement; import org.modelmapper.AbstractConverter; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; @Component public class AchievementVOMapper extends AbstractConverter { @Override protected AchievementVO convert(Achievement achievement) { - List list = new ArrayList<>(); - achievement.getTranslations() - .forEach(achievementTranslation -> list.add(AchievementTranslationVO.builder() - .id(achievementTranslation.getId()) - .name(achievementTranslation.getName()) - .nameEng(achievementTranslation.getNameEng()) - .build())); return AchievementVO.builder() - .id(achievement.getId()) - .translations(list) - .achievementCategory(AchievementCategoryVO.builder() - .id(achievement.getAchievementCategory().getId()) - .name(achievement.getAchievementCategory().getName()) - .build()) - .build(); + .id(achievement.getId()) + .condition(achievement.getCondition()) + .title(achievement.getTitle()) + .name(achievement.getName()) + .nameEng(achievement.getNameEng()) + .condition(achievement.getCondition()) + .achievementCategory(AchievementCategoryVO.builder() + .id(achievement.getAchievementCategory().getId()) + .name(achievement.getAchievementCategory().getName()) + .build()) + .build(); } } diff --git a/service/src/main/java/greencity/mapping/UserVOAchievementMapper.java b/service/src/main/java/greencity/mapping/UserVOAchievementMapper.java index 453ba975b..f47603ef0 100644 --- a/service/src/main/java/greencity/mapping/UserVOAchievementMapper.java +++ b/service/src/main/java/greencity/mapping/UserVOAchievementMapper.java @@ -20,7 +20,6 @@ protected UserVOAchievement convert(User user) { .userAchievements(user.getUserAchievements() != null ? user.getUserAchievements() .stream().map(userAchievement -> UserAchievementVO.builder() .id(userAchievement.getId()) - .achievementStatus(userAchievement.getAchievementStatus()) .user(UserVO.builder() .id(userAchievement.getUser().getId()) .build()) diff --git a/service/src/main/java/greencity/mapping/UserVOMapper.java b/service/src/main/java/greencity/mapping/UserVOMapper.java index ce24884dc..9d00a4538 100644 --- a/service/src/main/java/greencity/mapping/UserVOMapper.java +++ b/service/src/main/java/greencity/mapping/UserVOMapper.java @@ -63,7 +63,6 @@ protected UserVO convert(User user) { .userAchievements(user.getUserAchievements() != null ? user.getUserAchievements() .stream().map(userAchievement -> UserAchievementVO.builder() .id(userAchievement.getId()) - .achievementStatus(userAchievement.getAchievementStatus()) .user(UserVO.builder() .id(userAchievement.getUser().getId()) .build()) diff --git a/service/src/main/java/greencity/service/AchievementServiceImpl.java b/service/src/main/java/greencity/service/AchievementServiceImpl.java index 2fec52dfd..e6cd2db06 100644 --- a/service/src/main/java/greencity/service/AchievementServiceImpl.java +++ b/service/src/main/java/greencity/service/AchievementServiceImpl.java @@ -3,7 +3,7 @@ import greencity.constant.CacheConstants; import greencity.dto.achievement.AchievementVO; import greencity.entity.UserAchievement; -import greencity.enums.AchievementStatus; + import greencity.repository.AchievementRepo; import greencity.repository.UserAchievementRepo; import lombok.AllArgsConstructor; @@ -44,7 +44,6 @@ public List findAll() { public void findUserAchievement(Long userId, Long achievementId) { UserAchievement userAchievement = userAchievementRepo .getUserAchievementByIdAndAchievementId(userId, achievementId); - userAchievement.setAchievementStatus(AchievementStatus.ACTIVE); userAchievementRepo.save(userAchievement); } } diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index cc28343cc..a3434afed 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -37,8 +37,7 @@ import greencity.entity.User; import greencity.entity.UserAchievement; import greencity.entity.VerifyEmail; -import greencity.entity.localization.AchievementTranslation; -import greencity.enums.AchievementStatus; + import greencity.enums.EmailNotification; import greencity.enums.Role; import greencity.enums.UserStatus; @@ -310,7 +309,6 @@ public static UserVO getUserVOWithData() { .userAchievements(List.of( UserAchievementVO.builder() .id(47L) - .achievementStatus(AchievementStatus.ACTIVE) .user(UserVO.builder() .id(13L) .build()) @@ -320,7 +318,6 @@ public static UserVO getUserVOWithData() { .build(), UserAchievementVO.builder() .id(39L) - .achievementStatus(AchievementStatus.INACTIVE) .user(UserVO.builder() .id(13L) .build()) @@ -371,20 +368,16 @@ public static UserProfilePictureDto getUserProfilePictureDto() { } public static Achievement getAchievement() { - return new Achievement(1L, Collections.singletonList(getAchievementTranslation()), Collections.emptyList(), + return new Achievement(1L, "name", "name", "name", Collections.emptyList(), new AchievementCategory(), 1); } public static AchievementVO getAchievementVO() { - return new AchievementVO(1L, Collections.emptyList(), Collections.emptyList(), new AchievementCategoryVO(), 1); - } - - public static AchievementTranslation getAchievementTranslation() { - return new AchievementTranslation(1L, "Title", "Description", getAchievement()); + return new AchievementVO(1L, "name", "name", "name", new AchievementCategoryVO(), 1); } public static UserAchievement getUserAchievement() { - return new UserAchievement(1L, getUser(), getAchievement(), AchievementStatus.ACTIVE, false); + return new UserAchievement(1L, getUser(), getAchievement(), false); } public static EcoNewsAuthorDto getEcoNewsAuthorDto() { diff --git a/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java b/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java index ab3507821..710cc0146 100644 --- a/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java +++ b/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java @@ -1,46 +1,36 @@ package greencity.mapping; import greencity.ModelUtils; -import greencity.dto.achievement.AchievementTranslationVO; import greencity.dto.achievement.AchievementVO; import greencity.dto.achievementcategory.AchievementCategoryVO; -import greencity.dto.language.LanguageVO; import greencity.entity.Achievement; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.ArrayList; -import java.util.List; - import static org.junit.jupiter.api.Assertions.*; @ExtendWith(MockitoExtension.class) class AchievementVOMapperTest { @InjectMocks - AchievementVOMapper mapper; + AchievementVOMapper achievementVOMapper; @Test void convert() { - List list = new ArrayList<>(); Achievement achievement = ModelUtils.getAchievement(); - - achievement.getTranslations().forEach(achievementTranslation -> list.add(AchievementTranslationVO.builder() - .id(achievementTranslation.getId()) - .build())); - AchievementVO expected = AchievementVO.builder() .id(achievement.getId()) - .translations(list) + .title(achievement.getTitle()) + .name(achievement.getName()) + .nameEng(achievement.getNameEng()) .achievementCategory(AchievementCategoryVO.builder() .id(achievement.getAchievementCategory().getId()) .name(achievement.getAchievementCategory().getName()) .build()) .condition(achievement.getCondition()) .build(); - - assertEquals(expected, mapper.convert(achievement)); + assertEquals(expected, achievementVOMapper.convert(achievement)); } } \ No newline at end of file diff --git a/service/src/test/java/greencity/mapping/UserVOAchievementMapperTest.java b/service/src/test/java/greencity/mapping/UserVOAchievementMapperTest.java index 7b5129367..efe43fc42 100644 --- a/service/src/test/java/greencity/mapping/UserVOAchievementMapperTest.java +++ b/service/src/test/java/greencity/mapping/UserVOAchievementMapperTest.java @@ -33,7 +33,6 @@ void convert() { .userAchievements(user.getUserAchievements() != null ? user.getUserAchievements() .stream().map(userAchievement -> UserAchievementVO.builder() .id(userAchievement.getId()) - .achievementStatus(userAchievement.getAchievementStatus()) .user(UserVO.builder() .id(userAchievement.getUser().getId()) .build()) diff --git a/service/src/test/java/greencity/mapping/UserVOMapperTest.java b/service/src/test/java/greencity/mapping/UserVOMapperTest.java index 7b71748f8..a1d9eed67 100644 --- a/service/src/test/java/greencity/mapping/UserVOMapperTest.java +++ b/service/src/test/java/greencity/mapping/UserVOMapperTest.java @@ -65,7 +65,6 @@ void convert() { .userAchievements(expected.getUserAchievements() != null ? expected.getUserAchievements() .stream().map(userAchievement -> UserAchievement.builder() .id(userAchievement.getId()) - .achievementStatus(userAchievement.getAchievementStatus()) .user(User.builder() .id(userAchievement.getUser().getId()) .build()) diff --git a/service/src/test/java/greencity/service/AchievementServiceImplTest.java b/service/src/test/java/greencity/service/AchievementServiceImplTest.java index fd288b3de..4fa26e627 100644 --- a/service/src/test/java/greencity/service/AchievementServiceImplTest.java +++ b/service/src/test/java/greencity/service/AchievementServiceImplTest.java @@ -5,7 +5,7 @@ import greencity.entity.Achievement; import greencity.entity.User; import greencity.entity.UserAchievement; -import greencity.enums.AchievementStatus; + import greencity.repository.AchievementRepo; import greencity.repository.UserAchievementRepo; import org.junit.jupiter.api.Test; @@ -44,11 +44,9 @@ void findUserAchievement() { .user(new User()) .achievement(new Achievement()) .notified(false) - .achievementStatus(AchievementStatus.INACTIVE) .build(); when(userAchievementRepo.getUserAchievementByIdAndAchievementId(1L, 1L)) .thenReturn(userAchievement); - userAchievement.setAchievementStatus(AchievementStatus.ACTIVE); achievementService.findUserAchievement(1L, 1L); verify(userAchievementRepo).save(userAchievement); From cce212047f3e08e877f1e8eab3d11b64d614bd72 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 26 Sep 2023 09:55:32 +0300 Subject: [PATCH 4/8] Added status to achievement --- dao/src/main/java/greencity/enums/AchievementStatus.java | 6 ++++++ .../src/main/java/greencity/enums/AchievementStatus.java | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 dao/src/main/java/greencity/enums/AchievementStatus.java create mode 100644 service-api/src/main/java/greencity/enums/AchievementStatus.java diff --git a/dao/src/main/java/greencity/enums/AchievementStatus.java b/dao/src/main/java/greencity/enums/AchievementStatus.java new file mode 100644 index 000000000..01b8ea298 --- /dev/null +++ b/dao/src/main/java/greencity/enums/AchievementStatus.java @@ -0,0 +1,6 @@ +package greencity.enums; + +public enum AchievementStatus { + INACTIVE, + ACTIVE +} diff --git a/service-api/src/main/java/greencity/enums/AchievementStatus.java b/service-api/src/main/java/greencity/enums/AchievementStatus.java new file mode 100644 index 000000000..01b8ea298 --- /dev/null +++ b/service-api/src/main/java/greencity/enums/AchievementStatus.java @@ -0,0 +1,6 @@ +package greencity.enums; + +public enum AchievementStatus { + INACTIVE, + ACTIVE +} From de888b30f4f7cf3bf6d8a6165161120b97925f07 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 26 Sep 2023 10:01:30 +0300 Subject: [PATCH 5/8] Deleetd unused enum --- dao/src/main/java/greencity/enums/AchievementStatus.java | 6 ------ .../src/main/java/greencity/enums/AchievementStatus.java | 6 ------ 2 files changed, 12 deletions(-) delete mode 100644 dao/src/main/java/greencity/enums/AchievementStatus.java delete mode 100644 service-api/src/main/java/greencity/enums/AchievementStatus.java diff --git a/dao/src/main/java/greencity/enums/AchievementStatus.java b/dao/src/main/java/greencity/enums/AchievementStatus.java deleted file mode 100644 index 01b8ea298..000000000 --- a/dao/src/main/java/greencity/enums/AchievementStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package greencity.enums; - -public enum AchievementStatus { - INACTIVE, - ACTIVE -} diff --git a/service-api/src/main/java/greencity/enums/AchievementStatus.java b/service-api/src/main/java/greencity/enums/AchievementStatus.java deleted file mode 100644 index 01b8ea298..000000000 --- a/service-api/src/main/java/greencity/enums/AchievementStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package greencity.enums; - -public enum AchievementStatus { - INACTIVE, - ACTIVE -} From cccbc98e330bd309daa7c6bd16dfe84140619935 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 26 Sep 2023 10:06:14 +0300 Subject: [PATCH 6/8] Removed codesmell --- .../src/main/java/greencity/dto/achievement/AchievementVO.java | 1 - 1 file changed, 1 deletion(-) diff --git a/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java b/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java index 6e3b7a11d..ff6a1320b 100644 --- a/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java +++ b/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java @@ -7,7 +7,6 @@ import lombok.NoArgsConstructor; import javax.validation.constraints.NotEmpty; -import java.util.List; @Data @NoArgsConstructor From 0dedfc186ccaf21cc2f1e2b553c31366797e0be2 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 3 Oct 2023 12:36:58 +0300 Subject: [PATCH 7/8] Fixed blank lines and test values --- .../main/java/greencity/dto/achievement/AchievementVO.java | 2 -- .../java/greencity/dto/achievement/UserAchievementVO.java | 2 -- service/src/test/java/greencity/ModelUtils.java | 6 ++++-- .../java/greencity/service/AchievementServiceImplTest.java | 3 --- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java b/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java index ff6a1320b..65c0f9160 100644 --- a/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java +++ b/service-api/src/main/java/greencity/dto/achievement/AchievementVO.java @@ -15,12 +15,10 @@ public class AchievementVO { private Long id; private String title; - private String name; private String nameEng; @NotEmpty private AchievementCategoryVO achievementCategory; - @NotEmpty private Integer condition; } diff --git a/service-api/src/main/java/greencity/dto/achievement/UserAchievementVO.java b/service-api/src/main/java/greencity/dto/achievement/UserAchievementVO.java index 811518d08..60b24b70a 100644 --- a/service-api/src/main/java/greencity/dto/achievement/UserAchievementVO.java +++ b/service-api/src/main/java/greencity/dto/achievement/UserAchievementVO.java @@ -1,9 +1,7 @@ package greencity.dto.achievement; import greencity.dto.user.UserVO; - import lombok.*; - import javax.validation.constraints.NotEmpty; @Data diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index a3434afed..75dc4622c 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -368,12 +368,14 @@ public static UserProfilePictureDto getUserProfilePictureDto() { } public static Achievement getAchievement() { - return new Achievement(1L, "name", "name", "name", Collections.emptyList(), + return new Achievement(1L, "ACQUIRED_HABIT_14_DAYS", "Набуття звички протягом 14 днів", + "Acquired habit 14 days", Collections.emptyList(), new AchievementCategory(), 1); } public static AchievementVO getAchievementVO() { - return new AchievementVO(1L, "name", "name", "name", new AchievementCategoryVO(), 1); + return new AchievementVO(1L, "ACQUIRED_HABIT_14_DAYS", "Набуття звички протягом 14 днів", + "Acquired habit 14 days", new AchievementCategoryVO(), 1); } public static UserAchievement getUserAchievement() { diff --git a/service/src/test/java/greencity/service/AchievementServiceImplTest.java b/service/src/test/java/greencity/service/AchievementServiceImplTest.java index 4fa26e627..cd42ea464 100644 --- a/service/src/test/java/greencity/service/AchievementServiceImplTest.java +++ b/service/src/test/java/greencity/service/AchievementServiceImplTest.java @@ -5,7 +5,6 @@ import greencity.entity.Achievement; import greencity.entity.User; import greencity.entity.UserAchievement; - import greencity.repository.AchievementRepo; import greencity.repository.UserAchievementRepo; import org.junit.jupiter.api.Test; @@ -57,10 +56,8 @@ void findAllTest() { List achievementVOS = new ArrayList<>(); achievementVOS.add(ModelUtils.getAchievement()); when(achievementRepo.findAll()).thenReturn(achievementVOS); - List allAchievements = achievementService.findAll(); assertFalse(allAchievements.isEmpty()); - } } \ No newline at end of file From 6d408b6d9bb3b981e0e437d2354437c340f1892e Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Tue, 3 Oct 2023 22:36:24 +0300 Subject: [PATCH 8/8] Fixed blank lines --- .../src/main/java/greencity/service/AchievementServiceImpl.java | 1 - service/src/test/java/greencity/ModelUtils.java | 2 -- .../test/java/greencity/mapping/AchievementVOMapperTest.java | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/service/src/main/java/greencity/service/AchievementServiceImpl.java b/service/src/main/java/greencity/service/AchievementServiceImpl.java index e6cd2db06..10c526fe6 100644 --- a/service/src/main/java/greencity/service/AchievementServiceImpl.java +++ b/service/src/main/java/greencity/service/AchievementServiceImpl.java @@ -3,7 +3,6 @@ import greencity.constant.CacheConstants; import greencity.dto.achievement.AchievementVO; import greencity.entity.UserAchievement; - import greencity.repository.AchievementRepo; import greencity.repository.UserAchievementRepo; import lombok.AllArgsConstructor; diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 75dc4622c..721da93eb 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -37,14 +37,12 @@ import greencity.entity.User; import greencity.entity.UserAchievement; import greencity.entity.VerifyEmail; - import greencity.enums.EmailNotification; import greencity.enums.Role; import greencity.enums.UserStatus; import greencity.security.dto.ownsecurity.EmployeeSignUpDto; import greencity.security.dto.ownsecurity.OwnRestoreDto; import greencity.security.dto.ownsecurity.OwnSignUpDto; - import java.time.LocalDateTime; import java.time.ZonedDateTime; import java.util.ArrayList; diff --git a/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java b/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java index 710cc0146..c8f4c15a0 100644 --- a/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java +++ b/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java @@ -15,7 +15,7 @@ class AchievementVOMapperTest { @InjectMocks - AchievementVOMapper achievementVOMapper; + private AchievementVOMapper achievementVOMapper; @Test void convert() {