Skip to content

Commit

Permalink
♻️ Mydifing Todo Guide
Browse files Browse the repository at this point in the history
update Todo Guide

Related:
  • Loading branch information
L-U-Ready committed Nov 18, 2024
1 parent 3f60f5a commit 0f9061d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/LearnMate/dev/controller/PlanController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ApiResponse<PlanDetailResponse> getTodoDetail(@PathVariable("todoId") Lon
@PatchMapping("/{todoId}")
public ApiResponse<String> patchTodo(@PathVariable("todoId") Long todoId,
@RequestBody @Valid PlanPatchRequest request) {
return ApiResponse.onSuccess(planService.patchTodo(todoId, request));
return ApiResponse.onSuccessData("Todo Guide 재생성", planService.patchTodo(todoId, request));
}

@DeleteMapping("/{todoId}")
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/LearnMate/dev/model/entity/Plan.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public class Plan extends BaseTimeEntity {
@JoinColumn(name = "user_id")
private User user;

public void updateContent(String content) {
public void updateContentAndGuide(String content, String guide) {
if (!content.isEmpty()) {
this.content = content;
this.guide = guide;
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/LearnMate/dev/service/PlanService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String postTodo(PlanPostRequest request) {

User user = findUserById(userId);

String guide = openAIService.getTodoGuide(request.getContent());
String guide = getTodoGuide(request.getContent());

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

Expand Down Expand Up @@ -80,9 +80,11 @@ public String patchTodo(Long todoId, PlanPatchRequest request) {

validIsUserAuthorizedForPlan(user, plan);

plan.updateContent(request.getContent());
String guide = getTodoGuide(request.getContent());

return "Todo 수정";
plan.updateContentAndGuide(request.getContent(), guide);

return guide;
}

// Todo 삭제
Expand Down Expand Up @@ -131,4 +133,8 @@ private void validIsUserAuthorizedForPlan(User user, Plan plan) {
throw new ApiException(ErrorStatus._USER_FORBIDDEN_PLAN);
}

private String getTodoGuide(String content) {
return openAIService.getTodoGuide(content);
}

}

0 comments on commit 0f9061d

Please sign in to comment.