-
Notifications
You must be signed in to change notification settings - Fork 1
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] #39 - Log 생성 API 구현 #43
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2b12dd1
[Feat] #39 - OKR 생성 Principal 추가
0lynny a2f133c
[Feat] #39 - LogCreateRequestDto 추가
0lynny 3114349
[Feat] #39 - LogRepository 추가
0lynny 2a5faac
[Feat] #39 - Log 생성 API 구현
0lynny 302ae6f
[Feat] #39 - Log 생성 SuccessType 추가
0lynny 358bc0a
[Feat] #39 - KR 수정 시 Log 생성 기능 구현
0lynny 849aae7
[Feat] #39 - Target 범위에 따른 Entity 수정
0lynny a3f84fa
[Chore] #39 - 타입 변경으로 인한 관련 코드 수정
0lynny 71881c8
[Chore] #39 - 타입 변경에 따른 코드 수정
0lynny 4299cf8
[Feat] #39 - Log prevNum Default 설정
0lynny 680318c
[Chore] #39 - LogCreateRequestDto 변경
0lynny dce1bbe
[Feat] #39 - 메소드 분리
0lynny a575330
[Fix] #39 - merge 후 confilct 해결
0lynny dd338d4
[Feat] #28 - KR 삭제 시 Log 삭제 기능 구현
0lynny 9895da1
[Feat] #39 - Log 진척정도 직전값 기능 구현
0lynny 438dbce
[Feat] #39 - 예외처리 추가
0lynny 9647200
[Del] #39 - 사용하지 않는 import문 삭제
0lynny e0a0cc8
Merge branch 'develop' into feature/#39
0lynny 8cbfa38
Merge branch 'feature/#39' of https://github.com/MOONSHOT-Team/MOONSH…
0lynny af316b8
[Feat] #39 - 수치 Limit 관련 어노테이션 추가
0lynny 0296c9f
[Feat] #39 - ValidLimitValue 어노테이션 적용
0lynny 02e1f96
[Fix] #39 - 오탈자 수정
0lynny 91bf6df
[Fix] #39 - 코드리뷰 반영
0lynny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/org/moonshot/server/domain/log/controller/LogController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.moonshot.server.domain.log.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.moonshot.server.domain.log.dto.request.LogCreateRequestDto; | ||
import org.moonshot.server.domain.log.service.LogService; | ||
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; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v1/log") | ||
public class LogController { | ||
|
||
private final LogService logService; | ||
|
||
@PostMapping | ||
public ApiResponse<?> create(Principal principal, @RequestBody LogCreateRequestDto logCreateRequestDto) { | ||
logService.createRecordLog(JwtTokenProvider.getUserIdFromPrincipal(principal), logCreateRequestDto); | ||
return ApiResponse.success(SuccessType.POST_LOG_SUCCESS); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/moonshot/server/domain/log/dto/request/LogCreateRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.moonshot.server.domain.log.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import org.moonshot.server.global.common.model.validator.ValidLimitValue; | ||
|
||
public record LogCreateRequestDto( | ||
Long keyResultId, | ||
|
||
@NotNull(message = "Log의 수치를 입력해주세요.") | ||
@ValidLimitValue | ||
long logNum, | ||
|
||
@NotNull(message = "Log의 체크인 본문을 입력해주세요.") | ||
@Size(min = 1, max = 100, message = "본문은 100자 이하여야 합니다.") | ||
String logContent | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/moonshot/server/domain/log/repository/LogRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.moonshot.server.domain.log.repository; | ||
|
||
import org.moonshot.server.domain.keyresult.model.KeyResult; | ||
import org.moonshot.server.domain.log.model.Log; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface LogRepository extends JpaRepository<Log, Long> { | ||
|
||
List<Log> findAllByKeyResult(KeyResult keyResult); | ||
|
||
@Query("select l FROM Log l JOIN FETCH l.keyResult k WHERE l.keyResult.id = :keyResultId ORDER BY l.id DESC LIMIT 1") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 칭찬 스티커 0.5개 붙여드리겠습니다~ |
||
List<Log> findLatestLogByKeyResultId(@Param("keyResultId") Long keyResultId); | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/org/moonshot/server/domain/log/service/LogService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package org.moonshot.server.domain.log.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.moonshot.server.domain.keyresult.dto.request.KeyResultCreateRequestDto; | ||
import org.moonshot.server.domain.keyresult.dto.request.KeyResultCreateRequestInfoDto; | ||
import org.moonshot.server.domain.keyresult.dto.request.KeyResultModifyRequestDto; | ||
import org.moonshot.server.domain.keyresult.exception.KeyResultNotFoundException; | ||
import org.moonshot.server.domain.keyresult.model.KeyResult; | ||
import org.moonshot.server.domain.keyresult.repository.KeyResultRepository; | ||
import org.moonshot.server.domain.log.dto.request.LogCreateRequestDto; | ||
import org.moonshot.server.domain.log.model.Log; | ||
import org.moonshot.server.domain.log.model.LogState; | ||
import org.moonshot.server.domain.log.repository.LogRepository; | ||
import org.moonshot.server.domain.user.exception.UserNotFoundException; | ||
import org.moonshot.server.domain.user.model.User; | ||
import org.moonshot.server.domain.user.repository.UserRepository; | ||
import org.moonshot.server.global.auth.exception.AccessDeniedException; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class LogService { | ||
|
||
private final UserRepository userRepository; | ||
private final KeyResultRepository keyResultRepository; | ||
private final LogRepository logRepository; | ||
|
||
@Transactional | ||
public void createRecordLog(Long userId, LogCreateRequestDto request) { | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(UserNotFoundException::new); | ||
KeyResult keyResult = keyResultRepository.findById(request.keyResultId()) | ||
.orElseThrow(KeyResultNotFoundException::new); | ||
if (!keyResult.getObjective().getUser().getId().equals(userId)) { | ||
throw new AccessDeniedException(); | ||
} | ||
List<Log> prevLog = logRepository.findLatestLogByKeyResultId(request.keyResultId()); | ||
long prevNum = -1; | ||
if (!prevLog.isEmpty()) { | ||
prevNum = prevLog.get(0).getCurrNum(); | ||
} | ||
logRepository.save(Log.builder() | ||
.date(LocalDateTime.now()) | ||
.state(LogState.RECORD) | ||
.currNum(request.logNum()) | ||
.prevNum(prevNum) | ||
.content(request.logContent()) | ||
.keyResult(keyResult) | ||
.build()); | ||
} | ||
|
||
@Transactional | ||
public void createUpdateLog(KeyResultModifyRequestDto request, Long keyResultId) { | ||
KeyResult keyResult = keyResultRepository.findById(keyResultId) | ||
.orElseThrow(KeyResultNotFoundException::new); | ||
|
||
logRepository.save(Log.builder() | ||
.date(LocalDateTime.now()) | ||
.state(LogState.UPDATE) | ||
.currNum(request.target()) | ||
.prevNum(keyResult.getTarget()) | ||
.content(request.logContent()) | ||
.keyResult(keyResult) | ||
.build()); | ||
} | ||
|
||
@Transactional | ||
public void createKRLog(Object request, Long keyResultId) { | ||
KeyResult keyResult = keyResultRepository.findById(keyResultId) | ||
.orElseThrow(KeyResultNotFoundException::new); | ||
|
||
if (request instanceof KeyResultCreateRequestInfoDto) { | ||
KeyResultCreateRequestInfoDto dto = (KeyResultCreateRequestInfoDto) request; | ||
logRepository.save(Log.builder() | ||
.date(LocalDateTime.now()) | ||
.state(LogState.CREATE) | ||
.currNum(dto.target()) | ||
.content("") | ||
.keyResult(keyResult) | ||
.build()); | ||
} | ||
if (request instanceof KeyResultCreateRequestDto) { | ||
KeyResultCreateRequestDto dto = (KeyResultCreateRequestDto) request; | ||
logRepository.save(Log.builder() | ||
.date(LocalDateTime.now()) | ||
.state(LogState.CREATE) | ||
.currNum(dto.target()) | ||
.content("") | ||
.keyResult(keyResult) | ||
.build()); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p5; |
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p2;
이거 남기고 if(dto.taskList() !=null) 내 로직 지워야할것 같습니다!