-
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.
[Feat] #42 : Index 수정이 KeyResult, Task에서 이루어지므로 해당 Service를 인터페이스화 시킨…
… 다음 각각 구현하도록 개발
- Loading branch information
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
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); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
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,7 @@ | ||
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; | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
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); | ||
} | ||
} |