-
Notifications
You must be signed in to change notification settings - Fork 1
Bug/80 커뮤니티 댓글 필드 수정 #83
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
Changes from all commits
9b15a18
cc82066
0f63ec6
b7b0d9d
5af09e9
3b6552f
ff886b7
c339f4f
4e00263
c5ea384
511c89d
5350e83
aefe88e
58b731e
139c454
1e53d65
53576ef
1412311
7e4f4c4
6f73258
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package com.somemore.auth.util; | ||
|
|
||
| import static com.somemore.auth.oauth.OAuthProvider.NAVER; | ||
|
|
||
| import com.somemore.auth.jwt.domain.EncodedToken; | ||
| import com.somemore.auth.jwt.domain.TokenType; | ||
| import com.somemore.auth.jwt.domain.UserRole; | ||
| import com.somemore.auth.jwt.generator.JwtGenerator; | ||
| import com.somemore.auth.jwt.refresh.domain.RefreshToken; | ||
| import com.somemore.auth.jwt.refresh.manager.RefreshTokenManager; | ||
| import com.somemore.center.domain.Center; | ||
| import com.somemore.center.repository.CenterJpaRepository; | ||
| import com.somemore.volunteer.domain.Volunteer; | ||
| import com.somemore.volunteer.repository.VolunteerJpaRepository; | ||
| import jakarta.annotation.PostConstruct; | ||
| import jakarta.annotation.PreDestroy; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| @Component | ||
| public class DevAccountSetUpConfig { | ||
|
|
||
| private final VolunteerJpaRepository volunteerRepository; | ||
| private final CenterJpaRepository centerRepository; | ||
| private final JwtGenerator jwtGenerator; | ||
| private final RefreshTokenManager refreshTokenManager; | ||
|
|
||
| private Volunteer volunteer; | ||
| private Center center; | ||
|
|
||
| @Value("${app.develop.mode}") | ||
| private boolean developMode; | ||
|
|
||
| @PostConstruct | ||
| public void generateAccessTokenForDev() { | ||
| if (!developMode) { | ||
| return; // 개발 모드에서만 실행 | ||
| } | ||
|
|
||
| volunteer = Volunteer.createDefault(NAVER, "bongdari"); | ||
| center = Center.create( | ||
| "봉다리 자원봉사센터", | ||
| "02-1234-5678", | ||
| "", | ||
| "봉다리 기관 테스트 계정입니다.", | ||
| "https://somemore.bongdari.com", | ||
| "bongdari", | ||
| "1234" | ||
| ); | ||
|
|
||
| volunteer = volunteerRepository.findByOauthId(volunteer.getOauthId()) | ||
| .orElseGet(() -> volunteerRepository.save(volunteer)); | ||
|
|
||
| center = centerRepository.findByName(center.getName()) | ||
| .orElseGet(() -> centerRepository.save(center)); | ||
|
|
||
| EncodedToken volunteerToken = saveRefreshTokenAndReturnAccessToken(volunteer.getId(), | ||
| UserRole.VOLUNTEER); | ||
| EncodedToken centerToken = saveRefreshTokenAndReturnAccessToken(center.getId(), | ||
| UserRole.CENTER); | ||
|
|
||
| log.info("테스트용 봉사자 AccessToken: {}", volunteerToken.value()); | ||
| log.info("테스트용 기관 AccessToken: {}", centerToken.value()); | ||
| } | ||
|
|
||
| @PreDestroy | ||
| public void cleanup() { | ||
| if (volunteer != null) { | ||
| refreshTokenManager.removeRefreshToken(volunteer.getId().toString()); | ||
| log.info("테스트용 AccessToken 제거, 봉사자 ID: {}", volunteer.getId()); | ||
| } | ||
| if (center != null) { | ||
| refreshTokenManager.removeRefreshToken(center.getId().toString()); | ||
| log.info("테스트용 AccessToken 제거, 기관 ID: {}", center.getId()); | ||
| } | ||
| } | ||
|
|
||
| private EncodedToken saveRefreshTokenAndReturnAccessToken(UUID id, UserRole role) { | ||
| EncodedToken accessToken = generateToken(id, role, TokenType.ACCESS); | ||
| RefreshToken refreshToken = generateRefreshToken(id, role, accessToken); | ||
| refreshTokenManager.save(refreshToken); | ||
| return accessToken; | ||
| } | ||
|
|
||
| private EncodedToken generateToken(UUID id, UserRole role, TokenType tokenType) { | ||
| return jwtGenerator.generateToken(id.toString(), role.name(), tokenType); | ||
| } | ||
|
|
||
| private RefreshToken generateRefreshToken(UUID id, UserRole role, EncodedToken accessToken) { | ||
| return new RefreshToken(id.toString(), accessToken, | ||
| generateToken(id, role, TokenType.REFRESH)); | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,11 @@ public List<CommunityBoardView> findByWriterId(UUID writerId) { | |
| .fetch(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean existsById(Long id) { | ||
| return communityBoardJpaRepository.existsByIdAndDeletedFalse(id); | ||
| } | ||
|
|
||
| private JPAQuery<CommunityBoardView> getCommunityBoardsQuery() { | ||
|
Collaborator
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. 이건 이번 변경사항은 아닌데 repo에 find로 맞추기로 하지 않았는지 여쭤보고 싶습니다!
Collaborator
Author
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. 안그래도 저도 다시 수정하면서 거슬렸는데
Collaborator
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. 넵 ! |
||
| QCommunityBoard communityBoard = QCommunityBoard.communityBoard; | ||
| QVolunteer volunteer = QVolunteer.volunteer; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import com.somemore.community.domain.CommunityComment; | ||
| import com.somemore.community.dto.request.CommunityCommentCreateRequestDto; | ||
| import com.somemore.community.repository.board.CommunityBoardRepository; | ||
| import com.somemore.community.repository.comment.CommunityCommentRepository; | ||
| import com.somemore.community.usecase.comment.CreateCommunityCommentUseCase; | ||
| import com.somemore.global.exception.BadRequestException; | ||
|
|
@@ -11,26 +12,38 @@ | |
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_BOARD; | ||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_COMMENT; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| @Service | ||
| public class CreateCommunityCommentService implements CreateCommunityCommentUseCase { | ||
|
|
||
| private final CommunityBoardRepository communityBoardRepository; | ||
| private final CommunityCommentRepository communityCommentRepository; | ||
|
|
||
| @Override | ||
| public Long createCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId) { | ||
| CommunityComment communityComment = requestDto.toEntity(writerId); | ||
|
|
||
| validateParentCommentExists(communityComment.getParentCommentId()); | ||
| validateCommunityBoardExists(communityComment.getCommunityBoardId()); | ||
|
|
||
| if (requestDto.parentCommentId() != null) { | ||
| validateParentCommentExists(communityComment.getParentCommentId()); | ||
| } | ||
|
|
||
| return communityCommentRepository.save(communityComment).getId(); | ||
| } | ||
|
|
||
| private void validateCommunityBoardExists(Long communityBoardId) { | ||
| if (communityBoardRepository.doesNotExistById(communityBoardId)) { | ||
| throw new BadRequestException(NOT_EXISTS_COMMUNITY_BOARD.getMessage()); | ||
| } | ||
| } | ||
|
Comment on lines
+39
to
+43
Collaborator
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. 이전에는 early return 으로 해결하시지 않으셨는지, 변경하게 된 의도도 여쭤보고 싶습니다!
Collaborator
Author
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. 아 지난번에는 validator가 아니고 리턴 값이 있었는데
Collaborator
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. 감사합니다. 이해했습니다. 저는 반환값이 없는 return을 적어두는 편이라서 여쭤보고 싶었습니다 ㅎㅎ |
||
|
|
||
| private void validateParentCommentExists(Long parentCommentId) { | ||
| if (parentCommentId != null && !communityCommentRepository.existsById(parentCommentId)) { | ||
| if (communityCommentRepository.doesNotExistById(parentCommentId)) { | ||
| throw new BadRequestException(NOT_EXISTS_COMMUNITY_COMMENT.getMessage()); | ||
| } | ||
| } | ||
|
|
||
This file was deleted.
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.
이 메서드가 필요할까요?
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.
서진님 코드에서 멋져 보여서 저도 따라해봤습니다 ㅎ
Uh oh!
There was an error while loading. Please reload this page.
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.
저는 !를 쓰지 않으려고 만든다고 생각했습니다..!
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.
넵 참고하겠습니다!