Skip to content

Commit

Permalink
Merge pull request #250 from techeer-sv/BE/#249
Browse files Browse the repository at this point in the history
BE/#249 Service 계층 @transactional 설정
  • Loading branch information
youKeon committed Oct 2, 2023
2 parents 2e1e8b8 + 9b86f06 commit cb922ab
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@
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;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ApplicationService {
private final ApplicationRepository applicationRepository;
private final RecruitmentService recruitmentService;
private final NotificationService notificationService;
private final TagService tagService;

/**
*TODO
* @Transactional 적용
* 중복 지원 방지 로직 추가
*/
@Transactional
public void addApplication(CreateApplicationRequest request, Member loginUser) {
Recruitment recruitment = recruitmentService.getRecruitmentById(request.getRecruitmentId());

Expand All @@ -56,6 +54,7 @@ public void addApplication(CreateApplicationRequest request, Member loginUser) {
notificationService.addNotification(notificationDto, recruitment.getMember().getId());
}


public GetApplicationDetailResponse findApplicationById(Long applicationId) {
Application application = applicationRepository.findApplicationWithFetch(applicationId)
.orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class RecruitmentService {
private final RecruitmentRepository recruitmentRepository;
private final RecruitmentTagService recruitmentTagService;
Expand All @@ -43,15 +44,13 @@ 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)
);
return GetRecruitmentDetailResponse.from(recruitment);
}

@Transactional(readOnly = true)
public List<GetRecruitmentResponse> findRecruitmentList(List<Position> positions,
List<String> tags,
String keyword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit cb922ab

Please sign in to comment.