Skip to content

Commit

Permalink
Merge pull request #120 from KUSITMS-MOAMOA/refactor/#119
Browse files Browse the repository at this point in the history
  • Loading branch information
daeun084 authored Nov 28, 2024
2 parents d55a14a + 332e778 commit 86f67b2
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public void parseAndSaveAbilities(Map<String, String> keywordList, Analysis anal
validAbilityCount(abilityCount);
}

private void validAbilityCount(int abilityCount) {
if (abilityCount < 1 || abilityCount > 3)
throw new AbilityException(AbilityErrorStatus.INVALID_ABILITY_KEYWORD);
}

@Transactional
public void deleteOriginAbilityList(Analysis analysis) {
List<Ability> abilityList = analysis.getAbilityList();
Expand Down Expand Up @@ -102,10 +107,4 @@ private Ability findAbilityByKeyword(Analysis analysis, Keyword key) {
.findFirst()
.orElseThrow(() -> new AbilityException(AbilityErrorStatus.INVALID_KEYWORD));
}

private void validAbilityCount(int abilityCount) {
if (abilityCount < 1 || abilityCount > 3) {
throw new AbilityException(AbilityErrorStatus.INVALID_ABILITY_KEYWORD);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ public class AnalysisService {
private final RecordDbService recordDbService;

/*
* CLOVA STUDIO룰 활용해 역량 분석 객체를 생성 후 반환
* OpenAI룰 활용해 역량 분석 객체를 생성 후 반환
* @param record
* @param user
* @return
*/
public Analysis createAnalysis(Record record, User user) {

// MEMO 경험 기록이라면, CLOVA STUDIO를 이용해 요약 진행
// MEMO 경험 기록이라면, OpenAI를 이용해 요약 진행
String content = getRecordContent(record);

// Open-ai API 호출
// OpenAI API 호출
AnalysisAiResponse response = generateAbilityAnalysis(content);

// Analysis 객체 생성 및 저장
Expand All @@ -55,7 +55,7 @@ public Analysis createAnalysis(Record record, User user) {
}

/*
* CLOVA STUDIO를 활용해 역량 분석을 재수행함 Analysis 객체 데이터 교체 후 반환
* OpenAI를 활용해 역량 분석을 재수행함 Analysis 객체 데이터 교체 후 반환
* @param record
* @param user
* @return
Expand Down Expand Up @@ -103,6 +103,11 @@ public AnalysisResponse.AnalysisDto postAnalysis(Long userId, Long recordId) {
return AnalysisConverter.toAnalysisDto(analysis);
}

private void validIsUserAuthorizedForRecord(User user, Record record) {
if (!record.getUser().equals(user))
throw new RecordException(RecordErrorStatus.USER_RECORD_UNAUTHORIZED);
}

/*
* analysisId를 받아 경험 분석 상세 정보를 반환
* @param userId, analysisId
Expand Down Expand Up @@ -171,13 +176,18 @@ private AnalysisAiResponse generateAbilityAnalysis(String content) {
return response;
}

private String generateMemoSummary(String content) {
String response = openAiService.generateMemoSummary(content);
private void validAnalysisCommentLength(String comment) {
if (comment.isEmpty() || comment.length() > 300)
throw new AnalysisException(AnalysisErrorStatus.OVERFLOW_ANALYSIS_COMMENT);
}

validIsRecordEnough(response);
validAnalysisContentLength(response);
private void validAnalysisKeywordContentLength(Map<String, String> keywordList) {
for (Map.Entry<String, String> entry : keywordList.entrySet()) {
String keyContent = entry.getValue();

return response;
if (keyContent.isEmpty() || keyContent.length() > 300)
throw new AnalysisException(AnalysisErrorStatus.OVERFLOW_ANALYSIS_KEYWORD_CONTENT);
}
}

private String getRecordContent(Record record) {
Expand All @@ -190,38 +200,27 @@ private String getRecordContent(Record record) {
return content;
}

private void validIsRecordEnough(String response) {
if (response.contains("NO_RECORD"))
throw new RecordException(RecordErrorStatus.NO_RECORD);
}
private String generateMemoSummary(String content) {
String response = openAiService.generateMemoSummary(content);

private void validIsUserAuthorizedForAnalysis(User user, Analysis analysis) {
if (!analysis.getRecord().getUser().equals(user))
throw new RecordException(RecordErrorStatus.USER_RECORD_UNAUTHORIZED);
validIsRecordEnough(response);
validAnalysisContentLength(response);

return response;
}

private void validIsUserAuthorizedForRecord(User user, Record record) {
if (!record.getUser().equals(user))
throw new RecordException(RecordErrorStatus.USER_RECORD_UNAUTHORIZED);
private void validIsRecordEnough(String response) {
if (response.contains("NO_RECORD"))
throw new RecordException(RecordErrorStatus.NO_RECORD);
}

private void validAnalysisContentLength(String content) {
if (content.isEmpty() || content.length() > 500)
throw new AnalysisException(AnalysisErrorStatus.OVERFLOW_ANALYSIS_CONTENT);
}

private void validAnalysisCommentLength(String comment) {
if (comment.isEmpty() || comment.length() > 300)
throw new AnalysisException(AnalysisErrorStatus.OVERFLOW_ANALYSIS_COMMENT);
}

private void validAnalysisKeywordContentLength(Map<String, String> keywordList) {
for (Map.Entry<String, String> entry : keywordList.entrySet()) {
String keyContent = entry.getValue();

if (keyContent.isEmpty() || keyContent.length() > 300)
throw new AnalysisException(AnalysisErrorStatus.OVERFLOW_ANALYSIS_KEYWORD_CONTENT);
}
private void validIsUserAuthorizedForAnalysis(User user, Analysis analysis) {
if (!analysis.getRecord().getUser().equals(user))
throw new RecordException(RecordErrorStatus.USER_RECORD_UNAUTHORIZED);
}

}
52 changes: 25 additions & 27 deletions src/main/java/corecord/dev/domain/chat/application/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ public ChatResponse.ChatsDto createChat(Long userId, Long chatRoomId, ChatReques
return ChatConverter.toChatsDto(List.of(aiChat));
}

private static void checkGuideChat(ChatRoom chatRoom) {
if (chatRoom.getChatList().size() > 2)
throw new ChatException(ChatErrorStatus.INVALID_GUIDE_CHAT);
}

private ChatResponse.ChatsDto generateGuideChats(ChatRoom chatRoom) {
Chat guideChat1 = chatDbService.saveChat(0, "걱정 마세요!\n저와 대화하다 보면 경험이 정리될 거예요\uD83D\uDCDD", chatRoom);
Chat guideChat2 = chatDbService.saveChat(0, "오늘은 어떤 경험을 했나요?\n상황과 해결한 문제를 말해주세요!", chatRoom);
return ChatConverter.toChatsDto(List.of(guideChat1, guideChat2));
}

/*
* user의 채팅방의 채팅 목록을 반환
* @param userId
Expand Down Expand Up @@ -99,6 +110,15 @@ public void deleteChatRoom(Long userId, Long chatRoomId) {
chatDbService.deleteChatRoom(chatRoom);
}

private void checkTmpChat(User user, ChatRoom chatRoom) {
if (user.getTmpChat() == null) {
return;
}
if (user.getTmpChat().equals(chatRoom.getChatRoomId())) {
user.deleteTmpChat();
}
}

/*
* user의 채팅의 요약 정보를 반환
* @param userId
Expand All @@ -121,6 +141,11 @@ public ChatResponse.ChatSummaryDto getChatSummary(Long userId, Long chatRoomId)
return ChatConverter.toChatSummaryDto(chatRoom, response);
}

private static void validateChatList(List<Chat> chatList) {
if (chatList.size() <= 1)
throw new ChatException(ChatErrorStatus.NO_RECORD);
}

/*
* user의 임시 채팅방과 유무를 반환
* @param userId
Expand Down Expand Up @@ -155,18 +180,6 @@ public void saveChatTmp(Long userId, Long chatRoomId) {
userDbService.updateUserTmpChat(user, chatRoom.getChatRoomId());
}

private static void checkGuideChat(ChatRoom chatRoom) {
if (chatRoom.getChatList().size() > 2) {
throw new ChatException(ChatErrorStatus.INVALID_GUIDE_CHAT);
}
}

private ChatResponse.ChatsDto generateGuideChats(ChatRoom chatRoom) {
Chat guideChat1 = chatDbService.saveChat(0, "걱정 마세요!\n저와 대화하다 보면 경험이 정리될 거예요\uD83D\uDCDD", chatRoom);
Chat guideChat2 = chatDbService.saveChat(0, "오늘은 어떤 경험을 했나요?\n상황과 해결한 문제를 말해주세요!", chatRoom);
return ChatConverter.toChatsDto(List.of(guideChat1, guideChat2));
}

private static void validateResponse(ChatSummaryAiResponse response) {
if (response.getTitle().equals("NO_RECORD") || response.getContent().equals("NO_RECORD") || response.getContent().equals("") || response.getTitle().equals("")) {
throw new ChatException(ChatErrorStatus.NO_RECORD);
Expand All @@ -180,19 +193,4 @@ private static void validateResponse(ChatSummaryAiResponse response) {
throw new ChatException(ChatErrorStatus.OVERFLOW_SUMMARY_CONTENT);
}
}

private static void validateChatList(List<Chat> chatList) {
if (chatList.size() <= 1) {
throw new ChatException(ChatErrorStatus.NO_RECORD);
}
}

private void checkTmpChat(User user, ChatRoom chatRoom) {
if (user.getTmpChat() == null) {
return;
}
if (user.getTmpChat().equals(chatRoom.getChatRoomId())) {
user.deleteTmpChat();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public FolderResponse.FolderDtoList updateFolder(Long userId, FolderRequest.Fold
return FolderConverter.toFolderDtoList(folderList);
}

private void validIsUserAuthorizedForFolder(User user, Folder folder) {
if (!folder.getUser().equals(user))
throw new FolderException(FolderErrorStatus.USER_FOLDER_UNAUTHORIZED);
}

/*
* 생성일 오름차순으로 폴더 리스트를 조회
* @param userId
Expand All @@ -122,11 +127,4 @@ private void validDuplicatedFolderTitleAndLength(String title, User user) {
throw new FolderException(FolderErrorStatus.DUPLICATED_FOLDER_TITLE);
}
}

// user-folder 권한 검사
private void validIsUserAuthorizedForFolder(User user, Folder folder) {
if (!folder.getUser().equals(user))
throw new FolderException(FolderErrorStatus.USER_FOLDER_UNAUTHORIZED);
}

}
Loading

0 comments on commit 86f67b2

Please sign in to comment.