Skip to content

Commit

Permalink
Merge pull request #87 from Leets-Official/refactor-#86
Browse files Browse the repository at this point in the history
#86 Refactor: Transactional 추가
  • Loading branch information
KoungQ authored Aug 6, 2024
2 parents 206742f + 6873acf commit b5b152e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package leets.weeth.domain.penalty.service;

import jakarta.transaction.Transactional;
import leets.weeth.domain.penalty.dto.RequestPenalty;
import leets.weeth.domain.penalty.dto.ResponsePenalty;
import leets.weeth.domain.penalty.entity.Penalty;
Expand All @@ -12,6 +11,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Comparator;
import java.util.List;
Expand All @@ -22,7 +22,7 @@
public class PenaltyService {
private final PenaltyRepository penaltyRepository;
private final UserRepository userRepository;
@Transactional
@Transactional(rollbackFor = Exception.class)
public void assignPenalty(RequestPenalty requestPenalty){
User userToBan = userRepository.findById(requestPenalty.getUserId()).orElseThrow(UserNotFoundException::new);
Penalty penalty = penaltyRepository.save(Penalty.toEntity(requestPenalty, userToBan));
Expand All @@ -38,6 +38,7 @@ public List<ResponsePenalty> getMyPenalties(Long userId){
.toList();
}

@Transactional(rollbackFor = Exception.class)
public void removePenalty(Long penaltyId) {
Penalty penaltyToRemove = penaltyRepository.findById(penaltyId)
.orElseThrow(PenaltyNotFoundException::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package leets.weeth.domain.post.service;

import jakarta.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;
import leets.weeth.domain.post.dto.RequestCommentDTO;
import leets.weeth.domain.post.entity.Comment;
import leets.weeth.domain.post.entity.Post;
Expand All @@ -24,7 +24,7 @@ public class CommentService {
private final UserRepository userRepository;
private final CommentRepository commentRepository;

@Transactional
@Transactional(rollbackFor = Exception.class)
public void createComment(Long userId, Long postId, RequestCommentDTO requestCommentDTO) {
User user = userRepository.findById(userId)
.orElseThrow(UserNotFoundException::new);
Expand All @@ -45,7 +45,7 @@ public void createComment(Long userId, Long postId, RequestCommentDTO requestCom
parent.addChild(comment);
}

@Transactional
@Transactional(rollbackFor = Exception.class)
public void updateComment(Long userId, Long postId, Long commentId, RequestCommentDTO requestCommentDTO) throws UserMismatchException {
User currentUser = userRepository.findById(userId)
.orElseThrow(UserNotFoundException::new);
Expand All @@ -61,7 +61,7 @@ public void updateComment(Long userId, Long postId, Long commentId, RequestComme
commentRepository.save(commentToEdit);
}

@Transactional
@Transactional(rollbackFor = Exception.class)
public void deleteComment(Long userId, Long commentId) throws UserMismatchException {
User currentUser = userRepository.findById(userId)
.orElseThrow(UserNotFoundException::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package leets.weeth.domain.post.service;

import jakarta.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;
import leets.weeth.domain.file.service.FileService;
import leets.weeth.domain.post.dto.RequestPostDTO;
import leets.weeth.domain.post.dto.ResponsePostDTO;
Expand Down Expand Up @@ -57,7 +57,7 @@ public List<ResponsePostDTO> myPosts(Long userId){
.toList();
}

@Transactional
@Transactional(rollbackFor = Exception.class)
public void create(Long userId, RequestPostDTO requestPostDTO, List<MultipartFile> files, Long postId) throws InvalidAccessException {
// 사용자가 존재하지 않는 경우
User user = userRepository.findById(userId)
Expand Down Expand Up @@ -90,7 +90,7 @@ public void create(Long userId, RequestPostDTO requestPostDTO, List<MultipartFil
postRepository.save(newPost);
}

@Transactional
@Transactional(rollbackFor = Exception.class)
public void delete(Long postId, Long userId) throws InvalidAccessException {
// 대상 게시물이 존재하지 않는 경우
Post deleted = postRepository.findById(postId)
Expand Down

0 comments on commit b5b152e

Please sign in to comment.