Skip to content

Commit

Permalink
Merge pull request #53 from potenday-project/feat/#51
Browse files Browse the repository at this point in the history
Feat/#51
  • Loading branch information
oU-Ua authored Dec 19, 2023
2 parents d3f0fbe + 3d865c7 commit 01db4f4
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import mvc.promiseme.calendar.dto.CalendarAndTodoAllByRoleDto;
import mvc.promiseme.calendar.dto.CalendarResponseDTO;
import mvc.promiseme.calendar.service.CalendarService;
import org.springframework.http.ResponseEntity;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Slf4j
@Controller
@RestController
@RequiredArgsConstructor
@RequestMapping("/calendar")
public class CalendarController {
Expand All @@ -29,13 +25,4 @@ public class CalendarController {
//
// }

@GetMapping("/todoAll")
public ResponseEntity<List<CalendarAndTodoAllByRoleDto>> calendarTodoAll(
@RequestParam(name = "projectId") Long projectId
, @RequestParam(name = "todoDate") String todoDate){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(todoDate, formatter);
return ResponseEntity.ok(calendarService.calendarAndtodoAll(projectId, localDate));
}

}
3 changes: 0 additions & 3 deletions src/main/java/mvc/promiseme/calendar/entity/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import jakarta.persistence.*;
import lombok.*;

import mvc.promiseme.project.entity.Member;
import mvc.promiseme.project.entity.Project;
import mvc.promiseme.project.entity.Role;
import mvc.promiseme.todo.entity.Todo;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import java.util.List;
import java.util.Optional;


public interface CalendarRepository extends JpaRepository<Calendar, Long> {
// @Query("SELECT NEW mvc.promiseme.calendar.dto.CalendarResponseDTO(c.content, c.startDate, c.finishDate, u.nickname) from Calendar c join c.member m join m.users u where c.project = :project")
// List<CalendarResponseDTO> findByProject(Project project);
List<Calendar> findByProjectAndStartDateLessThanEqualAndFinishDateGreaterThanEqual(Project project, LocalDate startDate, LocalDate finishDate);
List<Calendar> findByProjectAndStartDateLessThanEqualAndFinishDateGreaterThanEqual(Project project, LocalDate startDate, LocalDate finishDate);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mvc.promiseme.meeting.dto;

import lombok.*;
import org.springframework.web.bind.annotation.RequestParam;
@NoArgsConstructor
@AllArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import mvc.promiseme.calendar.dto.CalendarResponseDTO;
import mvc.promiseme.project.dto.ProjectRequestDTO;
import mvc.promiseme.project.dto.ProjectResponseDTO;
import mvc.promiseme.project.dto.RecommendMemberRequestDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import mvc.promiseme.users.entity.Users;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
import java.util.List;
import java.util.Optional;

public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByUsersAndProject(Users users, Project project);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mvc.promiseme.project.repository;

import mvc.promiseme.project.dto.ProjectResponseDTO;
import mvc.promiseme.project.entity.Member;
import mvc.promiseme.project.entity.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.RequiredArgsConstructor;
import mvc.promiseme.common.exception.ErrorCode;
import mvc.promiseme.common.exception.UserException;
import mvc.promiseme.project.dto.MemberDTO;
import mvc.promiseme.project.dto.MemberRequestDTO;
import mvc.promiseme.project.dto.ProjectRequestDTO;
import mvc.promiseme.project.dto.ProjectResponseDTO;
Expand All @@ -14,15 +13,16 @@
import mvc.promiseme.project.repository.MemberRepository;
import mvc.promiseme.project.repository.ProjectRepository;
import mvc.promiseme.project.repository.RoleRepository;
import mvc.promiseme.todo.dto.TodoRequestDTO;
import mvc.promiseme.todo.entity.Todo;
import mvc.promiseme.todo.repository.TodoRepository;
import mvc.promiseme.users.entity.Users;
import mvc.promiseme.users.repository.UserRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

@Service
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package mvc.promiseme.project.service;

import lombok.RequiredArgsConstructor;
import mvc.promiseme.project.dto.RecommendMemberRequestDTO;
import mvc.promiseme.project.dto.RecommendScheduleRequestDTO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class RecommendServiceImpl implements RecommendService{
private final RoleRepository roleRepository;
@Override
public Map<String, String> recommendMember(RecommendMemberRequestDTO recommendMemberRequestDTO) {
String url = clovaStudioRecommend.getUrl();
String apiKeyClovaStudio = clovaStudioRecommend.getApiKeyClovaStudio();

String requestId = clovaStudioRecommend.getRequestMemberId();

List<Message> messages = new ArrayList<>();

Expand All @@ -52,27 +50,7 @@ public Map<String, String> recommendMember(RecommendMemberRequestDTO recommendMe

Message requestMessage = new Message("user", "나는" + recommendMemberRequestDTO.getCategory() + "프로젝트를 진행할예정입니다. 시작날짜는" + recommendMemberRequestDTO.getStart() + ", 마감날짜는" + recommendMemberRequestDTO.getDeadline() + "입니다. 이때 필요한 팀의 구성원 역할을 알려주세요. 다른 말 필요없이\n\"역할\" : \"역할이 해야할일\"\n로만 대답해주세요. 다른 말 없이 역할과 역할이 해야할일만 작성해주세요.");
messages.add(requestMessage);

HttpHeaders headers = new HttpHeaders();
headers.set("X-NCP-CLOVASTUDIO-API-KEY", apiKeyClovaStudio);
headers.set("X-NCP-APIGW-API-KEY", clovaStudioRecommend.getApiGateWayKey());
headers.set("X-NCP-CLOVASTUDIO-REQUEST-ID", clovaStudioRecommend.getRequestMemberId());
headers.set("Content-Type", "application/json");

Map<String, Object> requestBody = new HashMap<>();
requestBody.put("messages", messages);
requestBody.put("topP", 0.8);
requestBody.put("topK", 0);
requestBody.put("maxTokens", 256);
requestBody.put("temperature", 0.5);
requestBody.put("repeatPenalty", 5.0);
requestBody.put("includeAiFilters", "True");

HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);

RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);

ResponseEntity<String> responseEntity = fetchClovaAPI(messages,requestId);
JsonObject jsonObject = JsonParser.parseString(responseEntity.getBody()).getAsJsonObject();
JsonObject messageObject = jsonObject.getAsJsonObject("result").getAsJsonObject("message");
String content = messageObject.get("content").getAsString();
Expand All @@ -93,10 +71,8 @@ public Map<String, String> recommendMember(RecommendMemberRequestDTO recommendMe
}
@Transactional
public List<Map<String, String>> recommendSchedule(RecommendScheduleRequestDTO recommendScheduleRequestDTO) {
String url = clovaStudioRecommend.getUrl();
String apiKeyClovaStudio = clovaStudioRecommend.getApiKeyClovaStudio();


String requestId = clovaStudioRecommend.getRequestScheduleId();

List<Message> messages = new ArrayList<>();

// 첫 번째 메시지
Expand Down Expand Up @@ -138,26 +114,8 @@ public List<Map<String, String>> recommendSchedule(RecommendScheduleRequestDTO r
"\"해야할 업무\" (시작날짜 ~ 마감날짜)로만 대답해주세요. 다른 말 없이 역할과 해야할 업무, 시작날짜, 마감날짜만 작성해주세요. 역할 앞에 숫자를 넣지 말고, 업무 앞에 -를 넣지 마세요. ");
messages.add(requestMessage);

HttpHeaders headers = new HttpHeaders();
headers.set("X-NCP-CLOVASTUDIO-API-KEY", apiKeyClovaStudio);
headers.set("X-NCP-APIGW-API-KEY", clovaStudioRecommend.getApiGateWayKey());
headers.set("X-NCP-CLOVASTUDIO-REQUEST-ID", clovaStudioRecommend.getRequestScheduleId());
headers.set("Content-Type", "application/json");

Map<String, Object> requestBody = new HashMap<>();
requestBody.put("messages", messages);
requestBody.put("topP", 0.8);
requestBody.put("topK", 0);
requestBody.put("maxTokens", 256);
requestBody.put("temperature", 0.5);
requestBody.put("repeatPenalty", 5.0);
requestBody.put("includeAiFilters", "True");

HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);

RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);

ResponseEntity<String> responseEntity = fetchClovaAPI(messages,requestId);

JsonObject jsonObject = JsonParser.parseString(responseEntity.getBody()).getAsJsonObject();
JsonObject messageObject = jsonObject.getAsJsonObject("result").getAsJsonObject("message");
String content = messageObject.get("content").getAsString();
Expand All @@ -178,7 +136,6 @@ public List<Map<String, String>> recommendSchedule(RecommendScheduleRequestDTO r
Matcher roleMatcher = roleRegex.matcher(role);

if (roleMatcher.matches()) {
String roleNumber = roleMatcher.group(1); // 1.
role = roleMatcher.group(2); // 기획자

// 숫자와 점을 제거한 role
Expand Down Expand Up @@ -259,6 +216,7 @@ public List<Map<String, String>> recommendSchedule(RecommendScheduleRequestDTO r

@Transactional
public void insertCalender(Long projectId, List<Map<String, String>> roleScheduleList) {

Project project = projectRepository.findById(projectId).orElseThrow(()->new NoSuchElementException("[ERROR] 해당하는 프로젝트가 존재하지 않습니다."));
for(Map<String,String> map : roleScheduleList){
Role r = new Role();
Expand All @@ -274,4 +232,31 @@ public void insertCalender(Long projectId, List<Map<String, String>> roleSchedul
}
}

public ResponseEntity<String> fetchClovaAPI(List<Message> messages, String requestId){
String url = clovaStudioRecommend.getUrl();
String apiKeyClovaStudio = clovaStudioRecommend.getApiKeyClovaStudio();
String apiGateWayKey = clovaStudioRecommend.getApiGateWayKey();

HttpHeaders headers = new HttpHeaders();
headers.set("X-NCP-CLOVASTUDIO-API-KEY", apiKeyClovaStudio);
headers.set("X-NCP-APIGW-API-KEY", apiGateWayKey);
headers.set("X-NCP-CLOVASTUDIO-REQUEST-ID", requestId);
headers.set("Content-Type", "application/json");

Map<java.lang.String, Object> requestBody = new HashMap<>();
requestBody.put("messages", messages);
requestBody.put("topP", 0.8);
requestBody.put("topK", 0);
requestBody.put("maxTokens", 256);
requestBody.put("temperature", 0.5);
requestBody.put("repeatPenalty", 5.0);
requestBody.put("includeAiFilters", "True");

HttpEntity<Map<java.lang.String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);

RestTemplate restTemplate = new RestTemplate();
return restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.http.ResponseEntity;
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.Map;
Expand Down

0 comments on commit 01db4f4

Please sign in to comment.