Skip to content

Commit

Permalink
feat: Add getReadmeText in AiServer
Browse files Browse the repository at this point in the history
  • Loading branch information
npole0103 committed Sep 11, 2022
1 parent ed27cb8 commit 7f3d41a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/main/java/kr/markdown/alreadyme/service/AiService.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package kr.markdown.alreadyme.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
@RequiredArgsConstructor
@Log4j2
public class AiService {

public String getReadmeText(String requestJsonData, String githubOriginalUrl) throws JsonProcessingException {
@Value("${ai-server.host}")
private String aiServerHost;

public String getReadmeText(String requestJsonData, String githubOriginalUrl) throws IOException {

//requestJsonData
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode();

Expand All @@ -23,9 +35,13 @@ public String getReadmeText(String requestJsonData, String githubOriginalUrl) th
objectNode.set("data", jsonDataNode);

//httpClient
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(aiServerHost);
httpPost.setHeader("Content-type", "application/json");

//response.toString()
httpPost.setEntity(new StringEntity(objectNode.toString(), "UTF-8"));
HttpResponse httpResponse = httpClient.execute(httpPost);

return "create readme.md success";
return EntityUtils.toString(httpResponse.getEntity());
}
}

0 comments on commit 7f3d41a

Please sign in to comment.