Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change structure acheievements #6419

Merged
merged 54 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d934f6d
Added ACHIEVEMENTS category
ospodaryk Sep 15, 2023
c75ee8a
Changed naming of category type
ospodaryk Sep 15, 2023
92894bd
Added values for achievements
ospodaryk Sep 15, 2023
79ee106
added code to reorganise achievements structure
ospodaryk Sep 18, 2023
cf46017
deleted condition from Achievement
ospodaryk Sep 18, 2023
738f387
Returned column condition
ospodaryk Sep 19, 2023
035b778
Working version when user gets achievements
ospodaryk Sep 19, 2023
565482d
Updated achievement_translations:deleted unused lines
ospodaryk Sep 19, 2023
e3ac1e0
Updated achievement_translations:deleted unused lines+Formatted
ospodaryk Sep 19, 2023
02a2bf8
Deleted from achieveent category unused fields
ospodaryk Sep 19, 2023
e44f254
Deleted separation by category in Achievements
ospodaryk Sep 19, 2023
68483ec
Fixed Translation dto
ospodaryk Sep 20, 2023
9f4b676
Everything worked
ospodaryk Sep 20, 2023
89e366d
Fixed AchievementTranslationDto
ospodaryk Sep 20, 2023
1908f99
Fixed tests
ospodaryk Sep 20, 2023
42badac
Fixed translations table
ospodaryk Sep 20, 2023
113f1c6
Deleted table achievement_translations
ospodaryk Sep 20, 2023
73e69de
Fixed tests and deleted translation table+ changed mapper
ospodaryk Sep 21, 2023
6e1b8fc
Formatted and fixed checkstyle
ospodaryk Sep 21, 2023
5043732
Merge branch 'dev' into update-achievements
ospodaryk Sep 21, 2023
c07f9e2
Fixed errors
ospodaryk Sep 21, 2023
47270ca
Fixed errors
ospodaryk Sep 21, 2023
20cb60d
Fixed bugs
ospodaryk Sep 21, 2023
4e0a2d2
Fixed codesmells
ospodaryk Sep 21, 2023
9bd6e29
Fixed code
ospodaryk Sep 21, 2023
6dd1c48
Fixed code
ospodaryk Sep 21, 2023
1ca5933
Created AchievementAction to check if we have to add achievements or …
ospodaryk Sep 22, 2023
2641893
Fixed test to work
ospodaryk Sep 22, 2023
c4c05ec
Added preconditions to changelog
ospodaryk Sep 22, 2023
283d1fe
Fixed error when enum not found
ospodaryk Sep 22, 2023
c239895
Added preconditions to changelog
ospodaryk Sep 22, 2023
da968f6
Fixed rating calculation and added counting of score
ospodaryk Sep 22, 2023
f8d3065
Fixed tests
ospodaryk Sep 22, 2023
e4a72ce
Added logic to achievements to all methods
ospodaryk Sep 22, 2023
d048b57
Formatted and fixed style
ospodaryk Sep 22, 2023
a57c168
Formatted and added test to coverege
ospodaryk Sep 24, 2023
64158fd
Formatted and added test to coverege
ospodaryk Sep 24, 2023
8e9ad2a
Formatted and added test to coverege
ospodaryk Sep 25, 2023
c946ee1
Formatted and added test to coverage
ospodaryk Sep 25, 2023
78c1687
Deleted running async
ospodaryk Sep 25, 2023
d2bb1a5
Formatted and added test to coverage
ospodaryk Sep 25, 2023
d51aa36
Fixed codesmells
ospodaryk Sep 25, 2023
f01efd5
Added to table new values
ospodaryk Sep 25, 2023
a2558ba
Added methods to update score when we do action with events
ospodaryk Sep 25, 2023
8d833bd
Merge branch 'dev' into update-achievements
ospodaryk Sep 25, 2023
6835211
Leaved only methods which are changing structure of achievement entity
ospodaryk Sep 26, 2023
ab749fd
Fixed modelUtils
ospodaryk Sep 26, 2023
97adca4
Fixed code
ospodaryk Sep 26, 2023
9cd6297
Deleted unused files
ospodaryk Sep 26, 2023
a03c735
Fixed codesmell
ospodaryk Sep 27, 2023
ed70964
Merge branch 'dev' into change-structure-acheievements
ospodaryk Sep 27, 2023
6acb8cf
Fixed codesmell
ospodaryk Oct 3, 2023
cca7509
Added verify and removed blank lines
ospodaryk Oct 3, 2023
78a9f09
Removed blank lines
ospodaryk Oct 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions core/src/main/java/greencity/controller/AchievementController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import greencity.constant.HttpStatuses;
import greencity.dto.achievement.AchievementDTO;
import greencity.dto.achievement.AchievementNotification;
import greencity.dto.achievement.AchievementVO;
import greencity.dto.user.UserVO;
import greencity.enums.AchievementCategoryType;
import greencity.enums.AchievementType;
import greencity.service.AchievementService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
Expand Down Expand Up @@ -47,39 +43,4 @@ public AchievementController(AchievementService achievementService) {
public ResponseEntity<List<AchievementVO>> getAll() {
return ResponseEntity.status(HttpStatus.OK).body(achievementService.findAll());
}

/**
* Method notifies of the achievement.
*
* @param userId of {@link UserVO}
* @return list {@link AchievementNotification}
*/
@ApiOperation(value = "Get all the achievements that need to notify.")
@ApiResponses(value = {
@ApiResponse(code = 200, message = HttpStatuses.OK),
@ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST),
@ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
})
@GetMapping("/notification/{userId}")
ospodaryk marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<List<AchievementNotification>> getNotification(@PathVariable Long userId) {
return ResponseEntity.status(HttpStatus.OK).body(achievementService.findAchievementsWithStatusActive(userId));
}

