Skip to content

Commit

Permalink
[Feat] #39 - OKR 생성 Principal 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
0lynny committed Jan 9, 2024
1 parent f299413 commit 2b12dd1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
import lombok.extern.slf4j.Slf4j;
import org.moonshot.server.domain.objective.dto.request.OKRCreateRequestDto;
import org.moonshot.server.domain.objective.service.ObjectiveService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/objective")
public class ObjectiveController {

private final ObjectiveService objectiveService;
private final String TEST_USER_NICKNAME = "tester";

@PostMapping
public ApiResponse<?> createObjective(@RequestBody @Valid OKRCreateRequestDto request) {
objectiveService.createObjective(request, TEST_USER_NICKNAME);
public ApiResponse<?> createObjective(Principal principal, @RequestBody @Valid OKRCreateRequestDto request) {
objectiveService.createObjective(JwtTokenProvider.getUserIdFromPrincipal(principal), request);
return ApiResponse.success(SuccessType.POST_OKR_SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class ObjectiveService {
private final ObjectiveRepository objectiveRepository;

@Transactional
public void createObjective(OKRCreateRequestDto request, String nickname) {
User findUser = userRepository.findUserByNickname(nickname)
public void createObjective(Long userId, OKRCreateRequestDto request) {
User user = userRepository.findById(userId)
.orElseThrow(UserNotFoundException::new);

if (objectiveRepository.countAllByUserAndIsClosed(findUser, false) >= ACTIVE_OBJECTIVE_NUMBER) {
if (objectiveRepository.countAllByUserAndIsClosed(user, false) >= ACTIVE_OBJECTIVE_NUMBER) {
throw new ObjectiveNumberExceededException();
}

Expand All @@ -38,7 +38,7 @@ public void createObjective(OKRCreateRequestDto request, String nickname) {
.category(request.objCategory())
.content(request.objContent())
.period(Period.of(request.objStartAt(), request.objExpireAt()))
.user(findUser).build());
.user(user).build());

keyResultService.createInitKRWithObjective(newObjective, request.krList());
}
Expand Down

0 comments on commit 2b12dd1

Please sign in to comment.