Skip to content

Commit

Permalink
refactor : @transactional readOnly 최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
dltjdgh0428 committed Mar 27, 2024
1 parent 82d5df3 commit ddae92d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import java.util.List;

@Service
@Transactional
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class BookServiceImpl implements BookService {

private final BookRepository bookRepository;

//등록 혹은 수정
@Transactional
public void 책생성(ReviewRespDto reviewRespDto) {
BookRespDto bookRespDto = reviewRespDto.getBookRespDto();
Book book = bookRepository.mFindBookIsbn(bookRespDto.getIsbn());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.book_everywhere.common.entity;

import com.book_everywhere.common.config.BaseTimeConfig;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@


@RequiredArgsConstructor
@Transactional
@Transactional(readOnly = true)
@Service
public class LikesServiceImpl implements LikesService {

private final LikesRepository likesRepository;
private final UserRepository userRepository;

@Override
@Transactional
public void 좋아요(Long socialId, Long review_id) {
User user = userRepository.findBySocialId(socialId).orElseThrow();
likesRepository.mLike(user.getId(),review_id);
}

@Override
@Transactional
public void 좋아요취소(Long socialId, Long review_id) {
User user = userRepository.findBySocialId(socialId).orElseThrow();
likesRepository.mUnLike(user.getId(), review_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.List;

@RequiredArgsConstructor
@Transactional
@Transactional(readOnly = true)
@Service
public class PinServiceImpl implements PinService {
private final PinRepository pinRepository;
Expand All @@ -31,7 +31,7 @@ public class PinServiceImpl implements PinService {
.map(PinDto::toDto)
.toList();
}

@Transactional
public void 핀생성(ReviewRespDto reviewRespDto) {
PinRespDto pinRespDto = reviewRespDto.getPinRespDto();
Pin pined = pinRepository.mFindPinByAddress(reviewRespDto.getPinRespDto().getAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional
@Transactional(readOnly = true)
@Service
public class VisitServiceImpl implements VisitService{
private final UserRepository userRepository;
private final PinRepository pinRepository;
private final VisitRepository visitRepository;


@Transactional
public void 독후감쓰기전방문등록또는수정(ReviewRespDto reviewRespDto) {
//review가 올라가기전 visit에 등록되어있는지 확인후 없다면 visit등록
User user = userRepository.findBySocialId(reviewRespDto.getSocialId()).orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.List;

@RequiredArgsConstructor
@Transactional
@Transactional(readOnly = true)
@Service
public class ReviewServiceImpl implements ReviewService {
private final ReviewRepository reviewRepository;
Expand All @@ -35,7 +35,7 @@ public class ReviewServiceImpl implements ReviewService {

//사용자 검증에 메소드
//등록

@Transactional
public Long 독후감생성(ReviewRespDto reviewRespDto) {
User user = userRepository.findBySocialId(reviewRespDto.getSocialId()).orElseThrow(
() -> new EntityNotFoundException(CustomErrorCode.USER_NOT_FOUND));
Expand Down Expand Up @@ -133,7 +133,7 @@ public class ReviewServiceImpl implements ReviewService {
}).toList();
}


@Transactional
public void 독후감수정(Long reviewId, ReviewRespDto reviewRespDto) {
Review review = reviewRepository.findById(reviewId)
.orElseThrow(() -> new EntityNotFoundException(CustomErrorCode.REVIEW_NOT_FOUND));
Expand All @@ -147,7 +147,7 @@ public class ReviewServiceImpl implements ReviewService {
reviewRepository.save(review);
}


@Transactional
public void 유저독후감개수검증후책삭제(String isbn) {
Book book = bookRepository.mFindBookIsbn(isbn);
if (book == null) {
Expand All @@ -158,7 +158,7 @@ public class ReviewServiceImpl implements ReviewService {
bookRepository.delete(book);
}
}

@Transactional
public void 독후감개수검증삭제(String prevBookTitle) {
Book book = bookRepository.mFindBookTitle(prevBookTitle);
if (book == null) {
Expand All @@ -169,7 +169,7 @@ public class ReviewServiceImpl implements ReviewService {
bookRepository.delete(book);
}
}

@Transactional
public void 독후감개수검증후핀삭제(String address, Long socialId) {
Pin pin = pinRepository.mFindPinByAddress(address);
if (pin == null) {
Expand All @@ -183,8 +183,7 @@ public class ReviewServiceImpl implements ReviewService {
pinRepository.delete(pin);
}
}


@Transactional
public void 독후감삭제(Long reviewId) {
Review review = reviewRepository.findById(reviewId).orElseThrow(() -> new EntityNotFoundException(CustomErrorCode.REVIEW_NOT_FOUND));
reviewRepository.delete(review);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.List;

@RequiredArgsConstructor
@Transactional
@Transactional(readOnly = true)
@Service
public class TaggedServiceImpl implements TaggedService {
private final TagRepository tagRepository;
Expand All @@ -28,6 +28,7 @@ public class TaggedServiceImpl implements TaggedService {
private final UserRepository userRepository;

@Override
@Transactional
public void 태그등록(ReviewRespDto reviewRespDto) {
List<String> tags = reviewRespDto.getTags();
User user = userRepository.findBySocialId(reviewRespDto.getSocialId()).orElseThrow(() -> new EntityNotFoundException(CustomErrorCode.USER_NOT_FOUND));
Expand Down Expand Up @@ -61,6 +62,7 @@ public class TaggedServiceImpl implements TaggedService {
}

@Override
@Transactional
public void 태그삭제(String address, Long socialId) {
Pin pin = pinRepository.mFindPinByAddress(address);
if (pin == null) {
Expand Down

0 comments on commit ddae92d

Please sign in to comment.