From ec14131deef87ad7c2ebafce7c802e86da79e0ee Mon Sep 17 00:00:00 2001 From: youKeon Date: Mon, 2 Oct 2023 00:21:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor=20:=20Service=20=EA=B3=84=EC=B8=B5?= =?UTF-8?q?=20@Transactional=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/message/service/MessageService.java | 3 +++ .../domain/recruitment/service/ApplicationService.java | 8 +++----- .../domain/recruitment/service/RecruitmentService.java | 2 ++ .../domain/recruitment/service/RecruitmentTagService.java | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/graphy/backend/domain/message/service/MessageService.java b/backend/src/main/java/com/graphy/backend/domain/message/service/MessageService.java index 3f8e32c3..317fbd27 100644 --- a/backend/src/main/java/com/graphy/backend/domain/message/service/MessageService.java +++ b/backend/src/main/java/com/graphy/backend/domain/message/service/MessageService.java @@ -13,6 +13,7 @@ import com.graphy.backend.global.error.exception.EmptyResultException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -21,6 +22,7 @@ public class MessageService { private final MemberService memberService; private final NotificationService notificationService; + @Transactional public void addMessage(CreateMessageRequest request, Member loginUser) { Member receiver = memberService.findMemberById(request.getToMemberId()); messageRepository.save(request.toEntity(loginUser, receiver)); @@ -35,6 +37,7 @@ public void addMessage(CreateMessageRequest request, Member loginUser) { notificationService.addNotification(notificationDto, receiver.getId()); } + @Transactional(readOnly = true) public GetMessageDetailResponse findMessageById(Long messageId) { Message message = messageRepository.findById(messageId).orElseThrow( () -> new EmptyResultException(ErrorCode.MESSAGE_NOT_EXIST) diff --git a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/ApplicationService.java b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/ApplicationService.java index 5d9591aa..ab4f75cd 100644 --- a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/ApplicationService.java +++ b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/ApplicationService.java @@ -16,6 +16,7 @@ import com.graphy.backend.global.error.exception.EmptyResultException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.stream.Collectors; @@ -28,11 +29,7 @@ public class ApplicationService { private final NotificationService notificationService; private final TagService tagService; - /** - *TODO - * @Transactional 적용 - * 중복 지원 방지 로직 추가 - */ + @Transactional public void addApplication(CreateApplicationRequest request, Member loginUser) { Recruitment recruitment = recruitmentService.getRecruitmentById(request.getRecruitmentId()); @@ -56,6 +53,7 @@ public void addApplication(CreateApplicationRequest request, Member loginUser) { notificationService.addNotification(notificationDto, recruitment.getMember().getId()); } + @Transactional(readOnly = true) public GetApplicationDetailResponse findApplicationById(Long applicationId) { Application application = applicationRepository.findApplicationWithFetch(applicationId) .orElseThrow( diff --git a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentService.java b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentService.java index c571bb57..46fb81bf 100644 --- a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentService.java +++ b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentService.java @@ -88,10 +88,12 @@ public void removeRecruitment(Long recruitmentId, Member loginUser) { recruitment.delete(); } + @Transactional(readOnly = true) public Recruitment getRecruitmentById(Long id) { return recruitmentRepository.findById(id).orElseThrow(() -> new EmptyResultException(ErrorCode.RECRUITMENT_NOT_EXIST)); } + @Transactional(readOnly = true) public List findApplicationList(Long recruitmentId, Pageable pageable) { Page applicationList = applicationRepository.findAllByRecruitmentId(recruitmentId, pageable); return applicationList.stream() diff --git a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentTagService.java b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentTagService.java index 5a612fec..a6779391 100644 --- a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentTagService.java +++ b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentTagService.java @@ -4,12 +4,14 @@ import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class RecruitmentTagService { private final RecruitmentTagRepository recruitmentTagRepository; + @Transactional public void removeProjectTag(Long projectId) { recruitmentTagRepository.deleteAllByRecruitmentId(projectId); } From 9b86f06f2f2d78e0c8094643d3a225a2e0111aad Mon Sep 17 00:00:00 2001 From: youKeon Date: Mon, 2 Oct 2023 01:30:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor=20:=20@Transactional=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EB=A0=88=EB=B2=A8=EC=97=90=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/recruitment/service/ApplicationService.java | 3 ++- .../domain/recruitment/service/RecruitmentService.java | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/ApplicationService.java b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/ApplicationService.java index ab4f75cd..223b3499 100644 --- a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/ApplicationService.java +++ b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/ApplicationService.java @@ -23,6 +23,7 @@ @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class ApplicationService { private final ApplicationRepository applicationRepository; private final RecruitmentService recruitmentService; @@ -53,7 +54,7 @@ public void addApplication(CreateApplicationRequest request, Member loginUser) { notificationService.addNotification(notificationDto, recruitment.getMember().getId()); } - @Transactional(readOnly = true) + public GetApplicationDetailResponse findApplicationById(Long applicationId) { Application application = applicationRepository.findApplicationWithFetch(applicationId) .orElseThrow( diff --git a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentService.java b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentService.java index 46fb81bf..32bf614e 100644 --- a/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentService.java +++ b/backend/src/main/java/com/graphy/backend/domain/recruitment/service/RecruitmentService.java @@ -27,6 +27,7 @@ @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class RecruitmentService { private final RecruitmentRepository recruitmentRepository; private final RecruitmentTagService recruitmentTagService; @@ -43,7 +44,6 @@ public void addRecruitment(CreateRecruitmentRequest request, Member loginUser) { recruitmentRepository.save(recruitment); } - @Transactional(readOnly = true) public GetRecruitmentDetailResponse findRecruitmentById(Long recruitmentId) { Recruitment recruitment = recruitmentRepository.findById(recruitmentId).orElseThrow( () -> new EmptyResultException(ErrorCode.RECRUITMENT_NOT_EXIST) @@ -51,7 +51,6 @@ public GetRecruitmentDetailResponse findRecruitmentById(Long recruitmentId) { return GetRecruitmentDetailResponse.from(recruitment); } - @Transactional(readOnly = true) public List findRecruitmentList(List positions, List tags, String keyword, @@ -88,12 +87,10 @@ public void removeRecruitment(Long recruitmentId, Member loginUser) { recruitment.delete(); } - @Transactional(readOnly = true) public Recruitment getRecruitmentById(Long id) { return recruitmentRepository.findById(id).orElseThrow(() -> new EmptyResultException(ErrorCode.RECRUITMENT_NOT_EXIST)); } - @Transactional(readOnly = true) public List findApplicationList(Long recruitmentId, Pageable pageable) { Page applicationList = applicationRepository.findAllByRecruitmentId(recruitmentId, pageable); return applicationList.stream()