Skip to content

Commit

Permalink
Merge pull request #43 from siwonKH/main
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
siwonKH committed Jun 30, 2023
2 parents b85298f + 393ca81 commit 5f996ea
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 78 deletions.
5 changes: 4 additions & 1 deletion API/saramin/get_job_info_from_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
dotenv.load_dotenv(dotenv_file)


def get_job_info_from_api(job_codes=None, job_type=None, education_lvl=None, location=None, count="20", keywords=None):
def get_job_info_from_api(job_codes=None, job_type=None, education_lvl=None, location=None, count="20", keywords=None, sort=None):
url = "https://oapi.saramin.co.kr/job-search"
header = {
"Accept": "application/json"
Expand All @@ -19,6 +19,7 @@ def get_job_info_from_api(job_codes=None, job_type=None, education_lvl=None, loc
"loc_mcd": location,
"count": count,
"keywords": keywords,
"sort": sort,
"access-key": os.environ['SARAMIN_KEY']
}
if not job_codes:
Expand All @@ -31,6 +32,8 @@ def get_job_info_from_api(job_codes=None, job_type=None, education_lvl=None, loc
del params['loc_mcd']
if not keywords:
del params['keywords']
if not sort:
del params['sort']

response = requests.get(url, headers=header, params=params)
return json.loads(response.text)
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -25,61 +27,37 @@ public class ChatRestController {

// (프론트에서 채팅 보내기 클릭 하면 이 함수에 모든 채팅 기록을 줌)
@PostMapping
public ChatData sendChat(HttpSession session, HttpServletResponse response, @RequestBody List<ChatData> chatDataList) {
// if (session.getAttribute("user") == null) {
// System.out.println("Send chat failed. No session");
// response.setStatus(HttpStatus.BAD_REQUEST.value());
// return null;
// }
public ChatData sendChat(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestBody List<ChatData> chatDataList) throws IOException {
if (session.getAttribute("user") == null) {
System.out.println("Send chat failed. No session");
response.setStatus(HttpStatus.BAD_REQUEST.value());
return null;
}
ChatData lastChat = chatDataList.get(chatDataList.size() - 1);

Long userID = (Long) session.getAttribute("user");

chatService.updateUserChats(userID, lastChat);

try {
System.setProperty("https.protocols", "TLSv1.2");
ObjectMapper objectMapper = new ObjectMapper();
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();

// List를 JSON 형태로 변환
ObjectMapper objectMapper = new ObjectMapper();
try {
String json = objectMapper.writeValueAsString(chatDataList);

// RestTemplate 인스턴스 생성
RestTemplate restTemplate = new RestTemplate();

// ChatData 객체 생성
ChatData chatData = chatDataList.get(0);

// 요청 헤더 설정
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

// 요청 엔티티 생성
HttpEntity<ChatData> requestEntity = new HttpEntity<>(chatData, headers);
HttpEntity<String> requestEntity = new HttpEntity<>(json, headers);

// POST 요청 보내기
String url = "http://localhost:8090/result";
ResponseEntity<String> res = restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
String url = "http://localhost:8000/chat";
ResponseEntity<ChatData> res = restTemplate.exchange(url, HttpMethod.POST, requestEntity, ChatData.class);

// 응답 데이터 가져오기
String responseBody = res.getBody();
System.out.println("Response: " + responseBody);
return res.getBody();
} catch (Exception e) {
e.printStackTrace();
return new ChatData("assistant", "ERROR");
}

// ChatData 클래스는 채팅 하나를 의미함
// 여러개의 채팅이 모여 chatDataList 에 모든 채팅 내역이 순서대로 있음

// 물론 이 리스트의 마지막 아이템에 유저가 새로 입력한 채팅이 있음
// TODO chatDataList의 젤 마지막 아이템을 사용자 레포지토리 채팅 기록에 추가

// TODO chatDataList JSON으로 변환

// TODO 변환된 JSON을 API에 보내서 responseChat(GPT 응답) 가져오기

ChatData responseChat = new ChatData("assistant", "안녕하세요. 무엇을 도와드릴까요?");
return responseChat;
}

@GetMapping("/all")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
package com.khpt.projectkim.controller.api;

import com.khpt.projectkim.dto.ResultDto;
import com.khpt.projectkim.service.ApiRequestService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/result")
@RequiredArgsConstructor
public class ResultRestController {
@GetMapping

private final ApiRequestService apiRequestService;

@GetMapping("/api/chat")
public SseEmitter result() {
final SseEmitter emitter = new SseEmitter();

// Run in separate thread to avoid request timeout
new Thread(() -> {
try {
// Start processing and send initial status to frontend
emitter.send(SseEmitter.event().name("message").data("Processing ChatGPT request..."));

String chatGptResponse = apiRequestService.testService();
emitter.send(SseEmitter.event().name("message").data("ChatGPT processing complete. Weather API processing..."));

String weatherApiResponse = apiRequestService.testService();
emitter.send(SseEmitter.event().name("message").data("Weather API processing complete."));

// Send the responses to the frontend
emitter.send(SseEmitter.event().name("message").data(chatGptResponse));
emitter.send(SseEmitter.event().name("message").data(weatherApiResponse));

emitter.send(SseEmitter.event().name("complete").data("Processing complete"));
emitter.complete();
} catch (IOException e) {
emitter.completeWithError(e);
}
}).start();

return emitter;
}

@GetMapping("/result")
public List<ResultDto> getResult_test(HttpSession session) {
ResultDto responseChat1 = new ResultDto("https://google.com", "comp", "제목", "지역", "대충급여", "대충형태", "대충시간", "몰?루", "경력");
ResultDto responseChat2 = new ResultDto("https://google.com", "comp2", "제목2", "지역2", "대충급여2", "대충형태22", "대충시간22", "몰?루22", "경력22");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@RequestMapping("/login")
public class LoginController {
@GetMapping("")
public String loginPage(Model model, @RequestParam(value = "redirect", defaultValue = "") String uri) {
public String loginPage(Model model, @RequestParam(value = "redirect", defaultValue = "/") String uri) {
model.addAttribute("redirect_uri", uri);
return "login";
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/khpt/projectkim/service/ApiRequestService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.khpt.projectkim.service;

import org.springframework.stereotype.Service;

@Service
public class ApiRequestService {

public void getResult() {

}

public String testService() {
try {
Thread.sleep(2 * 1000);
System.out.println("2 sec");
Thread.sleep(2 * 1000);
System.out.println("4 sec");
Thread.sleep(2 * 1000);
System.out.println("6 sec");
Thread.sleep(2 * 1000);
System.out.println("8 sec");
Thread.sleep(2 * 1000);
System.out.println("10 sec");
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
return "This is response!";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="ko">
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -10,44 +10,41 @@
<div class="flex flex-col h-screen">

<!--Appbar-->
<div class="py-5 px-14 border-b flex justify-between items-center">
<div class="py-3 px-14 border-b flex justify-between items-center">

<!--Left Appbar contents-->
<div class="flex items-center space-x-16">
<div class="flex space-x-16 items-center">
<div class="text-2xl font-bold">김비서</div>
<div class="flex space-x-5">
<a href="#" class="text-stone-500 font-bold cursor-pointer">사용방법</a>
<a href="#" class="text-violet-500 font-bold cursor-pointer">대화하기</a>
<div class="flex space-x-5 items-center">
<a class="p-2 text-stone-500 font-bold cursor-pointer rounded-lg hover:bg-stone-100" href="#">사용방법</a>
<a class="p-2 text-violet-500 font-bold cursor-pointer rounded-lg hover:bg-stone-100" href="/chat/new" th:if="${name != null}">새로운 채팅</a>
<a class="p-2 text-stone-500 font-bold cursor-pointer rounded-lg hover:bg-stone-100" href="/chat/recent" th:if="${recent_results != null}">이전 분석 기록</a>
</div>
</div>
<!--Left Appbar contents-->

<!--Right Appbar contents-->
<div class="flex space-x-5">
{{^ name }}
<a href="/login?redirect={{ current_url }}" class="text-stone-800 font-bold cursor-pointer">로그인</a>
{{/ name }}
{{# recent_results }}
<a href="#" class="text-stone-800 font-bold cursor-pointer">이전 기록</a>
{{/ recent_results }}
{{# name }}
<span href="#" class="text-stone-800 font-bold underline">{{ name }}</span>
<a href="/logout" class="text-stone-800 font-bold cursor-pointer">로그아웃</a>
{{/ name }}
<div class="flex space-x-5 items-center">
<a th:if="${name == null}" th:href="|/login?redirect=${ current_url }|" class="p-2 text-stone-800 font-bold cursor-pointer hover:bg-stone-100">로그인</a>
<span th:if="${name != null}" class="p-2 text-violet-500 font-bold underline" th:text="${name}"></span>
<a th:if="${name != null}" href="/logout" class="p-2 text-stone-800 font-bold cursor-pointer rounded-lg hover:bg-stone-100">로그아웃</a>
</div>
<!--Right Appbar contents-->

</div>
<!--Appbar-->



<!--Body-->
<div class="h-full px-14 py-5 flex space-x-7 overflow-auto">
<div class="h-full px-14 py-5 flex space-x-4 overflow-auto">


<!--Chat-->
<div class="w-full h-full flex flex-col space-y-7 overflow-auto">
<div class="w-full h-full p-2 flex flex-col space-y-7 overflow-auto">

<!--Chat items-->
<div id="chats" class="h-full p-5 border rounded-lg shadow-md space-y-3 overflow-y-scroll no-scrollbar">
<div id="chats" class="h-full p-5 border rounded-lg shadow-lg space-y-3 overflow-y-scroll no-scrollbar">

<!-- <div class="assistant flex space-x-3">-->
<!-- <img class="w-7 h-7 rounded-lg" src="/images/logo-rev.png" alt="" />-->
Expand All @@ -67,13 +64,14 @@
<!-- </div>-->

</div>
<!--Chat-->

<!--Chat input-->
<div class="h-20">
<!-- <label>-->
<!-- <input type="text" name="chat" class="w-full p-3 border rounded-lg shadow-md">-->
<!-- </label>-->
<div class="flex flex-col w-full pl-4 py-4 relative border border-black/10 bg-white rounded-xl shadow-md">
<div class="flex flex-col w-full pl-4 py-4 relative border border-black/10 bg-white rounded-xl shadow-lg">
<textarea id="chat-input" class="m-0 w-full resize-none border-0 bg-transparent p-0 pr-10 focus:ring-0 focus:outline-none" tabindex="0" placeholder="Send a message" style="max-height: 200px; height: 24px; overflow-y: hidden;"></textarea>
<button id="chat-btn" class="absolute p-1 rounded-md bottom-3 md:p-2 right-3 disabled:text-gray-400 enabled:bg-violet-500 text-white transition-colors disabled:opacity-40" disabled>
<span data-state="closed">
Expand All @@ -84,23 +82,28 @@
</button>
</div>
</div>
<!--Chat input-->

</div>
<!--Chat-->


<!--Analysis-->
<div class="h-full w-1/3 flex flex-col justify-stretch space-y-7 overflow-auto">
<div class="h-full w-1/3 p-2 flex flex-col justify-stretch space-y-7 overflow-auto">

<!--Analysis items-->
<div id="container" data-modal-toggle="defaultModal" data-modal-target="defaultModal" class="h-full p-5 border rounded-lg shadow-md flex flex-col space-y-2 overflow-y-scroll no-scrollbar">
<div id="container" data-modal-toggle="defaultModal" data-modal-target="defaultModal" class="h-full p-2 border rounded-lg shadow-lg flex flex-col space-y-2 overflow-y-scroll no-scrollbar">
</div>
<!--Analysis items-->

<!--Info edit btn-->
<div class="h-20">
<button class="w-full p-4 border rounded-lg shadow-md text-stone-500">사전 정보 수정</button>
<button class="w-full p-4 border rounded-lg shadow-lg text-stone-500">사전 정보 수정</button>
</div>
<!--Info edit btn-->

</div>
<!--Analysis-->

</div>

Expand Down Expand Up @@ -180,21 +183,24 @@
</div>
</div>
</body>
<script>
document.getElementById('chat-input').addEventListener('keydown', function(event) {
<script th:inline="javascript">
document.getElementById('chat-input').addEventListener('keydown', (event) => {
if (event.key === "Enter") {
event.preventDefault(); // Prevents the addition of a new line in the input when pressing enter
event.preventDefault();
if (event.shiftKey) {

}

var inputValue = this.value;
this.value = ''; // Clears the input field
this.value = '';

// Creating new user element
var userChatItem = document.createElement('div');
userChatItem.classList.add('user', 'flex', 'space-x-3');

var userImg = document.createElement('img');
userImg.classList.add('w-7', 'h-7', 'rounded-lg');
userImg.src = "{{image}}";
userImg.src = [[${image}]];

var userText = document.createElement('div');
userText.classList.add('w-full', 'p-5', 'bg-pink-100', 'rounded-lg');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="ko">
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -8,9 +8,9 @@
</head>
<body>
<div class="w-screen h-screen py-8 flex flex-col justify-between items-center text-center">
<div>
<img class="w-10 h-10 rounded-lg" src="/images/logo.png" alt="" />
</div>
<a href="/">
<img class="w-10 h-10 rounded-lg" src="/images/logo.png" alt="김비서" />
</a>
<div class="flex flex-col space-y-5">
<div>
<h1 class="pb-14 text-3xl text-stone-700 font-bold">환영합니다</h1>
Expand All @@ -20,14 +20,19 @@ <h1 class="pb-14 text-3xl text-stone-700 font-bold">환영합니다</h1>
<span class="w-fit px-4 text-sm text-stone-700">LOGIN</span>
<div class="w-full h-3 border-b border-stone-400"></div>
</div>
<a href="/login/github?redirect={{ redirect_uri }}" class="w-80 p-3 border flex items-center space-x-5 rounded cursor-pointer">
<a th:href="|/login/github?redirect=${redirect_uri}|" class="w-80 p-3 border flex items-center space-x-5 rounded hover:bg-stone-100">
<svg class="w-7 h-7" width="16" height="16" aria-hidden="true" viewBox="0 0 16 16" >
<path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"></path>
</svg>
<span class="">Continue with Github</span>
</a>
<a href="#just_for_design" class="w-80 p-3 border flex items-center space-x-5 rounded cursor-not-allowed">
<img class="w-7 h-7" width="16" height="16" alt="google" src="data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 48 48'%3E%3Cdefs%3E%3Cpath id='a' d='M44.5 20H24v8.5h11.8C34.7 33.9 30.1 37 24 37c-7.2 0-13-5.8-13-13s5.8-13 13-13c3.1 0 5.9 1.1 8.1 2.9l6.4-6.4C34.6 4.1 29.6 2 24 2 11.8 2 2 11.8 2 24s9.8 22 22 22c11 0 21-8 21-22 0-1.3-.2-2.7-.5-4z'/%3E%3C/defs%3E%3CclipPath id='b'%3E%3Cuse xlink:href='%23a' overflow='visible'/%3E%3C/clipPath%3E%3Cpath clip-path='url(%23b)' fill='%23FBBC05' d='M0 37V11l17 13z'/%3E%3Cpath clip-path='url(%23b)' fill='%23EA4335' d='M0 11l17 13 7-6.1L48 14V0H0z'/%3E%3Cpath clip-path='url(%23b)' fill='%2334A853' d='M0 37l30-23 7.9 1L48 0v48H0z'/%3E%3Cpath clip-path='url(%23b)' fill='%234285F4' d='M48 48L17 24l-4-3 35-10z'/%3E%3C/svg%3E" />
<span>Continue with Google</span>
</a>
<div class="flex flex-col space-y-1">
<span class="text-xs text-stone-200 dark:text-black">No github account? Too bad for you..</span>
<span class="text-xs text-stone-600 dark:text-black pb-2">Only github account available.</span>
<span class="text-xs text-stone-200 dark:text-black">No github account? Too bad for you..</span>
<span class="text-xs text-stone-100">I'll provide Google acc someday..</span>
<span class="text-xs text-stone-50">Just kidding, no more developments :p</span>
</div>
Expand Down

0 comments on commit 5f996ea

Please sign in to comment.