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 17f981c27..000000000 --- a/dao/src/main/java/greencity/entity/localization/AchievementTranslation.java +++ /dev/null @@ -1,37 +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; - - @ManyToOne - private Language language; - - @Column(nullable = false, length = 300) - private String title; - - @Column(nullable = false, length = 300) - private String description; - - @Column(nullable = false, length = 300) - private String message; - - @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 c679df4b5..000000000 --- a/service-api/src/main/java/greencity/dto/achievement/AchievementTranslationVO.java +++ /dev/null @@ -1,27 +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 LanguageVO language; - - private String title; - - private String description; - - private String message; -} 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..65c0f9160 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 @@ -15,14 +14,11 @@ @Builder public class AchievementVO { private Long id; - - private List translations; - - private List userAchievements; - + 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 79259a314..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 greencity.enums.AchievementStatus; import lombok.*; - import javax.validation.constraints.NotEmpty; @Data @@ -21,9 +19,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 9656d60cd..ffad2ab68 100644 --- a/service/src/main/java/greencity/mapping/AchievementVOMapper.java +++ b/service/src/main/java/greencity/mapping/AchievementVOMapper.java @@ -1,39 +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()) - .title(achievementTranslation.getTitle()) - .description(achievementTranslation.getDescription()) - .message(achievementTranslation.getMessage()) - .language(LanguageVO.builder() - .id(achievementTranslation.getLanguage().getId()) - .code(achievementTranslation.getLanguage().getCode()) - .build()) - .build())); return AchievementVO.builder() .id(achievement.getId()) - .translations(list) + .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()) - .condition(achievement.getCondition()) .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..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.enums.AchievementStatus; import greencity.repository.AchievementRepo; import greencity.repository.UserAchievementRepo; import lombok.AllArgsConstructor; @@ -44,7 +43,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 353386d73..721da93eb 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -37,15 +37,12 @@ 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; 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; @@ -310,7 +307,6 @@ public static UserVO getUserVOWithData() { .userAchievements(List.of( UserAchievementVO.builder() .id(47L) - .achievementStatus(AchievementStatus.ACTIVE) .user(UserVO.builder() .id(13L) .build()) @@ -320,7 +316,6 @@ public static UserVO getUserVOWithData() { .build(), UserAchievementVO.builder() .id(39L) - .achievementStatus(AchievementStatus.INACTIVE) .user(UserVO.builder() .id(13L) .build()) @@ -371,20 +366,18 @@ public static UserProfilePictureDto getUserProfilePictureDto() { } public static Achievement getAchievement() { - return new Achievement(1L, Collections.singletonList(getAchievementTranslation()), 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, Collections.emptyList(), Collections.emptyList(), new AchievementCategoryVO(), 1); - } - - public static AchievementTranslation getAchievementTranslation() { - return new AchievementTranslation(1L, getLanguage(), "Title", "Description", "Message", null); + return new AchievementVO(1L, "ACQUIRED_HABIT_14_DAYS", "Набуття звички протягом 14 днів", + "Acquired habit 14 days", 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 23ae4b776..c8f4c15a0 100644 --- a/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java +++ b/service/src/test/java/greencity/mapping/AchievementVOMapperTest.java @@ -1,53 +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; + private AchievementVOMapper achievementVOMapper; @Test void convert() { - List list = new ArrayList<>(); Achievement achievement = ModelUtils.getAchievement(); - - 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() .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..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.enums.AchievementStatus; import greencity.repository.AchievementRepo; import greencity.repository.UserAchievementRepo; import org.junit.jupiter.api.Test; @@ -44,11 +43,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); @@ -59,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