/**
* Method for achievement calculation.
*/
@ApiOperation(value = "Calculate achievements.")
@ApiResponses(value = {
@ApiResponse(code = 200, message = HttpStatuses.OK),
@ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST),
@ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
})
@PostMapping("/calculate-achievement")
public ResponseEntity<HttpStatus> calculateAchievements(@RequestParam Long id,
@RequestParam AchievementType setter,
@RequestParam AchievementCategoryType socialNetwork,
@RequestParam int size) {
achievementService.calculateAchievements(id, setter, socialNetwork, size);
return ResponseEntity.ok().build();
}
}
19 changes: 6 additions & 13 deletions core/src/test/java/greencity/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import greencity.constant.AppConstant;
import greencity.dto.PageableAdvancedDto;
import greencity.dto.achievement.AchievementPostDto;
import greencity.dto.achievement.AchievementTranslationVO;

import greencity.dto.achievement.AchievementVO;
import greencity.dto.achievement.UserAchievementVO;
import greencity.dto.achievementcategory.AchievementCategoryDto;
import greencity.dto.achievementcategory.AchievementCategoryVO;
import greencity.dto.advice.AdvicePostDto;
Expand Down Expand Up @@ -582,25 +581,19 @@ public static ShoppingListItemPostDto getShoppingListItemPostDto() {
return new ShoppingListItemPostDto(getLanguageTranslationsDTOs(), new ShoppingListItemRequestDto(1L));
}

public static List<AchievementTranslationVO> getAchievementTranslationVOS() {
return Arrays.asList(
new AchievementTranslationVO(1L, getLanguageVO(), "title", "description", "message"),
new AchievementTranslationVO(2L, getLanguageVO(), "title", "description", "message"),
new AchievementTranslationVO(3L, getLanguageVO(), "title", "description", "message"));
}

public static AchievementCategoryDto getAchievementCategoryDto() {
return new AchievementCategoryDto("name");
}

public static AchievementPostDto getAchievementPostDto() {
return new AchievementPostDto(getAchievementTranslationVOS(), getAchievementCategoryDto(), 1);
return new AchievementPostDto("ACQUIRED_HABIT_14_DAYS", "Набуття звички протягом 14 днів",
"Acquired habit 14 days", getAchievementCategoryDto(), 1);
}

public static AchievementVO getAchievementVO() {
return new AchievementVO(1L, getAchievementTranslationVOS(),
Collections.singletonList(new UserAchievementVO()),
new AchievementCategoryVO(1L, "name", null, null), 1);
return new AchievementVO(1L, "ACQUIRED_HABIT_14_DAYS", "Набуття звички протягом 14 днів",
"Acquired habit 14 days",
new AchievementCategoryVO(1L, "name"), 1);
}

