-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Add] #42 - Task, KeyResult 순서 변경 API
- Loading branch information
Showing
20 changed files
with
202 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/org/moonshot/server/domain/objective/controller/IndexController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.moonshot.server.domain.objective.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import java.security.Principal; | ||
import lombok.RequiredArgsConstructor; | ||
import org.moonshot.server.domain.objective.dto.request.ModifyIndexRequestDto; | ||
import org.moonshot.server.domain.objective.model.IndexService; | ||
import org.moonshot.server.domain.objective.service.IndexTargetProvider; | ||
import org.moonshot.server.global.auth.jwt.JwtTokenProvider; | ||
import org.moonshot.server.global.common.response.ApiResponse; | ||
import org.moonshot.server.global.common.response.SuccessType; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v1/index") | ||
public class IndexController { | ||
|
||
private final IndexTargetProvider indexTargetProvider; | ||
|
||
@PatchMapping | ||
public ApiResponse<?> modifyIdx(Principal principal, @RequestBody @Valid ModifyIndexRequestDto request) { | ||
IndexService indexService = indexTargetProvider.getIndexService(request.target()); | ||
indexService.modifyIdx(request, JwtTokenProvider.getUserIdFromPrincipal(principal)); | ||
return ApiResponse.success(SuccessType.PATCH_TARGET_INDEX_SUCCESS); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/moonshot/server/domain/objective/dto/request/ModifyIndexRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.moonshot.server.domain.objective.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import org.hibernate.validator.constraints.Range; | ||
import org.moonshot.server.domain.objective.model.IndexTarget; | ||
|
||
public record ModifyIndexRequestDto( | ||
@NotNull(message = "대상의 ID를 입력해주세요.") | ||
Long id, | ||
@NotNull(message = "대상을 지정해주세요.") | ||
IndexTarget target, | ||
@NotNull(message = "대상의 이동할 위치 값을 입력하세요.") | ||
@Range(min = 0, max = 2, message = "순서는 0부터 2까지로 설정할 수 있습니다.") | ||
Integer idx | ||
) { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/moonshot/server/domain/objective/model/IndexService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.moonshot.server.domain.objective.model; | ||
|
||
import org.moonshot.server.domain.objective.dto.request.ModifyIndexRequestDto; | ||
|
||
public interface IndexService { | ||
|
||
void modifyIdx(ModifyIndexRequestDto request, Long userId); | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/moonshot/server/domain/objective/model/IndexTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.moonshot.server.domain.objective.model; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum IndexTarget { | ||
|
||
KEY_RESULT("keyResult"), | ||
TASK("task"); | ||
|
||
private final String value; | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/moonshot/server/domain/objective/service/IndexTargetProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.moonshot.server.domain.objective.service; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.moonshot.server.domain.keyresult.service.KeyResultService; | ||
import org.moonshot.server.domain.objective.model.IndexService; | ||
import org.moonshot.server.domain.objective.model.IndexTarget; | ||
import org.moonshot.server.domain.task.service.TaskService; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class IndexTargetProvider { | ||
|
||
private static final Map<IndexTarget, IndexService> indexServiceMap = new HashMap<>(); | ||
private final KeyResultService keyResultService; | ||
private final TaskService taskService; | ||
|
||
@PostConstruct | ||
void initIndexServiceMap() { | ||
indexServiceMap.put(IndexTarget.KEY_RESULT, keyResultService); | ||
indexServiceMap.put(IndexTarget.TASK, taskService); | ||
} | ||
|
||
public IndexService getIndexService(IndexTarget indexTarget) { | ||
return indexServiceMap.get(indexTarget); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/org/moonshot/server/domain/task/exception/TaskNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.moonshot.server.domain.task.exception; | ||
|
||
import org.moonshot.server.global.common.exception.MoonshotException; | ||
import org.moonshot.server.global.common.response.ErrorType; | ||
|
||
public class TaskNotFoundException extends MoonshotException { | ||
|
||
public TaskNotFoundException() { | ||
super(ErrorType.NOT_FOUND_TASK_ERROR); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/org/moonshot/server/domain/task/repository/TaskRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
package org.moonshot.server.domain.task.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import org.moonshot.server.domain.keyresult.model.KeyResult; | ||
import org.moonshot.server.domain.task.model.Task; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface TaskRepository extends JpaRepository<Task, Long> { | ||
|
||
List<Task> findAllByKeyResult(KeyResult keyResult); | ||
List<Task> findAllByKeyResultOrderByIdx(KeyResult keyResult); | ||
@Query("select t from Task t join fetch t.keyResult kr join fetch kr.objective obj join fetch obj.user u where t.id = :taskId") | ||
Optional<Task> findTaskWithFetchJoin(@Param("taskId") Long taskId); | ||
@Modifying(clearAutomatically = true) | ||
@Query(value = "UPDATE Task t SET t.idx = t.idx + 1 WHERE t.idx >= :lBound AND t.idx < :uBound AND t.keyResult.id = :keyResultId AND t.id != :targetId") | ||
void bulkUpdateTaskIdxIncrease(@Param("lBound") int lowerBound, @Param("uBound") int upperBound, @Param("keyResultId") Long keyResultId, @Param("targetId") Long targetId); | ||
@Modifying(clearAutomatically = true) | ||
@Query(value = "UPDATE Task t SET t.idx = t.idx - 1 WHERE t.idx >= :lBound AND t.idx <= :uBound AND t.keyResult.id = :keyResultId AND t.id != :targetId") | ||
void bulkUpdateTaskIdxDecrease(@Param("lBound") int lowerBound, @Param("uBound") int upperBound, @Param("keyResultId") Long keyResultId, @Param("targetId") Long targetId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.