Skip to content

Commit

Permalink
Merge pull request #83 from KUSITMS-29th-TEAM-D/feature/#74/final-ref…
Browse files Browse the repository at this point in the history
…actoring

[refactor] : @transactional 어노테이션 클래스단으로 변경
  • Loading branch information
bbbang105 authored May 23, 2024
2 parents de36707 + 1ca4525 commit e5796a5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,6 +10,7 @@
import reactor.core.publisher.Mono;

@Service
@Transactional
@RequiredArgsConstructor
public class ClovaServiceImpl implements ClovaService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.UUID;

@Service
@Transactional
@RequiredArgsConstructor
public class DefinePersonaServiceImpl implements DefinePersonaService {
private final JwtUtil jwtUtil;
Expand All @@ -28,7 +29,6 @@ public class DefinePersonaServiceImpl implements DefinePersonaService {

// 정의하기 페르소나 결과를 도출하는 메서드 (로그인 유저)
@Override
@Transactional
public DefinePersonaDto.DefinePersonaResponse createDefinePersona(String authorizationHeader, DefinePersonaDto.DefinePersonaRequest definePersonaRequest) {
List<String> definePersonaKeywords = new ArrayList<>();
String stepOneKeyword = judgeStepOneType(definePersonaRequest.getStageOneKeywords(), definePersonaKeywords);
Expand All @@ -45,7 +45,6 @@ public DefinePersonaDto.DefinePersonaResponse createDefinePersona(String authori

// 정의하기 페르소나 결과를 도출하는 메서드 (비로그인 유저)
@Override
@Transactional
public DefinePersonaDto.DefinePersonaResponse createDefinePersonaForSharing(DefinePersonaDto.DefinePersonaRequest definePersonaRequest) {
List<String> definePersonaKeywords = new ArrayList<>();
String stepOneKeyword = judgeStepOneType(definePersonaRequest.getStageOneKeywords(), definePersonaKeywords);
Expand All @@ -62,7 +61,6 @@ public DefinePersonaDto.DefinePersonaResponse createDefinePersonaForSharing(Defi

// 정의하기 페르소나 결과를 반환하는 메서드 (로그인 유저)
@Override
@Transactional
public DefinePersonaDto.DefinePersonaResponse getDefinePersona(String authorizationHeader) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

Expand All @@ -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로 검색
Expand Down Expand Up @@ -163,7 +160,6 @@ private List<String> judgeMoreCountKeywords (List<String> stepKeywords, List<Str
}

// 정의하기 페르소나를 저장하는 메서드 (로그인 유저)
@Transactional
protected DefinePersona saveDefinePersona(String authorizationHeader, String definePersonaName, String definePersonaCode, List<String> definePersonaKeywords) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

Expand All @@ -186,7 +182,6 @@ protected DefinePersona saveDefinePersona(String authorizationHeader, String def
}

// 정의하기 페르소나를 저장하는 메서드 (비로그인 유저)
@Transactional
protected DefinePersona saveDefinePersonaForSharing(String definePersonaName, String definePersonaCode, List<String> definePersonaKeywords) {

DefinePersona definePersona = DefinePersona.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Objects;

@Service
@Transactional
@RequiredArgsConstructor
public class DesignPersonaServiceImpl implements DesignPersonaService {
private final StringUtil stringUtil;
Expand All @@ -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);
Expand All @@ -50,7 +50,6 @@ public DesignPersonaDto.DesignPersonaResponse createDesignPersona(String authori

// 설계하기 페르소나 결과를 조회하는 메서드
@Override
@Transactional
public DesignPersonaDto.DesignPersonaDetailResponse getDesignPersona(String authorizationHeader) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

Expand Down Expand Up @@ -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);

Expand All @@ -97,7 +95,6 @@ protected DesignPersona saveDesignPersona(String authorizationHeader, String des
}

// 설계하기 페르소나 분야를 저장하는 메서드
@Transactional
protected void saveDesignPersonaFields(DesignPersona designPersona, List<String> fields) {
for (String field : fields) {
DesignPersonaField designPersonaField = DesignPersonaField.builder()
Expand All @@ -109,7 +106,6 @@ protected void saveDesignPersonaFields(DesignPersona designPersona, List<String>
}

// 설계하기 페르소나 특징을 저장하는 메서드
@Transactional
protected void saveDesignPersonaDistinctions(DesignPersona designPersona, List<String> distinctions) {
for (String distinction : distinctions) {
DesignPersonaDistinction designPersonaDistinction = DesignPersonaDistinction.builder()
Expand All @@ -121,7 +117,6 @@ protected void saveDesignPersonaDistinctions(DesignPersona designPersona, List<S
}

// 설계하기 페르소나 강점을 저장하는 메서드
@Transactional
protected void saveDesignPersonaAbilities(DesignPersona designPersona, List<String> abilities) {
for (String ability : abilities) {
DesignPersonaAbility designPersonaAbility = DesignPersonaAbility.builder()
Expand All @@ -133,7 +128,6 @@ protected void saveDesignPersonaAbilities(DesignPersona designPersona, List<Stri
}

// 설계하기 페르소나 플랫폼을 저장하는 메서드
@Transactional
protected void saveDesignPersonaPlatforms(DesignPersona designPersona, List<String> platforms) {
for (String platform : platforms) {
DesignPersonaPlatform designPersonaPlatform = DesignPersonaPlatform.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.stream.Collectors;

@Service
@Transactional
@RequiredArgsConstructor
public class DiscoverPersonaServiceImpl implements DiscoverPersonaService {
private final JwtUtil jwtUtil;
Expand All @@ -35,7 +36,6 @@ public class DiscoverPersonaServiceImpl implements DiscoverPersonaService {

// 질문을 새롭게 생성하며 채팅을 시작하는 메서드
@Override
@Transactional
public DiscoverPersonaDto.QuestionResponse getNewQuestion(String authorizationHeader, String category) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -126,7 +124,6 @@ public DiscoverPersonaDto.ChattingResponse getChattings(String authorizationHead

// 답변 요약 내역을 반환하는 메서드
@Override
@Transactional
public DiscoverPersonaDto.SummaryResponse getSummaries(String authorizationHeader) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

Expand All @@ -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);

Expand All @@ -158,7 +154,6 @@ public void restartChatting(String authorizationHeader, DiscoverPersonaDto.reset

// 카테고리별 대화 완료 여부를 반환하는 메서드
@Override
@Transactional
public DiscoverPersonaDto.CheckCompleteResponse checkComplete(String authorizationHeader) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

Expand All @@ -172,7 +167,6 @@ public DiscoverPersonaDto.CheckCompleteResponse checkComplete(String authorizati

// 모든 카테고리에서 상위 6개의 키워드를 반환하는 메서드
@Override
@Transactional
public DiscoverPersonaDto.KeywordResponse getAllKeywords(String authorizationHeader) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

Expand All @@ -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<DiscoverPersonaKeyword> keywords = collectCategoryKeywords(user, category);
Expand All @@ -201,7 +194,6 @@ public DiscoverPersonaDto.KeywordResponse getCategoryKeywords(String authorizati
}

// 모든 카테고리의 키워드를 반환하는 메서드
@Transactional
protected List<DiscoverPersonaKeyword> collectKeywords(User user) {
List<DiscoverPersonaKeyword> allKeywords = new ArrayList<>();

Expand All @@ -217,7 +209,6 @@ protected List<DiscoverPersonaKeyword> collectKeywords(User user) {
}

// 특정 카테고리의 키워드를 반환하는 메서드
@Transactional
protected List<DiscoverPersonaKeyword> collectCategoryKeywords(User user, String category) {
DiscoverPersona persona = getDiscoverPersona(user, category);
if (persona != null && persona.getIsComplete()) {
Expand All @@ -228,13 +219,11 @@ protected List<DiscoverPersonaKeyword> collectCategoryKeywords(User user, String
}

// 카테고리별 돌아보기 페르소나를 반환하는 메서드
@Transactional
protected DiscoverPersona getDiscoverPersona(User user, String category) {
return discoverPersonaRepository.findFirstByUserAndCategoryOrderByCreatedDateDesc(user, category);
}

// 페르소나에 해당하는 키워드를 찾아 반환하는 메서드
@Transactional
protected List<DiscoverPersonaKeyword> getKeywordsFromPersona(DiscoverPersona persona) {
return discoverPersonaKeywordRepository.findAllByDiscoverPersona(persona);
}
Expand Down Expand Up @@ -280,7 +269,6 @@ private List<String> createStageQuestions(String category, List<DiscoverPersonaC
}

// 답변 요약 목록을 반환하는 메서드
@Transactional
protected List<String> createSummaries(DiscoverPersona discoverPersona) {
List<DiscoverPersonaChatting> chattings = discoverPersonaChattingRepository.findAllByDiscoverPersonaOrderByCreatedDateAsc(discoverPersona);
List<String> summaries = new ArrayList<>();
Expand All @@ -292,7 +280,6 @@ protected List<String> createSummaries(DiscoverPersona discoverPersona) {
}

// 페르소나 키워드를 생성하고 저장하는 메서드
@Transactional
protected void createPersonaKeywords(DiscoverPersona discoverPersona) {
List<String> summaries = discoverPersonaChattingRepository.findSummariesByDiscoverPersona(discoverPersona);
String clovaRequestText = stringUtil.joinWithNewLine(summaries);
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,5 +198,4 @@ private List<Branding> findAllBrandingByUsersKeywordsAndInterests(String authori
private User findUserByUUID(UUID userId) {
return userRepository.findByUserId(userId).orElseThrow(() -> new UserException(NOT_FOUND_USER));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.UUID;

@Service
@Transactional
@RequiredArgsConstructor
public class TokenServiceImpl implements TokenService {
@Value("${jwt.access-token.expiration-time}")
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

@Slf4j
@Service
@Transactional
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
@Value("${jwt.access-token.expiration-time}")
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -161,8 +157,8 @@ public void logout(HttpServletResponse response) {
response.addCookie(cookie);
}

// 유저의 신청 프로그램을 반환하는 메서드
@Override
@Transactional
public List<UserDto.userHomeResponse> findUserApplyPrograms(String authorizationHeader, String type, String sort) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
List<ProgramParticipants> programParticipants = programParticipantsRepository.findAllByUser(user);
Expand Down Expand Up @@ -195,7 +191,6 @@ public List<UserDto.userHomeResponse> findUserApplyPrograms(String authorization
}

// 사용자의 관심 분야를 저장하는 메서드
@Transactional
protected void saveUserInterests(User user, List<String> interestList) {
if (interestList != null && !interestList.isEmpty()) {
for (String interestName : interestList) {
Expand All @@ -213,7 +208,6 @@ protected void saveUserInterests(User user, List<String> interestList) {
}

// 사용자의 키워드를 저장하는 메서드
@Transactional
protected void saveUserKeywords(User user, List<String> keywordList) {
if (keywordList != null && !keywordList.isEmpty()) {
for (String keywordName : keywordList) {
Expand Down

0 comments on commit e5796a5

Please sign in to comment.