Skip to content
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 @@ -59,6 +59,7 @@ public ResponseEntity<String> receiveData(@RequestBody String data) {
ObjectMapper Data = new ObjectMapper();
JsonNode convertData = Data.readTree(data);


log.info(data);
if (validateUserStudySync(convertData)) {
return ResponseEntity.ok("success");
Expand All @@ -77,6 +78,8 @@ public ResponseEntity<String> upload(@RequestBody String request) throws JsonPro
ObjectMapper Data = new ObjectMapper();
JsonNode convertData = Data.readTree(request);

log.info(String.valueOf(convertData));

codeService.upload(convertData);
return ResponseEntity.ok("Upload successful");
}
Expand Down Expand Up @@ -138,4 +141,3 @@ public OpenAIResponse analyzeCode(@RequestBody OpenAIRequest request) {




Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ public class UploadDTO {
private String time;
private String performance;
private String annotation;
private String status;
private boolean status;
private String annotatedSource;
private String accuracy;

public UploadDTO(JsonNode request) {
this.memberId = request.get("id").asText();
this.problemId = request.get("problemId").asText();


//.
this.source = request.get("sourceText").asText();
this.time = request.get("timeSpent").asText();
this.performance = request.get("commitMessage").asText();
this.annotation = "/** 주석 공간 테스트 */";
this.status = "Y";
this.status = true;
this.annotatedSource = annotation + "\n" + source;
this.accuracy = request.get("resultMessage").asText();
this.performance = request.get("commitMessage").asText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ public static class Usage {
@JsonProperty("total_tokens")
private int totalTokens;
}

public String getAnalyzedCode() {
if (choices != null && !choices.isEmpty()) {
return choices.get(0).getMessage().getContent(); // 첫 번째 응답의 content 반환
}
return ""; // choices가 비어있으면 빈 문자열 반환
}
}
20 changes: 16 additions & 4 deletions src/main/java/com/podofarm/dev/api/code/service/CodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,36 @@ public class CodeService {
public void upload(JsonNode request) {
UploadDTO uploadDTO = new UploadDTO(request);

MemberEntity memberEntity = memberRepository.findById(uploadDTO.getMemberId())
.orElseThrow(() -> new IllegalArgumentException("해당 회원이 존재하지 않습니다: " + uploadDTO.getMemberId()));
// 1. OpenAI 코드 분석 API를 호출하여 1차 포장된 source 얻기
OpenAIRequest openAIRequest = new OpenAIRequest();
openAIRequest.setCode(uploadDTO.getSource());

OpenAIResponse aiResponse = analyzeCode(openAIRequest);
String analyzedSource = aiResponse.getAnalyzedCode();

// 2. problemId로 problem 테이블에서 problemSolution 조회 후 source에 추가
ProblemEntity problemEntity = problemRepository.findById(Long.parseLong(uploadDTO.getProblemId()))
.orElseThrow(() -> new IllegalArgumentException("해당 문제 ID가 존재하지 않습니다: " + uploadDTO.getProblemId()));

// 3. 최종코드
String finalSource = problemEntity.getProblemSolution() + analyzedSource;

MemberEntity memberEntity = memberRepository.findById(uploadDTO.getMemberId())
.orElseThrow(() -> new IllegalArgumentException("해당 회원이 존재하지 않습니다: " + uploadDTO.getMemberId()));

CodeEntity codeEntity = CodeEntity.builder()
.memberEntity(memberEntity)
.problemEntity(problemEntity)
.codeSource(uploadDTO.getAnnotatedSource())
.codeSource(finalSource)
.codeSolvedDate(uploadDTO.getSolvedDateAsTimestamp())
.codeTime(Time.valueOf(uploadDTO.getTime()))
.codeStatus(Boolean.valueOf(uploadDTO.getStatus()))
.codeStatus(uploadDTO.isStatus())
.build();

codeRepository.save(codeEntity);
}


public CommentListResponse allComment(Long codeNo) {
CodeEntity code = codeRepository.findByIdWithComments(codeNo)
.orElseThrow(() -> new RuntimeException("없는 코드입니다."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public class ProblemEntity {
@Column(name = "problem_id")
private Long problemId;

@Column(name = "problem_solution")
private String problemSolution;

@OneToMany(mappedBy = "problemEntity")
private final List<CodeEntity> codeList = new ArrayList<>();


}