Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hot-dong committed Jul 4, 2023
2 parents 3e8eb62 + d773f7a commit 092e51d
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@ public class ChatController {

private final UserService userService;

// TODO check if prev data exist
// TODO add design if no prev data is provided
// TODO add examples. Add html code, with js

@ModelAttribute
public void addAttributes(HttpServletRequest request, Model model) {
model.addAttribute("current_url", request.getRequestURL().toString());
model.addAttribute("current_url", request.getRequestURL().toString().split("8090")[1]);
model.addAttribute("image", "/icons/black.png");
}

// TODO 이전 기록 가져오기 메소드

@GetMapping("/new")
public String newChat(HttpSession session, HttpServletResponse response) throws IOException {
if (session.getAttribute("user") == null) {
System.out.println("Create new chat failed. No session");
response.setStatus(HttpStatus.UNAUTHORIZED.value());
response.sendRedirect("/");
return null;
}
// TODO remove chats in user
// remove chats in user
String userId = session.getAttribute("user").toString();
userService.clearChats(userId);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/khpt/projectkim/dto/UserPrevData.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class UserPrevData {

private String education; // 학력

private String career;

private String category; // 직업 카테고리
}
2 changes: 1 addition & 1 deletion src/main/java/com/khpt/projectkim/entity/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Chat {
private ChatMessageRole role;

// chat messages
@Column(nullable = false)
@Column(nullable = false, length = 2048)
private String content;

}
2 changes: 2 additions & 0 deletions src/main/java/com/khpt/projectkim/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class User implements Serializable {

private String education; // 학력

private String career; // 경력

private String category; // 직업 카테고리

public User update(String name, String picture) {
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/com/khpt/projectkim/service/SimplifyJsonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ private static Map<String, Object> simplifyJob(Job job) {
}

public static Map<String, List<Map<String, Object>>> simplifyJobs(Root root, String experience_lvl, int maxSize) {
List<String> experience_lvl_list = List.of(experience_lvl.split(","));
List<String> experience_lvl_list = null;
if (experience_lvl != null) {
experience_lvl_list = List.of(experience_lvl.split(","));
}


List<Map<String, Object>> simplifiedJobs = new ArrayList<>();
for (Job job : root.jobs.job) {
Map<String, Object> objectMap = simplifyJob(job);
if (experience_lvl_list.contains(objectMap.get("experience_level_code").toString())) {
simplifiedJobs.add(objectMap);
if (experience_lvl_list != null) {
if (experience_lvl_list.contains(objectMap.get("experience_level_code").toString())) {
simplifiedJobs.add(objectMap);
}
}
if (simplifiedJobs.size() >= maxSize) {
break;
Expand Down Expand Up @@ -77,13 +83,18 @@ private static Map<String, Object> simplifyJob2(Job job) {
}

public static Map<String, List<Map<String, Object>>> simplifyJobs2(Root root, String experience_lvl, int maxSize) {
List<String> experience_lvl_list = List.of(experience_lvl.split(","));
List<String> experience_lvl_list = null;
if (experience_lvl != null) {
experience_lvl_list = List.of(experience_lvl.split(","));
}

List<Map<String, Object>> simplifiedJobs = new ArrayList<>();
for (Job job : root.jobs.job) {
Map<String, Object> objectMap = simplifyJob2(job);
if (experience_lvl_list.contains(objectMap.get("experience_level_code").toString())) {
simplifiedJobs.add(objectMap);
if (experience_lvl_list != null) {
if (experience_lvl_list.contains(objectMap.get("experience_level_code").toString())) {
simplifiedJobs.add(objectMap);
}
}
if (simplifiedJobs.size() >= maxSize) {
break;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/khpt/projectkim/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public void setUserPrevData(String id, UserPrevData userPrevData) {
user.setType(userPrevData.getType());
user.setRegion(userPrevData.getRegion());
user.setEducation(userPrevData.getEducation());
user.setCareer(userPrevData.getCareer());
user.setCategory(userPrevData.getCategory());

userRepository.save(user);
Expand All @@ -197,6 +198,7 @@ public UserPrevData getUserPrevData(String id) {
userPrevData.setType(user.getType());
userPrevData.setRegion(user.getRegion());
userPrevData.setEducation(user.getEducation());
userPrevData.setCareer(user.getCareer());
userPrevData.setCategory(user.getCategory());

return userPrevData;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/css/output.css

Large diffs are not rendered by default.

Binary file added src/main/resources/static/images/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/images/logo-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 39 additions & 7 deletions src/main/resources/static/js/chatInput.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const chatInput = document.getElementById("chat-input")
const chatBtn = document.getElementById("chat-btn")

let inputAvailable = true


chatInput.addEventListener('input', function() {
this.innerText = this.value
this.style.height = (this.value.split("\n").length * 24) + "px"

if (this.value.length > 0) {
if (!inputAvailable) {
return
}
chatBtn.removeAttribute("disabled")
} else {
chatBtn.setAttribute("disabled", "")
Expand All @@ -16,13 +20,16 @@ chatInput.addEventListener('input', function() {

chatBtn.addEventListener('click', function (event) {
event.preventDefault()
if (!inputAvailable) {
return
}
sendMessage(chatInput.value)
})

chatInput.addEventListener('keydown', function(event) {
if (event.key === "Enter") {
event.preventDefault()
if (event.shiftKey) {
if (event.shiftKey || !inputAvailable) {
if ((this.offsetHeight + 24) > 200) {
this.style.overflowY = ''
} else {
Expand All @@ -37,7 +44,17 @@ chatInput.addEventListener('keydown', function(event) {
}
})

function createCustomElement(text) {
const div = document.createElement('div');
div.className = 'process w-fit mb-2 p-2 pl-4 pr-16 bg-violet-200 rounded-lg text-sm flex';
div.innerHTML = `<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg><span>${text}</span>`;

return div;
}

function sendMessage(inputValue) {
inputAvailable = false

const userChatItem = makeUserChatItem(inputValue)

document.getElementById('chats').appendChild(userChatItem)
Expand Down Expand Up @@ -80,29 +97,44 @@ function sendMessage(inputValue) {
eventSource.addEventListener('message', function(event) {
assistantChatItem.lastChild.textContent = assistantChatItem.lastChild.textContent + event.data.toString().replaceAll("%20", " ").replaceAll("%0A", "\n")
const chats = document.getElementById('chats')

chats.scrollTo(0, chats.scrollHeight)
})
eventSource.addEventListener('function', function(event) {
console.log(event.data)
})
eventSource.addEventListener('process', function(event) {
console.log(event.data)
const chats = document.getElementById('chats')
const processElem = chats.querySelector(".process span")
if (event.data === "fine") {
processElem.textContent = ""
return
}
if (processElem == null) {
const process = createCustomElement(event.data)
chats.lastChild.lastChild.appendChild(process)
} else {
processElem.textContent = event.data
}

})
eventSource.addEventListener('result', function(event) {
// console.log(event.data)
// const obj = JSON.parse(event.data)
// console.log(obj)
// data = obj.jobs
// updateData()
console.log(event.data)
refreshData()
})
eventSource.addEventListener('error', function (event) {
eventSource.addEventListener('err', function (event) {
alert(event.data)
inputAvailable = true
})
eventSource.addEventListener('complete', function(event) {
console.log(event.data)
eventSource.close();
inputAvailable = true
})
eventSource.onerror = function(error) {
console.log('Error: ', error);
inputAvailable = true
}
// const data = await response.json()
//
Expand Down

0 comments on commit 092e51d

Please sign in to comment.