From 1ca4525ca7310eb8b4afb223a9d5b0dcc98bc3a9 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Thu, 23 May 2024 21:08:01 +0900 Subject: [PATCH] =?UTF-8?q?#74=20[refactor]=20:=20@Transactional=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=8B=A8=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clova/application/ClovaServiceImpl.java | 2 ++ .../application/DefinePersonaServiceImpl.java | 7 +------ .../application/DesignPersonaServiceImpl.java | 8 +------- .../application/DiscoverPersonaServiceImpl.java | 16 +--------------- .../program/application/ProgramServiceImpl.java | 3 +-- .../token/application/TokenServiceImpl.java | 2 +- .../domain/user/application/UserServiceImpl.java | 10 ++-------- 7 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/main/java/kusitms/jangkku/domain/clova/application/ClovaServiceImpl.java b/src/main/java/kusitms/jangkku/domain/clova/application/ClovaServiceImpl.java index 808dc04..529b19a 100644 --- a/src/main/java/kusitms/jangkku/domain/clova/application/ClovaServiceImpl.java +++ b/src/main/java/kusitms/jangkku/domain/clova/application/ClovaServiceImpl.java @@ -1,5 +1,6 @@ package kusitms.jangkku.domain.clova.application; +import jakarta.transaction.Transactional; import kusitms.jangkku.domain.clova.dto.ClovaDto; import kusitms.jangkku.domain.clova.dto.Message; import lombok.RequiredArgsConstructor; @@ -9,6 +10,7 @@ import reactor.core.publisher.Mono; @Service +@Transactional @RequiredArgsConstructor public class ClovaServiceImpl implements ClovaService { diff --git a/src/main/java/kusitms/jangkku/domain/persona/application/DefinePersonaServiceImpl.java b/src/main/java/kusitms/jangkku/domain/persona/application/DefinePersonaServiceImpl.java index ffd819b..779f3f5 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/application/DefinePersonaServiceImpl.java +++ b/src/main/java/kusitms/jangkku/domain/persona/application/DefinePersonaServiceImpl.java @@ -20,6 +20,7 @@ import java.util.UUID; @Service +@Transactional @RequiredArgsConstructor public class DefinePersonaServiceImpl implements DefinePersonaService { private final JwtUtil jwtUtil; @@ -28,7 +29,6 @@ public class DefinePersonaServiceImpl implements DefinePersonaService { // 정의하기 페르소나 결과를 도출하는 메서드 (로그인 유저) @Override - @Transactional public DefinePersonaDto.DefinePersonaResponse createDefinePersona(String authorizationHeader, DefinePersonaDto.DefinePersonaRequest definePersonaRequest) { List definePersonaKeywords = new ArrayList<>(); String stepOneKeyword = judgeStepOneType(definePersonaRequest.getStageOneKeywords(), definePersonaKeywords); @@ -45,7 +45,6 @@ public DefinePersonaDto.DefinePersonaResponse createDefinePersona(String authori // 정의하기 페르소나 결과를 도출하는 메서드 (비로그인 유저) @Override - @Transactional public DefinePersonaDto.DefinePersonaResponse createDefinePersonaForSharing(DefinePersonaDto.DefinePersonaRequest definePersonaRequest) { List definePersonaKeywords = new ArrayList<>(); String stepOneKeyword = judgeStepOneType(definePersonaRequest.getStageOneKeywords(), definePersonaKeywords); @@ -62,7 +61,6 @@ public DefinePersonaDto.DefinePersonaResponse createDefinePersonaForSharing(Defi // 정의하기 페르소나 결과를 반환하는 메서드 (로그인 유저) @Override - @Transactional public DefinePersonaDto.DefinePersonaResponse getDefinePersona(String authorizationHeader) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -82,7 +80,6 @@ public DefinePersonaDto.DefinePersonaResponse getDefinePersona(String authorizat // 정의하기 페르소나 결과를 반환하는 메서드 (비로그인 유저) @Override - @Transactional public DefinePersonaDto.DefinePersonaResponse getDefinePersonaForSharing(String definePersonaId) { DefinePersona definePersona = definePersonaRepository.findByDefinePersonaId(UUID.fromString(definePersonaId)); // 고유 id로 검색 @@ -163,7 +160,6 @@ private List judgeMoreCountKeywords (List stepKeywords, List definePersonaKeywords) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -186,7 +182,6 @@ protected DefinePersona saveDefinePersona(String authorizationHeader, String def } // 정의하기 페르소나를 저장하는 메서드 (비로그인 유저) - @Transactional protected DefinePersona saveDefinePersonaForSharing(String definePersonaName, String definePersonaCode, List definePersonaKeywords) { DefinePersona definePersona = DefinePersona.builder() diff --git a/src/main/java/kusitms/jangkku/domain/persona/application/DesignPersonaServiceImpl.java b/src/main/java/kusitms/jangkku/domain/persona/application/DesignPersonaServiceImpl.java index 6b06ddc..034c776 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/application/DesignPersonaServiceImpl.java +++ b/src/main/java/kusitms/jangkku/domain/persona/application/DesignPersonaServiceImpl.java @@ -18,6 +18,7 @@ import java.util.Objects; @Service +@Transactional @RequiredArgsConstructor public class DesignPersonaServiceImpl implements DesignPersonaService { private final StringUtil stringUtil; @@ -32,7 +33,6 @@ public class DesignPersonaServiceImpl implements DesignPersonaService { // 설계하기 페르소나 결과를 도출하는 메서드 @Override - @Transactional public DesignPersonaDto.DesignPersonaResponse createDesignPersona(String authorizationHeader, DesignPersonaDto.DesignPersonaRequest designPersonaRequest) { String message = createClovaRequestMessage(designPersonaRequest); String designPersonaDefinition = clovaService.createDesignPersona(message); @@ -50,7 +50,6 @@ public DesignPersonaDto.DesignPersonaResponse createDesignPersona(String authori // 설계하기 페르소나 결과를 조회하는 메서드 @Override - @Transactional public DesignPersonaDto.DesignPersonaDetailResponse getDesignPersona(String authorizationHeader) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -82,7 +81,6 @@ private String createClovaRequestMessage(DesignPersonaDto.DesignPersonaRequest d } // 설계하기 페르소나를 저장하는 메서드 - @Transactional protected DesignPersona saveDesignPersona(String authorizationHeader, String designPersonaDefinition, String career) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -97,7 +95,6 @@ protected DesignPersona saveDesignPersona(String authorizationHeader, String des } // 설계하기 페르소나 분야를 저장하는 메서드 - @Transactional protected void saveDesignPersonaFields(DesignPersona designPersona, List fields) { for (String field : fields) { DesignPersonaField designPersonaField = DesignPersonaField.builder() @@ -109,7 +106,6 @@ protected void saveDesignPersonaFields(DesignPersona designPersona, List } // 설계하기 페르소나 특징을 저장하는 메서드 - @Transactional protected void saveDesignPersonaDistinctions(DesignPersona designPersona, List distinctions) { for (String distinction : distinctions) { DesignPersonaDistinction designPersonaDistinction = DesignPersonaDistinction.builder() @@ -121,7 +117,6 @@ protected void saveDesignPersonaDistinctions(DesignPersona designPersona, List abilities) { for (String ability : abilities) { DesignPersonaAbility designPersonaAbility = DesignPersonaAbility.builder() @@ -133,7 +128,6 @@ protected void saveDesignPersonaAbilities(DesignPersona designPersona, List platforms) { for (String platform : platforms) { DesignPersonaPlatform designPersonaPlatform = DesignPersonaPlatform.builder() diff --git a/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaServiceImpl.java b/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaServiceImpl.java index 661cce8..b9fff28 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaServiceImpl.java +++ b/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaServiceImpl.java @@ -24,6 +24,7 @@ import java.util.stream.Collectors; @Service +@Transactional @RequiredArgsConstructor public class DiscoverPersonaServiceImpl implements DiscoverPersonaService { private final JwtUtil jwtUtil; @@ -35,7 +36,6 @@ public class DiscoverPersonaServiceImpl implements DiscoverPersonaService { // 질문을 새롭게 생성하며 채팅을 시작하는 메서드 @Override - @Transactional public DiscoverPersonaDto.QuestionResponse getNewQuestion(String authorizationHeader, String category) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -72,7 +72,6 @@ public DiscoverPersonaDto.QuestionResponse getNewQuestion(String authorizationHe // 공감과 요약을 생성해 응답하는 메서드 @Override - @Transactional public DiscoverPersonaDto.AnswerResponse getReactionAndSummary(String authorizationHeader, DiscoverPersonaDto.AnswerRequest answerRequest) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -105,7 +104,6 @@ public DiscoverPersonaDto.AnswerResponse getReactionAndSummary(String authorizat // 카테고리별 채팅 내역을 반환하는 메서드 @Override - @Transactional public DiscoverPersonaDto.ChattingResponse getChattings(String authorizationHeader, String category) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -126,7 +124,6 @@ public DiscoverPersonaDto.ChattingResponse getChattings(String authorizationHead // 답변 요약 내역을 반환하는 메서드 @Override - @Transactional public DiscoverPersonaDto.SummaryResponse getSummaries(String authorizationHeader) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -145,7 +142,6 @@ public DiscoverPersonaDto.SummaryResponse getSummaries(String authorizationHeade // 채팅 다시하기를 위해 테이블을 새롭게 생성하는 메서드 @Override - @Transactional public void restartChatting(String authorizationHeader, DiscoverPersonaDto.resetChattingRequest resetChattingRequest) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -158,7 +154,6 @@ public void restartChatting(String authorizationHeader, DiscoverPersonaDto.reset // 카테고리별 대화 완료 여부를 반환하는 메서드 @Override - @Transactional public DiscoverPersonaDto.CheckCompleteResponse checkComplete(String authorizationHeader) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -172,7 +167,6 @@ public DiscoverPersonaDto.CheckCompleteResponse checkComplete(String authorizati // 모든 카테고리에서 상위 6개의 키워드를 반환하는 메서드 @Override - @Transactional public DiscoverPersonaDto.KeywordResponse getAllKeywords(String authorizationHeader) { User user = jwtUtil.getUserFromHeader(authorizationHeader); @@ -189,7 +183,6 @@ public DiscoverPersonaDto.KeywordResponse getAllKeywords(String authorizationHea // 특정 카테고리에서 상위 6개의 키워드를 반환하는 메서드 @Override - @Transactional public DiscoverPersonaDto.KeywordResponse getCategoryKeywords(String authorizationHeader, String category) { User user = jwtUtil.getUserFromHeader(authorizationHeader); List keywords = collectCategoryKeywords(user, category); @@ -201,7 +194,6 @@ public DiscoverPersonaDto.KeywordResponse getCategoryKeywords(String authorizati } // 모든 카테고리의 키워드를 반환하는 메서드 - @Transactional protected List collectKeywords(User user) { List allKeywords = new ArrayList<>(); @@ -217,7 +209,6 @@ protected List collectKeywords(User user) { } // 특정 카테고리의 키워드를 반환하는 메서드 - @Transactional protected List collectCategoryKeywords(User user, String category) { DiscoverPersona persona = getDiscoverPersona(user, category); if (persona != null && persona.getIsComplete()) { @@ -228,13 +219,11 @@ protected List collectCategoryKeywords(User user, String } // 카테고리별 돌아보기 페르소나를 반환하는 메서드 - @Transactional protected DiscoverPersona getDiscoverPersona(User user, String category) { return discoverPersonaRepository.findFirstByUserAndCategoryOrderByCreatedDateDesc(user, category); } // 페르소나에 해당하는 키워드를 찾아 반환하는 메서드 - @Transactional protected List getKeywordsFromPersona(DiscoverPersona persona) { return discoverPersonaKeywordRepository.findAllByDiscoverPersona(persona); } @@ -280,7 +269,6 @@ private List createStageQuestions(String category, List createSummaries(DiscoverPersona discoverPersona) { List chattings = discoverPersonaChattingRepository.findAllByDiscoverPersonaOrderByCreatedDateAsc(discoverPersona); List summaries = new ArrayList<>(); @@ -292,7 +280,6 @@ protected List createSummaries(DiscoverPersona discoverPersona) { } // 페르소나 키워드를 생성하고 저장하는 메서드 - @Transactional protected void createPersonaKeywords(DiscoverPersona discoverPersona) { List summaries = discoverPersonaChattingRepository.findSummariesByDiscoverPersona(discoverPersona); String clovaRequestText = stringUtil.joinWithNewLine(summaries); @@ -305,7 +292,6 @@ protected void createPersonaKeywords(DiscoverPersona discoverPersona) { } // 새로 뽑아낸 키워드를 업데이트 or 저장하는 메서드 - @Transactional protected void processKeyword(DiscoverPersona discoverPersona, String name) { DiscoverPersonaKeyword personaKeyword = discoverPersonaKeywordRepository.findByDiscoverPersonaAndName(discoverPersona, name); if (!Objects.isNull(personaKeyword)) { diff --git a/src/main/java/kusitms/jangkku/domain/program/application/ProgramServiceImpl.java b/src/main/java/kusitms/jangkku/domain/program/application/ProgramServiceImpl.java index 35aa1e1..1109ff8 100644 --- a/src/main/java/kusitms/jangkku/domain/program/application/ProgramServiceImpl.java +++ b/src/main/java/kusitms/jangkku/domain/program/application/ProgramServiceImpl.java @@ -29,8 +29,8 @@ import static kusitms.jangkku.domain.user.exception.UserErrorResult.NOT_FOUND_USER; @Service -@RequiredArgsConstructor @Transactional +@RequiredArgsConstructor public class ProgramServiceImpl implements ProgramService { private final JwtUtil jwtUtil; @@ -198,5 +198,4 @@ private List findAllBrandingByUsersKeywordsAndInterests(String authori private User findUserByUUID(UUID userId) { return userRepository.findByUserId(userId).orElseThrow(() -> new UserException(NOT_FOUND_USER)); } - } diff --git a/src/main/java/kusitms/jangkku/domain/token/application/TokenServiceImpl.java b/src/main/java/kusitms/jangkku/domain/token/application/TokenServiceImpl.java index fbd29bc..787805f 100644 --- a/src/main/java/kusitms/jangkku/domain/token/application/TokenServiceImpl.java +++ b/src/main/java/kusitms/jangkku/domain/token/application/TokenServiceImpl.java @@ -20,6 +20,7 @@ import java.util.UUID; @Service +@Transactional @RequiredArgsConstructor public class TokenServiceImpl implements TokenService { @Value("${jwt.access-token.expiration-time}") @@ -34,7 +35,6 @@ public class TokenServiceImpl implements TokenService { // 리프레쉬 토큰을 재발행하는 메서드 @Override - @Transactional public TokenDto.TokenResponse reissueAccessToken(HttpServletRequest request, HttpServletResponse response) { Cookie cookie = cookieUtil.getCookie(request); String refreshToken = cookie.getValue(); diff --git a/src/main/java/kusitms/jangkku/domain/user/application/UserServiceImpl.java b/src/main/java/kusitms/jangkku/domain/user/application/UserServiceImpl.java index 0602d02..cbb5fce 100644 --- a/src/main/java/kusitms/jangkku/domain/user/application/UserServiceImpl.java +++ b/src/main/java/kusitms/jangkku/domain/user/application/UserServiceImpl.java @@ -38,6 +38,7 @@ @Slf4j @Service +@Transactional @RequiredArgsConstructor public class UserServiceImpl implements UserService { @Value("${jwt.access-token.expiration-time}") @@ -60,7 +61,6 @@ public class UserServiceImpl implements UserService { // 기본 정보까지 추가하여 신규 유저를 등록하는 메서드 @Override - @Transactional public UserDto.UserRegisterResponse registerUser(HttpServletResponse response, String authorizationHeader, UserDto.UserRegisterRequest userRegisterRequest) { // 토큰을 이용하여 사용자 정보 추출 String registerToken = jwtUtil.getTokenFromHeader(authorizationHeader); @@ -107,14 +107,12 @@ public UserDto.UserRegisterResponse registerUser(HttpServletResponse response, S // 닉네임 중복 여부를 판단하는 메서드 @Override - @Transactional public boolean isDuplicate(String nickname) { return userOnboardingInfoRepository.findByNickname(nickname) != null; } // 유저 프로필 사진을 업로드하는 메서드 @Override - @Transactional public void uploadProfileImg(String authorizationHeader, MultipartFile file) { User user = jwtUtil.getUserFromHeader(authorizationHeader); UserOnboardingInfo userOnboardingInfo = userOnboardingInfoRepository.findByUser(user); @@ -133,7 +131,6 @@ public void uploadProfileImg(String authorizationHeader, MultipartFile file) { // 유저 정보를 반환하는 메서드 @Override - @Transactional public UserDto.UserInfosResponse getUserInfos(String authorizationHeader) { User user = jwtUtil.getUserFromHeader(authorizationHeader); UserOnboardingInfo userOnboardingInfo = userOnboardingInfoRepository.findByUser(user); @@ -143,7 +140,6 @@ public UserDto.UserInfosResponse getUserInfos(String authorizationHeader) { // 유저 정보를 수정하는 메서드 @Override - @Transactional public UserDto.UserInfosResponse editUserInfos(String authorizationHeader, UserDto.EditUserInfosRequest editUserInfosRequest) { User user = jwtUtil.getUserFromHeader(authorizationHeader); UserOnboardingInfo userOnboardingInfo = userOnboardingInfoRepository.findByUser(user); @@ -161,8 +157,8 @@ public void logout(HttpServletResponse response) { response.addCookie(cookie); } + // 유저의 신청 프로그램을 반환하는 메서드 @Override - @Transactional public List findUserApplyPrograms(String authorizationHeader, String type, String sort) { User user = jwtUtil.getUserFromHeader(authorizationHeader); List programParticipants = programParticipantsRepository.findAllByUser(user); @@ -195,7 +191,6 @@ public List findUserApplyPrograms(String authorization } // 사용자의 관심 분야를 저장하는 메서드 - @Transactional protected void saveUserInterests(User user, List interestList) { if (interestList != null && !interestList.isEmpty()) { for (String interestName : interestList) { @@ -213,7 +208,6 @@ protected void saveUserInterests(User user, List interestList) { } // 사용자의 키워드를 저장하는 메서드 - @Transactional protected void saveUserKeywords(User user, List keywordList) { if (keywordList != null && !keywordList.isEmpty()) { for (String keywordName : keywordList) {