-
Notifications
You must be signed in to change notification settings - Fork 1
[SCRUM-364] Refactor : 편의점 응답 및 기타 수정 #113
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
Merged
chaen-ing
merged 9 commits into
develop
from
refactor/SCRUM-364-convenience-reseponse-time
Aug 19, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
efd4c81
[SCRUM-364] Refactor: 타임유틸 이동 및 편의점 리스트에서 시간 추가
chaen-ing 562e9f5
[SCRUM-364] Refactor: 로컬에서만 기본 회원가입 가능하도록 변경
chaen-ing cc99649
[SCRUM-364] Refactor: 커뮤니티 게시글 락 낙관적으로 변경
chaen-ing 003ccb9
[SCRUM-364] Refactor: 커뮤니티 게시글 댓글 락 낙관적으로 변경
chaen-ing 2aac5c4
[SCRUM-364] Rename: 이름 변경
chaen-ing 5370340
[SCRUM-364] Rename: 변수명 수정
chaen-ing 49df9f8
[SCRUM-364] Refactor: 커뮤니티 게시글 좋아요 기능을 별도의 실행기 클래스로 분리
chaen-ing cea7adf
[SCRUM-364] Refactor: 커뮤니티 댓글 좋아요 기능을 별도의 실행기 클래스로 분리
chaen-ing 1487bcb
[SCRUM-364] Refactor: 커뮤니티 서비스에서 재시도 횟수 초과 오류 코드 추가 및 예외 처리 개선
chaen-ing 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/kkinikong/be/auth/controller/SignupController.java
This file contains hidden or 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,39 @@ | ||
| package com.kkinikong.be.auth.controller; | ||
|
|
||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| 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 io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import com.kkinikong.be.auth.dto.request.BasicLoginRequest; | ||
| import com.kkinikong.be.auth.service.AuthService; | ||
| import com.kkinikong.be.global.response.ApiResponse; | ||
|
|
||
| @Profile({"local"}) | ||
| @RequestMapping("/api/v1/auth") | ||
| @Tag(name = "Auth 로컬", description = "인증 및 회원 관련 API") | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class SignupController { | ||
|
|
||
| private final AuthService authService; | ||
|
|
||
| @Operation( | ||
| summary = "기본 회원가입", | ||
| description = "(관리자) 이메일과 비밀번호로 회원가입합니다. '@'를 포함한 이메일과 비밀번호를 입력해주세요.") | ||
| @PostMapping("/signup") | ||
| public ResponseEntity<ApiResponse<Object>> signUp( | ||
| @Valid @RequestBody BasicLoginRequest basicLoginRequest) { | ||
|
|
||
| authService.signup(basicLoginRequest); | ||
| return ResponseEntity.status(HttpStatus.OK).body(ApiResponse.EMPTY_RESPONSE); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/kkinikong/be/community/dto/response/CommunityPostListResponse.java
This file contains hidden or 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 hidden or 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
12 changes: 0 additions & 12 deletions
12
src/main/java/com/kkinikong/be/community/repository/comment/CommentRepository.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,28 +1,16 @@ | ||
| package com.kkinikong.be.community.repository.comment; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.data.jpa.repository.EntityGraph; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Lock; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import io.lettuce.core.dynamic.annotation.Param; | ||
| import jakarta.persistence.LockModeType; | ||
|
|
||
| import com.kkinikong.be.community.domain.Comment; | ||
|
|
||
| @Repository | ||
| public interface CommentRepository extends JpaRepository<Comment, Long>, CommentRepositoryCustom { | ||
|
|
||
| @EntityGraph(attributePaths = {"commentLikeList", "commentLikeList.user"}) | ||
| List<Comment> findAllByCommunityPostId(Long postId); | ||
|
|
||
| @Lock(LockModeType.PESSIMISTIC_WRITE) | ||
| @Query("SELECT c FROM Comment c WHERE c.id = :commentId") | ||
| Optional<Comment> findByIdForUpdate(@Param("commentId") Long commentId); | ||
|
|
||
| void deleteAllByCommunityPostId(Long postId); | ||
| } |
This file contains hidden or 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
105 changes: 105 additions & 0 deletions
105
src/main/java/com/kkinikong/be/community/service/CommunityLikeToggleExecutor.java
This file contains hidden or 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,105 @@ | ||
| package com.kkinikong.be.community.service; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Propagation; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import com.kkinikong.be.community.domain.Comment; | ||
| import com.kkinikong.be.community.domain.CommentLike; | ||
| import com.kkinikong.be.community.domain.CommunityPost; | ||
| import com.kkinikong.be.community.domain.CommunityPostLike; | ||
| import com.kkinikong.be.community.dto.response.LikeToggleResponse; | ||
| import com.kkinikong.be.community.exception.CommunityException; | ||
| import com.kkinikong.be.community.exception.errorcode.CommunityErrorCode; | ||
| import com.kkinikong.be.community.repository.CommentLikeRepository; | ||
| import com.kkinikong.be.community.repository.CommunityPostLikeRepository; | ||
| import com.kkinikong.be.community.repository.comment.CommentRepository; | ||
| import com.kkinikong.be.community.repository.communityPost.CommunityPostRepository; | ||
| import com.kkinikong.be.notification.event.payload.CommentLikeEvent; | ||
| import com.kkinikong.be.notification.event.payload.CommunityLikeEvent; | ||
| import com.kkinikong.be.user.domain.User; | ||
| import com.kkinikong.be.user.exception.UserException; | ||
| import com.kkinikong.be.user.exception.errorcode.UserErrorCode; | ||
| import com.kkinikong.be.user.repository.UserRepository; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class CommunityLikeToggleExecutor { | ||
| private final CommunityPostRepository communityPostRepository; | ||
| private final CommunityPostLikeRepository communityPostLikeRepository; | ||
| private final UserRepository userRepository; | ||
| private final CommentRepository commentRepository; | ||
| private final CommentLikeRepository commentLikeRepository; | ||
|
|
||
| private final ApplicationEventPublisher eventPublisher; | ||
|
|
||
| @Transactional(propagation = Propagation.REQUIRES_NEW) | ||
| public LikeToggleResponse togglePostLikeOnce(Long postId, Long userId) { | ||
|
|
||
| CommunityPost post = | ||
| communityPostRepository | ||
| .findById(postId) | ||
| .orElseThrow(() -> new CommunityException(CommunityErrorCode.COMMUNITY_POST_NOT_FOUND)); | ||
| User user = getUserOrThrow(userId); | ||
|
|
||
| Optional<CommunityPostLike> existing = | ||
| communityPostLikeRepository.findByCommunityPostIdAndUserId(postId, userId); | ||
|
|
||
| boolean isLiked; | ||
| if (existing.isPresent()) { | ||
| communityPostLikeRepository.delete(existing.get()); | ||
| post.decrementLikeCount(); | ||
| isLiked = false; | ||
| } else { | ||
| communityPostLikeRepository.save( | ||
| CommunityPostLike.builder().communityPost(post).user(user).build()); | ||
| post.incrementLikeCount(); | ||
| isLiked = true; | ||
| if (!post.getUser().getId().equals(userId)) { | ||
| eventPublisher.publishEvent(new CommunityLikeEvent(post.getUser(), user, post)); | ||
| } | ||
| } | ||
chaen-ing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| communityPostRepository.saveAndFlush(post); // 버전 충돌 감지 | ||
| return LikeToggleResponse.from(isLiked, post.getLikeCount()); | ||
| } | ||
|
|
||
| @Transactional(propagation = Propagation.REQUIRES_NEW) | ||
| public LikeToggleResponse toggleCommentLikeOnce(Long commentId, Long userId) { | ||
| Comment comment = | ||
| commentRepository | ||
| .findById(commentId) | ||
| .orElseThrow(() -> new CommunityException(CommunityErrorCode.COMMENT_NOT_FOUND)); | ||
|
|
||
| User user = getUserOrThrow(userId); | ||
|
|
||
| Optional<CommentLike> commentLike = | ||
| commentLikeRepository.findByCommentIdAndUserId(commentId, userId); | ||
|
|
||
| boolean isLiked; | ||
| if (commentLike.isPresent()) { | ||
| commentLikeRepository.delete(commentLike.get()); | ||
| comment.decrementLikeCount(); | ||
| isLiked = false; | ||
| } else { | ||
| commentLikeRepository.save(CommentLike.builder().comment(comment).user(user).build()); | ||
| comment.incrementLikeCount(); | ||
| isLiked = true; | ||
| if (!comment.getUser().getId().equals(userId)) { | ||
| eventPublisher.publishEvent(new CommentLikeEvent(comment.getUser(), user, comment)); | ||
| } | ||
| } | ||
chaen-ing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| commentRepository.saveAndFlush(comment); | ||
| return LikeToggleResponse.from(isLiked, comment.getLikeCount()); | ||
| } | ||
|
|
||
| private User getUserOrThrow(Long userId) { | ||
| return userRepository | ||
| .findById(userId) | ||
| .orElseThrow(() -> new UserException(UserErrorCode.USER_NOT_FOUND)); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.