Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Implement Todo Guide #23

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

public class PlanConverter {

public static Plan toPlan(String content, User user, String guid) {
public static Plan toPlan(String content, User user, String guide) {
return Plan.builder()
.content(content)
.user(user)
.guide(guid)
.guide(guide)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package LearnMate.dev.model.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -11,4 +12,9 @@ public class PlanPostRequest {
@NotBlank(message = "계획 내용은 필수입니다.")
private String content;

@Builder
public PlanPostRequest(String content) {
this.content = content;
}

}
9 changes: 9 additions & 0 deletions src/main/java/LearnMate/dev/service/OpenAIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@RequiredArgsConstructor
public class OpenAIService {
private final String ACTION_TIP_PROMPT = ResourceLoader.getResourceContent("action-tip-prompt.txt");
private final String TODO_GUIDE_PROMPT = ResourceLoader.getResourceContent("todo-guide-prompt.txt");
private final OpenAiChatModel chatModel;

@Async
Expand All @@ -21,4 +22,12 @@ public CompletableFuture<String> getActionTip(String content) {

return CompletableFuture.completedFuture(text);
}


public String getTodoGuide(String content) {

return chatModel.call(TODO_GUIDE_PROMPT + content);

}

}
10 changes: 8 additions & 2 deletions src/main/java/LearnMate/dev/service/PlanService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
@Transactional(readOnly = true)
public class PlanService {

private final UserRepository userRepository;
private final OpenAIService openAIService;

private final UserRepository userRepository;
private final PlanRepository planRepository;

// 최신 가이드 조회
public String getTodos() {

Long userId = getUserIdFromAuthentication();
Expand All @@ -36,6 +38,7 @@ public String getTodos() {

}

// Todo 생성
@Transactional
public String postTodo(PlanPostRequest request) {

Expand All @@ -45,13 +48,14 @@ public String postTodo(PlanPostRequest request) {

User user = findUserById(userId);

String guide = ""; // 이후 open api 연결
String guide = openAIService.getTodoGuide(request.getContent());

planRepository.save(PlanConverter.toPlan(request.getContent(), user, guide));

return "Todo 생성";
}

// Todo 상세 조회
public PlanDetailResponse getTodoDetail(Long todoId) {

Long userId = getUserIdFromAuthentication();
Expand All @@ -62,6 +66,7 @@ public PlanDetailResponse getTodoDetail(Long todoId) {

}

// Todo 수정
@Transactional
public String patchTodo(Long todoId, PlanPatchRequest request) {

Expand All @@ -80,6 +85,7 @@ public String patchTodo(Long todoId, PlanPatchRequest request) {
return "Todo 수정";
}

// Todo 삭제
@Transactional
public String deleteTodo(Long todoId) {

Expand Down