Skip to content

Commit

Permalink
[Add] #40 : OKR 생성 관련 API 유저 인가 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
its-sky committed Jan 9, 2024
1 parent e1cb1f2 commit c8351e9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import static org.moonshot.server.global.common.response.SuccessType.*;

import jakarta.validation.Valid;
import java.security.Principal;
import lombok.RequiredArgsConstructor;
import org.moonshot.server.domain.keyresult.dto.request.KeyResultCreateRequestDto;
import org.moonshot.server.domain.keyresult.dto.request.KeyResultModifyRequestDto;
import org.moonshot.server.domain.keyresult.service.KeyResultService;
import org.moonshot.server.global.auth.jwt.JwtTokenProvider;
import org.moonshot.server.global.common.response.ApiResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
Expand All @@ -24,20 +26,20 @@ public class KeyResultController {
private final KeyResultService keyResultService;

@PostMapping
public ApiResponse<?> createKeyResult(@RequestBody @Valid KeyResultCreateRequestDto request) {
keyResultService.createKeyResult(request);
public ApiResponse<?> createKeyResult(Principal principal, @RequestBody @Valid KeyResultCreateRequestDto request) {
keyResultService.createKeyResult(request, JwtTokenProvider.getUserIdFromPrincipal(principal));
return ApiResponse.success(POST_KEY_RESULT_SUCCESS);
}

@DeleteMapping("/{keyResultId}")
public ApiResponse<?> deleteKeyResult(@PathVariable("keyResultId") Long keyResultId) {
keyResultService.deleteKeyResult(keyResultId);
public ApiResponse<?> deleteKeyResult(Principal principal, @PathVariable("keyResultId") Long keyResultId) {
keyResultService.deleteKeyResult(keyResultId, JwtTokenProvider.getUserIdFromPrincipal(principal));
return ApiResponse.success(DELETE_KEY_RESULT_SUCCESS);
}

@PatchMapping
public ApiResponse<?> modifyKeyResult(@RequestBody @Valid KeyResultModifyRequestDto request) {
keyResultService.modifyKeyResult(request);
public ApiResponse<?> modifyKeyResult(Principal principal, @RequestBody @Valid KeyResultModifyRequestDto request) {
keyResultService.modifyKeyResult(request, JwtTokenProvider.getUserIdFromPrincipal(principal));
return ApiResponse.success(PATCH_KEY_RESULT_SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import static org.moonshot.server.global.common.response.SuccessType.*;

import jakarta.validation.Valid;
import java.security.Principal;
import lombok.RequiredArgsConstructor;
import org.moonshot.server.domain.task.dto.request.TaskSingleCreateRequestDto;
import org.moonshot.server.domain.task.service.TaskService;
import org.moonshot.server.global.auth.jwt.JwtTokenProvider;
import org.moonshot.server.global.common.response.ApiResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -20,8 +22,8 @@ public class TaskController {
private final TaskService taskService;

@PostMapping
public ApiResponse<?> createTask(@RequestBody @Valid TaskSingleCreateRequestDto request) {
taskService.createTask(request);
public ApiResponse<?> createTask(Principal principal, @RequestBody @Valid TaskSingleCreateRequestDto request) {
taskService.createTask(request, JwtTokenProvider.getUserIdFromPrincipal(principal));
return ApiResponse.success(POST_TASK_SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public enum ErrorType {
INVALID_AUTH_ERROR(HttpStatus.UNAUTHORIZED, "인증되지 않은 사용자입니다."),
EXPIRED_TOKEN_ERROR(HttpStatus.UNAUTHORIZED, "만료된 TOKEN입니다."),

/**
* 403 FORBIDDEN
*/
FORBIDDEN_ERROR(HttpStatus.FORBIDDEN, "해당 자원에 접근 권한이 없습니다."),

/**
* 404 NOT FOUND
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ logging:
config: classpath:logback-local.xml
level:
org.springframework.security: DEBUG
org.hibernate.type: TRACE

springdoc:
packages-to-scan: org.moonshot.server
Expand Down

0 comments on commit c8351e9

Please sign in to comment.