Skip to content

Commit

Permalink
[Feat] #42 : Index 수정이 KeyResult, Task에서 이루어지므로 해당 Service를 인터페이스화 시킨…
Browse files Browse the repository at this point in the history
… 다음 각각 구현하도록 개발
  • Loading branch information
its-sky committed Jan 9, 2024
1 parent c7b2a12 commit f384894
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
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);
}

}
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);
}
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;

}
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);
}
}

0 comments on commit f384894

Please sign in to comment.