Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ToriForH committed Dec 6, 2024
1 parent c90bd0a commit 015fc88
Show file tree
Hide file tree
Showing 40 changed files with 338 additions and 302 deletions.
11 changes: 5 additions & 6 deletions core/src/main/java/greencity/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@ public class SecurityConfig {
private static final String ACTIVE = "/active";
private static final String CUSTOM_TO_DO_LIST = "/habits/custom-to-do-list-items";
private static final String TO_DO_LIST = "/habits/to-do-list-items";
private static final String USER_TO_DO_LIST = "/habits/assign/user-to-do-list-items";
private static final String USER_TO_DO_LIST = "/habits/assign/user-to-do-list-items/{habitAssignId}";
private static final String HABIT_ASSIGN_WITH_HABIT_ID = "/habit/assign/{habitId}";
private static final String ACHIEVEMENTS = "/achievements";
private static final String NOTIFICATIONS = "/notifications";
private static final String NOTIFICATION_ID = "/{notificationId}";
private static final String HABIT_INVITE = "/habit/invite";
private static final String INVITATION_ID = "/{invitationId}";
private static final String HABIT_ASSIGN_ID = "/{habitAssignId}";
private final JwtTool jwtTool;
private final UserService userService;
private final AuthenticationConfiguration authenticationConfiguration;
Expand Down Expand Up @@ -221,7 +220,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
CUSTOM_TO_DO_LIST + "/assign/{habitAssignId}",
TO_DO_LIST + "/{habitId}",
TO_DO_LIST + "/assign/{habitAssignId}",
USER_TO_DO_LIST + HABIT_ASSIGN_ID,
USER_TO_DO_LIST,
ECO_NEWS + COUNT,
ECO_NEWS + ECO_NEWS_ID + "/summary",
ECO_NEWS + ECO_NEWS_ID + LIKES + "/{userId}",
Expand Down Expand Up @@ -314,7 +313,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/place/{placeId}/comments",
"/place/propose",
"/place/save/favorite/",
USER_TO_DO_LIST + HABIT_ASSIGN_ID,
USER_TO_DO_LIST,
"/user/{userId}/habit",
"/user/{userId}/userFriend/{friendId}",
"/user/{userId}/declineFriend/{friendId}",
Expand Down Expand Up @@ -345,7 +344,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
EVENTS_COMMENTS + COMMENT_ID,
ECO_NEWS + COMMENTS,
HABIT_ASSIGN_WITH_HABIT_ID,
USER_TO_DO_LIST + HABIT_ASSIGN_ID,
USER_TO_DO_LIST,
HABIT_ASSIGN_WITH_HABIT_ID,
"/user/profilePicture",
"/user/deleteProfilePicture",
Expand All @@ -361,7 +360,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/habit/{habitId}/favorites",
"/favorite_place/{placeId}",
"/social-networks",
USER_TO_DO_LIST + HABIT_ASSIGN_ID,
USER_TO_DO_LIST,
EVENTS_COMMENTS + COMMENT_ID,
EVENTS + EVENT_ID,
EVENTS + EVENT_ID + ATTENDERS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public ResponseEntity<PageableAdvancedDto<HabitAssignPreviewDto>> getMyHabitsOfC
content = @Content(examples = @ExampleObject(HttpStatuses.NOT_FOUND)))
})
@ApiLocale
@GetMapping("{habitAssignId}/allUserToDoList")
@GetMapping("/{habitAssignId}/allUserToDoList")
public ResponseEntity<List<UserToDoListItemResponseDto>> getToDoAndCustomToDoLists(
@PathVariable Long habitAssignId,
@Parameter(hidden = true) @CurrentUser UserVO userVO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import greencity.annotations.CurrentUser;
import greencity.annotations.ValidLanguage;
import greencity.constant.HttpStatuses;
import greencity.dto.todolistitem.ToDoListItemResponseWithStatusDto;
import greencity.dto.todolistitem.ToDoListItemResponseDto;
import greencity.dto.user.UserVO;
import greencity.service.ToDoListItemService;
import io.swagger.v3.oas.annotations.media.ExampleObject;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class ToDoListItemController {
*
* @param locale {@link Locale} with needed language code.
* @param habitId {@link Long} with needed habit id.
* @return list of {@link ToDoListItemResponseWithStatusDto}.
* @return list of {@link ToDoListItemResponseDto}.
*/
@Operation(description = "Get all available to-do list for habit.")
@ApiResponses(value = {
Expand All @@ -49,7 +49,7 @@ public class ToDoListItemController {
})
@GetMapping("/{habitId}")
@ApiLocale
public ResponseEntity<List<ToDoListItemResponseWithStatusDto>> getAllToDoListItemsForHabit(
public ResponseEntity<List<ToDoListItemResponseDto>> getAllToDoListItemsForHabit(
@Parameter @PathVariable @Min(1) Long habitId,
@Parameter(hidden = true) @ValidLanguage Locale locale) {
return ResponseEntity.status(HttpStatus.OK)
Expand All @@ -62,7 +62,7 @@ public ResponseEntity<List<ToDoListItemResponseWithStatusDto>> getAllToDoListIte
*
* @param locale {@link Locale} with needed language code.
* @param habitAssignId {@link Long} with needed habit assign id.
* @return List of {@link ToDoListItemResponseWithStatusDto}.
* @return List of {@link ToDoListItemResponseDto}.
*/
@Operation(description = "Get all not added to-do list for habit assign.")
@ApiResponses(value = {
Expand All @@ -78,7 +78,7 @@ public ResponseEntity<List<ToDoListItemResponseWithStatusDto>> getAllToDoListIte
})
@GetMapping("/assign/{habitAssignId}")
@ApiLocale
public ResponseEntity<List<ToDoListItemResponseWithStatusDto>> getAllNotAddedToDoListItemsForHabitAssign(
public ResponseEntity<List<ToDoListItemResponseDto>> getAllNotAddedToDoListItemsForHabitAssign(
@Parameter(hidden = true) @CurrentUser UserVO user,
@Parameter @PathVariable @Min(1) Long habitAssignId,
@Parameter(hidden = true) @ValidLanguage Locale locale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/habits/assign/user-to-do-list-items")
@RequestMapping("/habits/assign/user-to-do-list-items/{habitAssignId}")
public class UserToDoListItemController {
private final UserToDoListItemService userToDoListItemService;

Expand All @@ -57,7 +57,7 @@ public class UserToDoListItemController {
@ApiResponse(responseCode = "404", description = HttpStatuses.NOT_FOUND,
content = @Content(examples = @ExampleObject(HttpStatuses.NOT_FOUND)))
})
@GetMapping("/{habitAssignId}")
@GetMapping
@ApiLocale
public ResponseEntity<List<UserToDoListItemResponseDto>> getUserToDoListItemsForHabitAssign(
@PathVariable @Min(1) Long habitAssignId,
Expand Down Expand Up @@ -89,7 +89,7 @@ public ResponseEntity<List<UserToDoListItemResponseDto>> getUserToDoListItemsFor
@ApiResponse(responseCode = "404", description = HttpStatuses.NOT_FOUND,
content = @Content(examples = @ExampleObject(HttpStatuses.NOT_FOUND)))
})
@PostMapping("/{habitAssignId}")
@PostMapping
@ApiLocale
public ResponseEntity<List<UserToDoListItemResponseDto>> saveUserToDoListItemsForHabitAssign(
@PathVariable @Min(1) Long habitAssignId,
Expand Down Expand Up @@ -122,8 +122,7 @@ public ResponseEntity<List<UserToDoListItemResponseDto>> saveUserToDoListItemsFo
@ApiResponse(responseCode = "404", description = HttpStatuses.NOT_FOUND,
content = @Content(examples = @ExampleObject(HttpStatuses.NOT_FOUND)))
})
@DeleteMapping("/{habitAssignId}")
@ApiLocale
@DeleteMapping
public ResponseEntity<Object> deleteUserToDoListItemsForHabitAssign(
@PathVariable @Min(1) Long habitAssignId,
@RequestBody List<@Min(1) Long> userToDoListItemsIds,
Expand Down Expand Up @@ -154,7 +153,7 @@ public ResponseEntity<Object> deleteUserToDoListItemsForHabitAssign(
@ApiResponse(responseCode = "404", description = HttpStatuses.NOT_FOUND,
content = @Content(examples = @ExampleObject(HttpStatuses.NOT_FOUND)))
})
@PatchMapping("/{habitAssignId}")
@PatchMapping
@ApiLocale
public ResponseEntity<List<UserToDoListItemResponseDto>> changeStatusUserToDoListItems(
@PathVariable @Min(1) Long habitAssignId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package greencity.webcontroller;

import greencity.dto.todolistitem.ToDoListItemResponseWithStatusDto;
import greencity.dto.todolistitem.ToDoListItemManagementDto;
import greencity.dto.habit.HabitDto;
import greencity.service.ToDoListItemService;
Expand Down Expand Up @@ -38,7 +37,7 @@ public String getAllToDoListItems(@RequestParam("habitId") Long id, Model model,
}

/**
* Controller for deleting {@link ToDoListItemResponseWithStatusDto} by given
* Controller for deleting {@link greencity.dto.todolistitem.ToDoListItemVO} by given
* id.
*
* @param listId list of IDs.
Expand All @@ -54,9 +53,9 @@ public ResponseEntity<List<Long>> deleteAllToDoListItem(@RequestParam("habitId")
}

/**
* Controller add all {@link ToDoListItemResponseWithStatusDto} by list of ids.
* Controller add all {@link greencity.dto.todolistitem.ToDoListItemVO} by list of ids.
*
* @param listId list of id {@link ToDoListItemResponseWithStatusDto}
* @param listId list of id {@link greencity.dto.todolistitem.ToDoListItemVO}
* @param habitId - {@link HabitDto} the id of the instance to which it will be
* added.
* @return {@link ResponseEntity}
Expand All @@ -70,10 +69,10 @@ public ResponseEntity<List<Long>> addAllToDoListItem(@RequestParam("habitId") Lo
}

/**
* Controller for c the {@link ToDoListItemResponseWithStatusDto} instance by
* Controller for c the {@link greencity.dto.todolistitem.ToDoListItemVO} instance by
* its id.
*
* @param itemId - {@link ToDoListItemResponseWithStatusDto} instance id which
* @param itemId - {@link greencity.dto.todolistitem.ToDoListItemVO} instance id which
* will be deleted.
* @param habitId - {@link HabitDto} the id of the instance from which it will
* be deleted.
Expand All @@ -88,7 +87,7 @@ public ResponseEntity<Long> deleteToDoListItem(@RequestParam("habitId") Long hab
}

/**
* Controller add {@link ToDoListItemResponseWithStatusDto} by id.
* Controller add {@link greencity.dto.todolistitem.ToDoListItemVO} by id.
*
* @param habitId - {@link HabitDto} the id of the instance to which it will be
* added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public GenericResponseDto update(
* @author Dmytro Khonko
*/
@GetMapping("/{id}")
public ResponseEntity<ToDoListItemResponseDto> getToDoListItemById(
public ResponseEntity<ToDoListItemResponseWithTranslationDto> getToDoListItemById(
@PathVariable("id") Long id) {
return ResponseEntity.status(HttpStatus.OK).body(toDoListItemService.findToDoListItemById(id));
}
Expand Down
10 changes: 4 additions & 6 deletions core/src/test/java/greencity/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import greencity.dto.location.MapBoundsDto;
import greencity.dto.todolistitem.CustomToDoListItemRequestDto;
import greencity.dto.todolistitem.CustomToDoListItemResponseDto;
import greencity.dto.todolistitem.ToDoListItemResponseWithStatusDto;
import greencity.dto.todolistitem.ToDoListItemResponseDto;
import greencity.dto.todolistitem.ToDoListItemPostDto;
import greencity.dto.todolistitem.ToDoListItemRequestDto;
import greencity.dto.specification.SpecificationNameDto;
Expand Down Expand Up @@ -206,7 +206,7 @@ public static UserManagementDto getUserManagementDto() {

public static HabitAssignPropertiesDto getHabitAssignPropertiesDto() {
return HabitAssignPropertiesDto.builder()
.defaultToDoListItems(List.of(1L, 2L))
.defaultToDoListItemIds(List.of(1L, 2L))
.duration(20)
.build();
}
Expand All @@ -221,7 +221,6 @@ public static HabitAssignCustomPropertiesDto getHabitAssignCustomPropertiesDto()
public static CustomToDoListItemResponseDto getCustomToDoListItemResponseDto() {
return CustomToDoListItemResponseDto.builder()
.id(1L)
.status(ToDoListItemStatus.ACTIVE)
.text("text")
.build();
}
Expand Down Expand Up @@ -257,11 +256,10 @@ public static UserToDoListItemResponseDto getUserToDoListItemResponseDto() {
.build();
}

public static ToDoListItemResponseWithStatusDto getToDoListItemResponseWithStatusDto() {
return ToDoListItemResponseWithStatusDto.builder()
public static ToDoListItemResponseDto getToDoListItemResponseDto() {
return ToDoListItemResponseDto.builder()
.id(1L)
.text("item text")
.status(ToDoListItemStatus.ACTIVE)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ void setup() {
.setControllerAdvice(new CustomExceptionHandler(errorAttributes, objectMapper))
.build();

dto = new CustomToDoListItemResponseDto(3L, "text",
ToDoListItemStatus.ACTIVE);
dto = new CustomToDoListItemResponseDto(3L, "text");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import greencity.converters.UserArgumentResolver;
import greencity.dto.todolistitem.ToDoListItemResponseWithStatusDto;
import greencity.dto.todolistitem.ToDoListItemResponseDto;
import greencity.dto.user.UserVO;
import greencity.exception.exceptions.NotFoundException;
import greencity.exception.handler.CustomExceptionHandler;
Expand All @@ -22,7 +22,7 @@
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.test.web.servlet.MockMvc;
import static greencity.ModelUtils.getPrincipal;
import static greencity.ModelUtils.getToDoListItemResponseWithStatusDto;
import static greencity.ModelUtils.getToDoListItemResponseDto;
import static greencity.ModelUtils.getUserVO;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -62,7 +62,7 @@ class ToDoListItemControllerTest {

private final Principal principal = getPrincipal();

private ToDoListItemResponseWithStatusDto dto;
private ToDoListItemResponseDto dto;

@BeforeEach
void setUp() {
Expand All @@ -74,13 +74,13 @@ void setUp() {
.setValidator(mockValidator)
.build();

dto = getToDoListItemResponseWithStatusDto();
dto = getToDoListItemResponseDto();
}

@Test
void getAllToDoListItemsForHabitIsOk() throws Exception {
Long habitId = 1L;
List<ToDoListItemResponseWithStatusDto> expected = List.of(dto);
List<ToDoListItemResponseDto> expected = List.of(dto);
when(toDoListItemService.findAllHabitToDoList(eq(habitId), anyString()))
.thenReturn(expected);
this.mockMvc.perform(get(toDoListItemLink + "/" + habitId)
Expand All @@ -102,7 +102,7 @@ void getAllToDoListItemsForHabitIsNotFound() throws Exception {
void findAvailableToDoListForHabitAssignIsOk() throws Exception {
Long habitAssignId = 1L;
UserVO userVO = getUserVO();
List<ToDoListItemResponseWithStatusDto> expected = List.of(dto);
List<ToDoListItemResponseDto> expected = List.of(dto);
when(userService.findByEmail(principal.getName())).thenReturn(userVO);
when(
toDoListItemService.findAvailableToDoListForHabitAssign(eq(userVO.getId()), eq(habitAssignId), anyString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface CustomToDoListItemRepo extends JpaRepository<CustomToDoListItem
* @return list of {@link CustomToDoListItem}
*/
@Query(nativeQuery = true,
value = "SELECT ctd FROM custom_to_do_list_items ctd WHERE "
value = "SELECT * FROM custom_to_do_list_items ctd WHERE "
+ "ctd.status like 'ACTIVE' "
+ "AND ctd.user_id=:userId "
+ "AND ctd.habit_id=:habitId")
Expand All @@ -32,7 +32,7 @@ List<CustomToDoListItem> findAllAvailableCustomToDoListItemsForUserId(@Param("us

@Query(nativeQuery = true,
value = "SELECT ctdl.* FROM custom_to_do_list_items ctdl "
+ "JOIN user_to_do_list ustdl ON ustdl.target_id = ctdl.id "
+ "JOIN user_to_do_list ustdl ON ustdl.to_do_list_item_id = ctdl.id "
+ "WHERE ustdl.is_custom_item = true "
+ "AND ustdl.habit_assign_id = :habitAssignId")
List<CustomToDoListItem> findAllByHabitAssignId(Long habitAssignId);
Expand Down
8 changes: 4 additions & 4 deletions dao/src/main/java/greencity/repository/ToDoListItemRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public interface ToDoListItemRepo
* @return list of id.
*/
@Query(nativeQuery = true,
value = "select to_do_list_items.id from to_do_list_items where id not in"
value = "select to_do_list_items.id from to_do_list_items where id not in"
+ " (select to_do_list_item_id from habit_to_do_list_items where habit_id = :habitId and "
+ "habit_to_do_list_items.status like 'ACTUAL');")
+ "habit_to_do_list_items.status like 'ACTIVE');")
List<Long> getAllToDoListItemsByHabitIdNotContained(@Param("habitId") Long habitId);

/**
Expand All @@ -45,7 +45,7 @@ public interface ToDoListItemRepo
* @return list of id.
*/
@Query(nativeQuery = true,
value = "select to_do_list_item_id from habit_to_do_list_items where habit_id = :habitId and "
value = "select to_do_list_item_id from habit_to_do_list_items where habit_id = :habitId and "
+ " habit_to_do_list_items.status like 'ACTIVE';")
List<Long> getAllToDoListItemIdByHabitIdIsContained(@Param("habitId") Long habitId);

Expand All @@ -69,7 +69,7 @@ public interface ToDoListItemRepo

@Query(nativeQuery = true,
value = "SELECT tdli.* FROM to_do_list_items tdli "
+ "JOIN user_to_do_list ustdl ON ustdl.target_id = tdli.id "
+ "JOIN user_to_do_list ustdl ON ustdl.to_do_list_item_id = tdli.id "
+ "WHERE ustdl.is_custom_item = false "
+ "AND ustdl.habit_assign_id = :habitAssignId")
List<ToDoListItem> findAllByHabitAssignId(Long habitAssignId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public interface UserToDoListItemRepo extends JpaRepository<UserToDoListItem, Lo
* @return List of {@link Long}
*/
@Query(nativeQuery = true,
value = "SELECT target_id FROM user_to_do_list WHERE habit_assign_id = :habitAssignId"
value = "SELECT to_do_list_item_id FROM user_to_do_list WHERE habit_assign_id = :habitAssignId"
+ " AND is_custom_item = false AND status = :status")
List<Long> getToDoListItemsByHabitAssignIdAndStatus(Long habitAssignId, String status);

Expand All @@ -71,7 +71,7 @@ public interface UserToDoListItemRepo extends JpaRepository<UserToDoListItem, Lo
@Query(nativeQuery = true, value = """
select utdl.* from user_to_do_list as utdl
where utdl.habit_assign_id = :habitAssignId
and target_id = :itemId
and to_do_list_item_id = :itemId
and is_custom_item = true""")
Optional<UserToDoListItem> getCustomToDoItemIdByHabitAssignIdAndItemId(Long habitAssignId, Long itemId);

Expand All @@ -84,7 +84,7 @@ public interface UserToDoListItemRepo extends JpaRepository<UserToDoListItem, Lo
@Query(nativeQuery = true, value = """
select utdl.* from user_to_do_list as utdl
where utdl.habit_assign_id = :habitAssignId
and target_id = :itemId
and to_do_list_item_id = :itemId
and is_custom_item = false""")
Optional<UserToDoListItem> getToDoItemIdByHabitAssignIdAndItemId(Long habitAssignId, Long itemId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<constraints nullable="false"/>
</column>
</addColumn>
<addUniqueConstraint tableName="user_to_do_list" columnNames="target_id, is_custom_item"/>
<addUniqueConstraint tableName="user_to_do_list" columnNames="target_id, is_custom_item, habit_assign_id"/>
</changeSet>
</databaseChangeLog>
Loading

0 comments on commit 015fc88

Please sign in to comment.