Skip to content

Commit

Permalink
Merge pull request #247 from MOONSHOT-Team/develop
Browse files Browse the repository at this point in the history
[Deploy] 운영서버 v1.0.2 배포
  • Loading branch information
its-sky authored Mar 11, 2024
2 parents 09c0876 + b4ed228 commit 3ea5f9f
Show file tree
Hide file tree
Showing 83 changed files with 653 additions and 681 deletions.
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 @@ -10,19 +10,19 @@

public record KeyResultCreateRequestInfoDto(
@Size(min = 1, max = 30, message = "KR은 30자 이하여야 합니다.")
String title,
String krTitle,
@NotNull(message = "KR 시작 날짜를 선택해주세요.")
LocalDate startAt,
LocalDate krStartAt,
@NotNull(message = "KR 종료 날짜를 선택해주세요.")
LocalDate expireAt,
LocalDate krExpireAt,
@NotNull(message = "KR의 순서를 입력해주세요.")
@Range(min = 0, max = 2, message = "KeyResult의 순서는 0부터 2까지로 설정할 수 있습니다.")
Integer idx,
Integer krIdx,
@NotNull(message = "KR 목표 수치를 입력해주세요.")
@Range(min = 1, max = 999999L, message = "수치는 999,999 이하여야 합니다.")
Long target,
Long krTarget,
@NotNull(message = "KR 목표 수치의 단위를 입력해주세요.")
String metric,
String krMetric,
@Valid @Size(max = 3, message = "Task 개수는 최대 3개로 제한되어 있습니다.")
List<TaskCreateRequestDto> taskList
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.moonshot.task.dto.response.TaskResponseDto;

public record KeyResultResponseDto(
Long keyResultId,
String keyResultTitle,
Integer idx,
Long krId,
String krTitle,
Integer krIdx,
List<TaskResponseDto> taskList
) {
public static List<KeyResultResponseDto> of(List<KeyResult> krList) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package org.moonshot.keyresult.service;

import static org.moonshot.keyresult.service.validator.KeyResultValidator.*;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.hasChange;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.hasDateChange;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.hasKeyResultTask;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.isKeyResultAchieved;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.validateActiveKRSizeExceeded;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.validateIndex;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.validateIndexUnderMaximum;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.validateKRPeriodWithInObjPeriod;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.validateKeyResultIndex;
import static org.moonshot.keyresult.service.validator.KeyResultValidator.validateKeyResultPeriod;
import static org.moonshot.log.service.validator.LogValidator.validateLogNum;
import static org.moonshot.response.ErrorType.NOT_FOUND_KEY_RESULT;
import static org.moonshot.response.ErrorType.NOT_FOUND_OBJECTIVE;
import static org.moonshot.response.ErrorType.REQUIRED_KEY_RESULT_VALUE;
import static org.moonshot.task.service.validator.TaskValidator.validateTaskIndex;
import static org.moonshot.user.service.validator.UserValidator.validateUserAuthorization;
import static org.moonshot.validator.IndexValidator.isIndexIncreased;
Expand All @@ -13,10 +25,8 @@
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.moonshot.common.model.Period;
import org.moonshot.exception.keyresult.KeyResultNotFoundException;
import org.moonshot.exception.keyresult.KeyResultRequiredException;
import org.moonshot.exception.log.LogNotFoundException;
import org.moonshot.exception.objective.ObjectiveNotFoundException;
import org.moonshot.exception.BadRequestException;
import org.moonshot.exception.NotFoundException;
import org.moonshot.keyresult.dto.request.KeyResultCreateRequestDto;
import org.moonshot.keyresult.dto.request.KeyResultCreateRequestInfoDto;
import org.moonshot.keyresult.dto.request.KeyResultModifyRequestDto;
Expand Down Expand Up @@ -54,15 +64,15 @@ public void createInitKRWithObjective(final Objective objective, final List<KeyR
List<KeyResultCreateRequestInfoDto> nonNullRequests = requests.stream().filter(Objects::nonNull).toList();
for (int i = 0; i < nonNullRequests.size(); i++) {
KeyResultCreateRequestInfoDto dto = nonNullRequests.get(i);
validateKeyResultIndex(i, dto.idx());
validateKRPeriodWithInObjPeriod(objective.getPeriod(), dto.startAt(), dto.expireAt());
validateKeyResultIndex(i, dto.krIdx());
validateKRPeriodWithInObjPeriod(objective.getPeriod(), dto.krStartAt(), dto.krExpireAt());

KeyResult keyResult = keyResultRepository.save(KeyResult.builder()
.title(dto.title())
.period(Period.of(dto.startAt(), dto.expireAt()))
.idx(dto.idx())
.target(dto.target())
.metric(dto.metric())
.title(dto.krTitle())
.period(Period.of(dto.krStartAt(), dto.krExpireAt()))
.idx(dto.krIdx())
.target(dto.krTarget())
.metric(dto.krMetric())
.objective(objective)
.build());
logService.createKRLog(dto, keyResult.getId());
Expand All @@ -75,7 +85,7 @@ public void createInitKRWithObjective(final Objective objective, final List<KeyR

public void createKeyResult(final KeyResultCreateRequestDto request, final Long userId) {
Objective objective = objectiveRepository.findObjectiveAndUserById(request.objectiveId())
.orElseThrow(ObjectiveNotFoundException::new);
.orElseThrow(() -> new NotFoundException(NOT_FOUND_OBJECTIVE));
validateUserAuthorization(objective.getUser().getId(), userId);

List<KeyResult> krList = keyResultRepository.findAllByObjective(objective);
Expand All @@ -92,12 +102,12 @@ public void createKeyResult(final KeyResultCreateRequestDto request, final Long
.idx(request.idx())
.target(request.target())
.metric(request.metric()).build());
logService.createKRLog(request, keyResult.getId());
logService.createKRLog(request, keyResult.getId());
}

public void deleteKeyResult(final Long keyResultId, final Long userId) {
KeyResult keyResult = keyResultRepository.findKeyResultAndObjective(keyResultId)
.orElseThrow(KeyResultNotFoundException::new);
.orElseThrow(() -> new NotFoundException(NOT_FOUND_KEY_RESULT));
validateUserAuthorization(keyResult.getObjective().getUser().getId(), userId);

logRepository.deleteAllInBatch(logRepository.findAllByKeyResult(keyResult));
Expand Down Expand Up @@ -127,7 +137,7 @@ public void deleteAllKeyResult(List<Objective> objectiveList) {

public Optional<AchieveResponseDto> modifyKeyResult(final KeyResultModifyRequestDto request, final Long userId) {
KeyResult keyResult = keyResultRepository.findKeyResultAndObjective(request.keyResultId())
.orElseThrow(KeyResultNotFoundException::new);
.orElseThrow(() -> new NotFoundException(NOT_FOUND_KEY_RESULT));
validateUserAuthorization(keyResult.getObjective().getUser().getId(), userId);

if (hasChange(request.title())) {
Expand All @@ -149,7 +159,7 @@ public Optional<AchieveResponseDto> modifyKeyResult(final KeyResultModifyRequest
}

if (request.target() == null || request.logContent() == null){
throw new KeyResultRequiredException();
throw new BadRequestException(REQUIRED_KEY_RESULT_VALUE);
}

Log updateLog = logService.createUpdateLog(request, keyResult.getId());
Expand All @@ -173,7 +183,7 @@ public Optional<AchieveResponseDto> modifyKeyResult(final KeyResultModifyRequest
@Override
public void modifyIdx(final ModifyIndexRequestDto request, final Long userId) {
KeyResult keyResult = keyResultRepository.findKeyResultAndObjective(request.id())
.orElseThrow(KeyResultNotFoundException::new);
.orElseThrow(() -> new NotFoundException(NOT_FOUND_KEY_RESULT));
validateUserAuthorization(keyResult.getObjective().getUser().getId(), userId);

Long krCount = keyResultRepository.countAllByObjectiveId(keyResult.getObjective().getId());
Expand All @@ -195,7 +205,7 @@ public void modifyIdx(final ModifyIndexRequestDto request, final Long userId) {
@Transactional(readOnly = true)
public KRDetailResponseDto getKRDetails(final Long userId, final Long keyResultId) {
KeyResult keyResult = keyResultRepository.findKeyResultAndObjective(keyResultId)
.orElseThrow(KeyResultNotFoundException::new);
.orElseThrow(() -> new NotFoundException(NOT_FOUND_KEY_RESULT));
validateUserAuthorization(keyResult.getObjective().getUser().getId(), userId);

List<Log> logList = logService.getLogList(keyResult);
Expand All @@ -220,7 +230,7 @@ private void saveTasks(final KeyResult keyResult, final List<TaskCreateRequestDt
List<TaskCreateRequestDto> nonNullTaskList = taskList.stream().filter(Objects::nonNull).toList();
for (int i = 0; i < nonNullTaskList.size(); i++) {
TaskCreateRequestDto taskDto = nonNullTaskList.get(i);
validateTaskIndex(i, taskDto.idx());
validateTaskIndex(i, taskDto.taskIdx());
taskService.saveTask(keyResult, taskDto);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.moonshot.keyresult.service.converter;

import org.moonshot.exception.global.common.MoonshotException;
import org.moonshot.exception.MoonshotException;
import org.moonshot.keyresult.model.KRState;
import org.moonshot.response.ErrorType;
import org.springframework.core.convert.converter.Converter;
Expand Down
Loading

0 comments on commit 3ea5f9f

Please sign in to comment.