Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 현재 로그인한 유저 어노테이션 구현 #237

Merged
merged 8 commits into from
Mar 3, 2024
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ subprojects {
}

dependencies {
// Spring Security

//Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'

// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
1 change: 0 additions & 1 deletion moonshot-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dependencies {
// Spring Framework
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.security.Principal;
import org.moonshot.keyresult.dto.request.KeyResultCreateRequestDto;
import org.moonshot.keyresult.dto.request.KeyResultModifyRequestDto;
import org.moonshot.keyresult.dto.response.KRDetailResponseDto;
import org.moonshot.response.MoonshotResponse;
import org.moonshot.user.model.LoginUser;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -27,7 +27,7 @@ public interface KeyResultApi {
@ApiResponse(responseCode = "404", description = "존재하지 않는 Objective입니다\t\n존재하지 않는 KeyResult입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "KeyResult 데이터 생성")
public ResponseEntity<MoonshotResponse<?>> createKeyResult(Principal principal, @RequestBody @Valid KeyResultCreateRequestDto request);
public ResponseEntity<MoonshotResponse<?>> createKeyResult(@LoginUser Long userId, @RequestBody @Valid KeyResultCreateRequestDto request);

@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "KeyResult 삭제를 성공하였습니다"),
Expand All @@ -36,7 +36,7 @@ public interface KeyResultApi {
@ApiResponse(responseCode = "404", description = "존재하지 않는 KeyResult입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "KeyResult 데이터 삭제")
public ResponseEntity<?> deleteKeyResult(Principal principal, @PathVariable("keyResultId") Long keyResultId);
public ResponseEntity<?> deleteKeyResult(@LoginUser Long userId, @PathVariable("keyResultId") Long keyResultId);

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "KeyResult 수정 후 목표를 달성하였습니다\t\nKeyResult 수정을 성공하였습니다"),
Expand All @@ -46,7 +46,7 @@ public interface KeyResultApi {
@ApiResponse(responseCode = "404", description = "존재하지 않는 KeyResult입니다\t\n존재하지 않는 Log입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "KeyResult 데이터 수정")
public ResponseEntity<MoonshotResponse<?>> modifyKeyResult(Principal principal, @RequestBody @Valid KeyResultModifyRequestDto request);
public ResponseEntity<MoonshotResponse<?>> modifyKeyResult(@LoginUser Long userId, @RequestBody @Valid KeyResultModifyRequestDto request);

@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "O-KR을 생성을 성공하였습니다"),
Expand All @@ -56,5 +56,5 @@ public interface KeyResultApi {
@ApiResponse(responseCode = "404", description = "존재하지 않는 유저입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "KeyResult 상세 조회 (사이드바)")
public ResponseEntity<MoonshotResponse<KRDetailResponseDto>> getKRDetails(Principal principal, @PathVariable("keyResultId") Long keyResultId);
public ResponseEntity<MoonshotResponse<KRDetailResponseDto>> getKRDetails(@LoginUser Long userId, @PathVariable("keyResultId") Long keyResultId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import static org.moonshot.response.SuccessType.POST_KEY_RESULT_SUCCESS;

import jakarta.validation.Valid;
import java.security.Principal;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.moonshot.jwt.JwtTokenProvider;
import org.moonshot.keyresult.dto.request.KeyResultCreateRequestDto;
import org.moonshot.keyresult.dto.request.KeyResultModifyRequestDto;
import org.moonshot.keyresult.dto.response.KRDetailResponseDto;
Expand All @@ -18,6 +16,7 @@
import org.moonshot.model.Logging;
import org.moonshot.response.MoonshotResponse;
import org.moonshot.response.SuccessType;
import org.moonshot.user.model.LoginUser;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -38,22 +37,22 @@ public class KeyResultController implements KeyResultApi {

@PostMapping
@Logging(item = "KeyResult", action = "Post")
public ResponseEntity<MoonshotResponse<?>> createKeyResult(final Principal principal, @RequestBody @Valid final KeyResultCreateRequestDto request) {
keyResultService.createKeyResult(request, JwtTokenProvider.getUserIdFromPrincipal(principal));
public ResponseEntity<MoonshotResponse<?>> createKeyResult(@LoginUser Long userId, @RequestBody @Valid final KeyResultCreateRequestDto request) {
keyResultService.createKeyResult(request, userId);
return ResponseEntity.status(HttpStatus.CREATED).body(MoonshotResponse.success(POST_KEY_RESULT_SUCCESS));
}

@DeleteMapping("/{keyResultId}")
@Logging(item = "KeyResult", action = "Delete")
public ResponseEntity<?> deleteKeyResult(final Principal principal, @PathVariable("keyResultId") final Long keyResultId) {
keyResultService.deleteKeyResult(keyResultId, JwtTokenProvider.getUserIdFromPrincipal(principal));
public ResponseEntity<?> deleteKeyResult(@LoginUser Long userId, @PathVariable("keyResultId") final Long keyResultId) {
keyResultService.deleteKeyResult(keyResultId, userId);
return ResponseEntity.noContent().build();
}

@PatchMapping
@Logging(item = "KeyResult", action = "Patch")
public ResponseEntity<MoonshotResponse<?>> modifyKeyResult(final Principal principal, @RequestBody @Valid final KeyResultModifyRequestDto request) {
Optional<AchieveResponseDto> response = keyResultService.modifyKeyResult(request, JwtTokenProvider.getUserIdFromPrincipal(principal));
public ResponseEntity<MoonshotResponse<?>> modifyKeyResult(@LoginUser Long userId, @RequestBody @Valid final KeyResultModifyRequestDto request) {
Optional<AchieveResponseDto> response = keyResultService.modifyKeyResult(request, userId);
if (response.isPresent()) {
return ResponseEntity.ok(MoonshotResponse.success(PATCH_KR_ACHIEVE_SUCCESS, response));
}
Expand All @@ -62,9 +61,8 @@ public ResponseEntity<MoonshotResponse<?>> modifyKeyResult(final Principal princ

@GetMapping("/{keyResultId}")
@Logging(item = "KeyResult", action = "Get")
public ResponseEntity<MoonshotResponse<KRDetailResponseDto>> getKRDetails(final Principal principal, @PathVariable("keyResultId") final Long keyResultId) {
return ResponseEntity.ok(MoonshotResponse.success(SuccessType.GET_KR_DETAIL_SUCCESS, keyResultService.getKRDetails(
JwtTokenProvider.getUserIdFromPrincipal(principal), keyResultId)));
public ResponseEntity<MoonshotResponse<KRDetailResponseDto>> getKRDetails(@LoginUser Long userId, @PathVariable("keyResultId") final Long keyResultId) {
return ResponseEntity.ok(MoonshotResponse.success(SuccessType.GET_KR_DETAIL_SUCCESS, keyResultService.getKRDetails(userId, keyResultId)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.security.Principal;
import org.moonshot.log.dto.request.LogCreateRequestDto;
import org.moonshot.response.MoonshotResponse;
import org.moonshot.user.model.LoginUser;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;

Expand All @@ -26,7 +26,7 @@ public interface LogApi {
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "Log 생성")
public ResponseEntity<MoonshotResponse<?>> create(Principal principal,
public ResponseEntity<MoonshotResponse<?>> create(@LoginUser Long userId,
@Parameter(in = ParameterIn.DEFAULT, name = "TaskSingleCreateRequest", description = "task 추가 요청 body")
@RequestBody @Valid LogCreateRequestDto logCreateRequestDto);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package org.moonshot.log.controller;

import jakarta.validation.Valid;
import java.security.Principal;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.moonshot.jwt.JwtTokenProvider;
import org.moonshot.log.dto.request.LogCreateRequestDto;
import org.moonshot.log.dto.response.AchieveResponseDto;
import org.moonshot.log.service.LogService;
import org.moonshot.model.Logging;
import org.moonshot.response.MoonshotResponse;
import org.moonshot.response.SuccessType;
import org.moonshot.user.model.LoginUser;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -27,11 +26,11 @@ public class LogController implements LogApi {

@PostMapping
@Logging(item = "Log", action = "Post")
public ResponseEntity<MoonshotResponse<?>> create(final Principal principal, @RequestBody @Valid final LogCreateRequestDto logCreateRequestDto) {
Optional<AchieveResponseDto> response = logService.createRecordLog(JwtTokenProvider.getUserIdFromPrincipal(principal), logCreateRequestDto);
public ResponseEntity<MoonshotResponse<?>> create(@LoginUser Long userId, @RequestBody @Valid final LogCreateRequestDto logCreateRequestDto) {
Optional<AchieveResponseDto> response = logService.createRecordLog(userId, logCreateRequestDto);

if (response.isPresent()) {
return ResponseEntity.status(HttpStatus.CREATED).body(
MoonshotResponse.success(SuccessType.POST_LOG_ACHIEVE_SUCCESS, response));
return ResponseEntity.status(HttpStatus.CREATED).body(MoonshotResponse.success(SuccessType.POST_LOG_ACHIEVE_SUCCESS, response));
}
return ResponseEntity.status(HttpStatus.CREATED).body(MoonshotResponse.success(SuccessType.POST_LOG_SUCCESS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.security.Principal;
import org.moonshot.objective.dto.request.ModifyIndexRequestDto;
import org.moonshot.response.MoonshotResponse;
import org.moonshot.user.model.LoginUser;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;

Expand All @@ -24,6 +24,6 @@ public interface IndexApi {
@ApiResponse(responseCode = "404", description = "존재하지 않는 Objective입니다\t\n존재하지 않는 KeyResult입니다\t\n존재하지 않는 Task입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "Objective, KeyResult, Task Index 변경")
public ResponseEntity<MoonshotResponse<?>> modifyIdx(Principal principal, @RequestBody @Valid ModifyIndexRequestDto request);
public ResponseEntity<MoonshotResponse<?>> modifyIdx(@LoginUser Long userId, @RequestBody @Valid ModifyIndexRequestDto request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.moonshot.objective.model.IndexService;
import org.moonshot.objective.service.IndexTargetProvider;
import org.moonshot.response.MoonshotResponse;
import org.moonshot.user.model.LoginUser;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -22,9 +23,9 @@ public class IndexController implements IndexApi {
private final IndexTargetProvider indexTargetProvider;

@PatchMapping
public ResponseEntity<MoonshotResponse<?>> modifyIdx(final Principal principal, @RequestBody @Valid final ModifyIndexRequestDto request) {
public ResponseEntity<MoonshotResponse<?>> modifyIdx(@LoginUser Long userId, @RequestBody @Valid final ModifyIndexRequestDto request) {
IndexService indexService = indexTargetProvider.getIndexService(request.target());
indexService.modifyIdx(request, JwtTokenProvider.getUserIdFromPrincipal(principal));
indexService.modifyIdx(request, userId);
return ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package org.moonshot.objective.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import jakarta.validation.Valid;
import java.security.Principal;
import org.moonshot.objective.dto.request.ModifyObjectiveRequestDto;
import org.moonshot.objective.dto.request.OKRCreateRequestDto;
import org.moonshot.objective.dto.response.DashboardResponseDto;
import org.moonshot.objective.dto.response.HistoryResponseDto;
import org.moonshot.objective.model.Category;
import org.moonshot.objective.model.Criteria;
import org.moonshot.response.MoonshotResponse;
import org.moonshot.user.model.LoginUser;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -33,8 +31,7 @@ interface ObjectiveApi {
@ApiResponse(responseCode = "404", description = "존재하지 않는 유저입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "O-KR 데이터 생성")
ResponseEntity<MoonshotResponse<?>> createObjective(@Parameter(in = ParameterIn.HEADER, name = "Authorization", description = "Access Token", required = true, schema = @Schema(type = "string")) final Principal principal,
@RequestBody @Valid final OKRCreateRequestDto request);
ResponseEntity<MoonshotResponse<?>> createObjective(@LoginUser Long userId, @RequestBody @Valid final OKRCreateRequestDto request);

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "O-KR 트리 삭제를 성공하였습니다"),
Expand All @@ -43,8 +40,7 @@ ResponseEntity<MoonshotResponse<?>> createObjective(@Parameter(in = ParameterIn.
@ApiResponse(responseCode = "404", description = "존재하지 않는 Objective입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "O-KR 데이터 삭제")
ResponseEntity<MoonshotResponse<DashboardResponseDto>> deleteObjective(@Parameter(in = ParameterIn.HEADER, name = "Authorization", description = "Access Token", required = true, schema = @Schema(type = "string")) final Principal principal,
@PathVariable("objectiveId") final Long objectiveId);
ResponseEntity<MoonshotResponse<DashboardResponseDto>> deleteObjective(@LoginUser Long userId, @PathVariable("objectiveId") final Long objectiveId);

@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Objective 수정에 성공하였습니다"),
Expand All @@ -54,8 +50,7 @@ ResponseEntity<MoonshotResponse<DashboardResponseDto>> deleteObjective(@Paramete
@ApiResponse(responseCode = "404", description = "존재하지 않는 Objective입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "Objective 데이터 수정")
ResponseEntity<?> modifyObjective(@Parameter(in = ParameterIn.HEADER, name = "Authorization", description = "Access Token", required = true, schema = @Schema(type = "string")) final Principal principal,
@RequestBody final ModifyObjectiveRequestDto request);
ResponseEntity<?> modifyObjective(@LoginUser Long userId, @RequestBody final ModifyObjectiveRequestDto request);

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "O-KR 목록 조회에 성공하였습니다"),
Expand All @@ -64,16 +59,15 @@ ResponseEntity<?> modifyObjective(@Parameter(in = ParameterIn.HEADER, name = "Au
@ApiResponse(responseCode = "404", description = "존재하지 않는 Objective입니다", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class)))
})
@Operation(summary = "O-KR 목록 조회")
ResponseEntity<MoonshotResponse<DashboardResponseDto>> getObjectiveInDashboard(@Parameter(in = ParameterIn.HEADER, name = "Authorization", description = "Access Token", required = true, schema = @Schema(type = "string")) final Principal principal,
@Nullable @RequestParam("objectiveId") final Long objectiveId);
ResponseEntity<MoonshotResponse<DashboardResponseDto>> getObjectiveInDashboard(@LoginUser Long userId, @Nullable @RequestParam("objectiveId") final Long objectiveId);

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "히스토리 조회에 성공하였습니다."),
@ApiResponse(responseCode = "401", description = "인증되지 않은 사용자입니다.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class))),
@ApiResponse(responseCode = "403", description = "해당 자원에 접근 권한이 없습니다.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoonshotResponse.class))),
})
@Operation(summary = "히스토리 목록 조회")
ResponseEntity<MoonshotResponse<HistoryResponseDto>> getObjectiveHistory(final Principal principal, @RequestParam(required = false) final Integer year,
ResponseEntity<MoonshotResponse<HistoryResponseDto>> getObjectiveHistory(@LoginUser Long userId, @RequestParam(required = false) final Integer year,
@RequestParam(required = false) final Category category,
@RequestParam(required = false) final Criteria criteria);

Expand Down
Loading
Loading