public static UserShoppingListItem getUserShoppingListItem() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package greencity.controller;

import greencity.enums.AchievementCategoryType;
import greencity.enums.AchievementType;
import greencity.service.AchievementService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -45,22 +44,4 @@ void findAllTest() throws Exception {
verify(achievementService).findAll();
}

@Test
void calculateAchievements() throws Exception {
mockMvc.perform(post(achievementLink + "/calculate-achievement"
+ "?id=" + 1L
+ "&setter=" + AchievementType.INCREMENT
+ "&socialNetwork=" + AchievementCategoryType.ECO_NEWS
+ "&size=" + 1)).andExpect(status().isOk());
verify(achievementService).calculateAchievements(1L, AchievementType.INCREMENT,
AchievementCategoryType.ECO_NEWS, 1);
}

@Test
void getNotificationTest() throws Exception {
mockMvc.perform(get(achievementLink
+ "/notification/{userId}", 1)).andExpect(status().isOk());
verify(achievementService).findAchievementsWithStatusActive(1L);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ void getAllAchievementSearchByQueryTest() throws Exception {

@Test
void saveAchievementTest() throws Exception {
// String accessToken = "accessToken";
// HttpHeaders headers = new HttpHeaders();
// headers.set(AUTHORIZATION, accessToken);
AchievementPostDto achievementPostDto = ModelUtils.getAchievementPostDto();
String content = objectMapper.writeValueAsString(achievementPostDto);
this.mockMvc.perform(post(link)
Expand Down
11 changes: 7 additions & 4 deletions dao/src/main/java/greencity/entity/Achievement.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package greencity.entity;

import greencity.entity.localization.AchievementTranslation;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
Expand Down Expand Up @@ -32,8 +30,13 @@ public class Achievement {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToMany(cascade = {CascadeType.ALL}, mappedBy = "achievement", fetch = FetchType.LAZY)
private List<AchievementTranslation> 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<UserAchievement> userAchievements;
Expand Down
4 changes: 0 additions & 4 deletions dao/src/main/java/greencity/entity/AchievementCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public class AchievementCategory {

@Column(nullable = false, unique = true, length = 100)
private String name;

@OneToMany(mappedBy = "achievementCategory")
private List<Achievement> achievementList;

@OneToMany(mappedBy = "achievementCategory")
private List<UserAction> userActions;
}
5 changes: 0 additions & 5 deletions dao/src/main/java/greencity/entity/UserAchievement.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package greencity.entity;

import greencity.enums.AchievementStatus;
import javax.persistence.*;

import lombok.*;
Expand All @@ -25,10 +24,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;
}

This file was deleted.

6 changes: 0 additions & 6 deletions dao/src/main/java/greencity/enums/AchievementStatus.java

This file was deleted.

15 changes: 6 additions & 9 deletions dao/src/main/java/greencity/repository/AchievementRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
@Repository
public interface AchievementRepo extends JpaRepository<Achievement, Long> {
/**
* Method returns {@link Achievement} by search query and page.
* Searches for achievements based on a query string and returns a paginated
* result.
*
* @param paging {@link Pageable}.
* @param query query to search.
* @return list of {@link Achievement}.
* @author Orest Mamchuk
* @param paging A Pageable object containing the pagination information (e.g.,
* page number, size, sort order).
* @param query The search query string to filter achievements.
* @return A Page of Achievement objects that match the search query.
*/
@Query("SELECT DISTINCT a FROM Achievement a "
+ "JOIN AchievementTranslation at on at.achievement.id = a.id "
+ "WHERE CONCAT(a.id,'') LIKE LOWER(CONCAT('%', :query, '%')) "
+ "OR LOWER(at.title) LIKE LOWER(CONCAT('%', :query, '%'))"
+ "OR LOWER(at.description) LIKE LOWER(CONCAT('%', :query, '%'))"
+ "OR LOWER(at.message) LIKE LOWER(CONCAT('%', :query, '%'))"
+ "OR LOWER(a.achievementCategory.name) LIKE LOWER(CONCAT('%', :query, '%'))"
+ "OR CONCAT(a.condition, ' ') LIKE LOWER(CONCAT('%', :query, '%'))")
Page<Achievement> searchAchievementsBy(Pageable paging, String query);
Expand Down

This file was deleted.

10 changes: 10 additions & 0 deletions dao/src/main/java/greencity/repository/UserAchievementRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface UserAchievementRepo extends JpaRepository<UserAchievement, Long> {
Expand All @@ -16,4 +17,13 @@ public interface UserAchievementRepo extends JpaRepository<UserAchievement, Long
*/
@Query(value = "FROM UserAchievement u WHERE u.user.id =:userId AND u.achievement.id =:achievementId")
UserAchievement getUserAchievementByIdAndAchievementId(Long userId, Long achievementId);

/**
* Retrieves a list of UserAchievement objects associated with a given user ID.
*
* @param userId The unique identifier of the user for whom to fetch the
* achievements.
* @return A list of UserAchievement objects related to the specified user ID.
*/
List<UserAchievement> getUserAchievementByUserId(Long userId);
}
3 changes: 3 additions & 0 deletions dao/src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
<include file="db/changelog/logs/ch-delete-from-fact_of_the_day_translations-Spodaryk.xml"/>
<include file="db/changelog/logs/ch-delete-from-tag_translations-Spodaryk.xml"/>
<include file="db/changelog/logs/ch-delete-from-languages-Spodaryk.xml"/>
<include file="db/changelog/logs/ch-add-column-achievements-Spodaryk.xml"/>
<include file="db/changelog/logs/ch-drop-column-user_achievements-Spodaryk.xml"/>
<include file="db/changelog/logs/ch-delete-table-achievement_translations-Spodaryk.xml"/>
<include file="db/changelog/logs/ch-delete-values-employee_authorities-mapping-Spodaryk.xml"/>
<include file="db/changelog/logs/ch-delete-values-positions_authorities-mapping-Spodaryk.xml"/>
</databaseChangeLog>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<changeSet id="Spodaryk-22" author="Oksana Spodaryk">
<preConditions onFail="MARK_RAN">
<and>
<tableExists tableName="achievements"/>
<not>
<columnExists tableName="achievements" columnName="title"/>
</not>
<not>
<columnExists tableName="achievements" columnName="name"/>
</not>
<not>
<columnExists tableName="achievements" columnName="name_eng"/>
</not>
<not>
<columnExists tableName="achievements" columnName="score"/>
</not>
</and>
</preConditions>

<addColumn tableName="achievements">
<column name="title" type="VARCHAR(255)">
<constraints nullable="true"/>
</column>
</addColumn>
<addColumn tableName="achievements">
<column name="name" type="VARCHAR(255)">
<constraints nullable="true"/>
</column>
</addColumn>
<addColumn tableName="achievements">
<column name="name_eng" type="VARCHAR(255)">
<constraints nullable="true"/>
</column>
</addColumn>
<addColumn tableName="achievements">
<column name="score" type="INT">
<constraints nullable="true"/>
</column>
</addColumn>
</changeSet>


</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<changeSet id="Spodaryk-25" author="Oksana Spodaryk">
<preConditions onFail="MARK_RAN">
<tableExists tableName="achievement_translations"/>
</preConditions>
<dropTable tableName="achievement_translations"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<changeSet id="Spodaryk-24" author="Oksana Spodaryk">
<preConditions onFail="MARK_RAN">
<columnExists tableName="user_achievements" columnName="achievement_status"/>
</preConditions>
<dropColumn tableName="user_achievements" columnName="achievement_status"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public final class ErrorMessage {
"Count of tags should be at least one but not more three";
public static final String TOKEN_FOR_RESTORE_IS_INVALID = "Token is null or it doesn't exist.";
public static final String ACHIEVEMENT_NOT_DELETED = "Achievement not deleted ";
public static final String ACHIEVEMENT_NOT_FOUND_BY_ID = "The name does not exist by this id: ";
public static final String ACHIEVEMENT_NOT_FOUND_BY_ID = "The achievement does not exist by this id: ";
public static final String PAGE_INDEX_IS_MORE_THAN_TOTAL_PAGES = "Page index is more than total pages: ";
public static final String MULTIPART_FILE_BAD_REQUEST =
"Can`t convert To Multipart Image. Bad inputed image string : ";
Expand Down
Loading
Loading