Skip to content

Commit

Permalink
fix: dto 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
osoohynn committed Nov 29, 2024
1 parent e1a187f commit 46d36d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/main/java/com/project/oof/gpt/controller/ChatGPTController.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
package com.project.oof.gpt.controller;

import com.project.oof.gpt.dto.MessageDto;
import com.project.oof.gpt.service.ChatGPTService;
import com.project.oof.storage.service.ChatHistoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/api")
public class ChatGPTController {
private final ChatHistoryService chatHistoryService;

private final ChatGPTService chatGPTService;

@PostMapping("/translate")
public ResponseEntity<String> selectPrompt(@RequestBody String message) {
String result = chatGPTService.translateMessage(message);
public ResponseEntity<MessageDto> selectPrompt(@RequestBody MessageDto request) {
MessageDto result = chatGPTService.translateMessage(request.message());
return new ResponseEntity<>(result, HttpStatus.OK);
}

@PostMapping("/refresh")
public ResponseEntity<String> refresh() {
String result = chatGPTService.refreshResult();
public ResponseEntity<MessageDto> refresh() {
MessageDto result = chatGPTService.refreshResult();
return new ResponseEntity<>(result, HttpStatus.OK);
}

@PostMapping("/clear")
public ResponseEntity<String> clearChatHistory() {
chatHistoryService.clearChatHistory(); // 대화 기록 초기화
return ResponseEntity.ok("Chat history cleared.");
@GetMapping()
public ResponseEntity<List<String>> getAnswers() {
return new ResponseEntity<>(chatGPTService.getAnswers(), HttpStatus.OK);
}

}
9 changes: 9 additions & 0 deletions src/main/java/com/project/oof/gpt/dto/MessageDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.project.oof.gpt.dto;

public record MessageDto (
String message
){
public static MessageDto of(String message) {
return new MessageDto(message);
}
}

0 comments on commit 46d36d4

Please sign in to comment.