-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ [Feat] 유저의 입력 값 바탕 제일 높은 가중치의 개발자 3명 반환하는 API #151
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
500b88b
:sparkles: [Feat] 팀원매칭 봇 API 구현
88dldl bb28103
:sparkles: [Feat] 유저의 입력 값 바탕 높은 가중치 developer 반환
88dldl 7eaf64a
Merge branch 'develop' of https://github.com/SSU-Plector/SSU-Plector-…
88dldl 6073af7
:art: openai 설정경로 수정
88dldl 5362ea8
:wrench: [Add] valid 추가
88dldl 2adcb70
:wrench: [Update] 가중치 변경
88dldl e9998f7
Revert ":art: openai 설정경로 수정"
88dldl bd8782f
:wrench: [Add] openai 설정경로(image) local 추가
88dldl 7f2c7ba
:wrench: [Update] 가중치 수정
88dldl d9c20cb
:wrench: [Add] developer 존재하지 않을시 에러처리
88dldl bc9f33e
:wrench: [Add] map상 null로 존재할 시 값 0.0으로 세팅
88dldl 1aaf5f1
:wrench: [Refactor] 학번 String -> Long으로 입력받기
88dldl 2044dfe
:wrench: [Add] part2 검사 추가
88dldl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
src/main/java/ssuPlector/repository/developer/DeveloperRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
package ssuPlector.repository.developer; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import ssuPlector.domain.Developer; | ||
import ssuPlector.domain.category.Part; | ||
import ssuPlector.dto.request.DeveloperDTO.DeveloperMatchingDTO; | ||
|
||
public interface DeveloperRepositoryCustom { | ||
|
||
Page<Developer> findDevelopers(String sortType, Part part, Pageable pageable); | ||
|
||
List<Developer> searchDeveloper(String developerName); | ||
|
||
Map<Long, Double> matchDeveloper(String developerInfo, DeveloperMatchingDTO requestDTO); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
package ssuPlector.service.developer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import ssuPlector.aws.s3.AmazonS3Manager; | ||
import ssuPlector.converter.DeveloperConverter; | ||
|
@@ -23,6 +38,7 @@ | |
import ssuPlector.domain.category.TechStack; | ||
import ssuPlector.dto.request.DeveloperDTO; | ||
import ssuPlector.dto.request.DeveloperDTO.DeveloperListRequestDTO; | ||
import ssuPlector.dto.request.DeveloperDTO.DeveloperMatchingDTO; | ||
import ssuPlector.dto.request.DeveloperDTO.DeveloperRequestDTO; | ||
import ssuPlector.dto.request.DeveloperDTO.DeveloperUpdateRequestDTO; | ||
import ssuPlector.dto.response.DeveloperDTO.DeveloperSearchDTO; | ||
|
@@ -42,6 +58,9 @@ public class DeveloperServiceImpl implements DeveloperService { | |
private final AmazonS3Manager s3Manager; | ||
private final UuidRepository uuidRepository; | ||
|
||
@Value("${sp.ai.url}") | ||
private String aiUrl; | ||
|
||
@Override | ||
@Transactional | ||
public Long createDeveloper(String email, DeveloperRequestDTO requestDTO) { | ||
|
@@ -137,4 +156,73 @@ public List<DeveloperSearchDTO> searchDeveloper(String developerName) { | |
List<Developer> developers = developerRepository.searchDeveloper(developerName); | ||
return developers.stream().map(DeveloperConverter::toDeveloperSearchDTO).toList(); | ||
} | ||
|
||
@Override | ||
public List<DeveloperSearchDTO> matchDeveloper( | ||
String developerInfo, DeveloperMatchingDTO requestDTO) { | ||
// request | ||
RestTemplate restTemplate = new RestTemplate(); | ||
HttpHeaders headers = new HttpHeaders(); | ||
|
||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
String requestBody = | ||
String.format( | ||
"{\"part\":\"%s\", \"request\":\"%s\"}", | ||
requestDTO.getPart(), developerInfo); | ||
|
||
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers); | ||
|
||
ResponseEntity<String> response = | ||
restTemplate.exchange(aiUrl, HttpMethod.POST, requestEntity, String.class); | ||
|
||
// response | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
List<Long> developerIds = new ArrayList<>(); | ||
try { | ||
JsonNode developersNode = objectMapper.readTree(response.getBody()).path("developers"); | ||
Iterator<JsonNode> elements = developersNode.elements(); | ||
while (elements.hasNext()) { | ||
Long developerId = elements.next().path("developer_id").asLong(); | ||
developerIds.add(developerId); | ||
} | ||
} catch (JsonProcessingException e) { | ||
throw new GlobalException(GlobalErrorCode.INVALID_REQUEST_INFO); | ||
} | ||
|
||
Map<Long, Double> weight = developerRepository.matchDeveloper(developerInfo, requestDTO); | ||
|
||
double w = 0.0; | ||
for (Long developerId : developerIds) { | ||
Developer developer = | ||
developerRepository | ||
.findById(developerId) | ||
.orElseThrow( | ||
() -> new GlobalException(GlobalErrorCode.DEVELOPER_NOT_FOUND)); | ||
|
||
weight.put(developer.getId(), weight.get(developer.getId()) + w); | ||
w -= 0.3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSON 데이터를 읽어오는 과정이 복잡하긴 하지만 각 개발자들의 매칭 정도를 가중치로 표현해서 정렬하는 좋은 방식인 것 같습니다. 오류 부분을 수정하고 나서 머지하면 될 것 같습니다. 수고하셨습니다 |
||
} | ||
|
||
// sort | ||
List<Pair<Long, Double>> sortedDeveloper = | ||
weight.entrySet().stream() | ||
.map(entry -> Pair.of(entry.getKey(), entry.getValue())) | ||
.sorted((p1, p2) -> p2.getValue().compareTo(p1.getValue())) | ||
.toList(); | ||
|
||
List<Developer> developerList = | ||
sortedDeveloper.stream() | ||
.limit(3) | ||
.map( | ||
m -> { | ||
Optional<Developer> optionalDeveloper = | ||
developerRepository.findById(m.getLeft()); | ||
return optionalDeveloper.orElseThrow( | ||
() -> | ||
new GlobalException( | ||
GlobalErrorCode.DEVELOPER_NOT_FOUND)); | ||
}) | ||
.toList(); | ||
return developerList.stream().map(DeveloperConverter::toDeveloperSearchDTO).toList(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
part1만 조회하는 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아니요.. 그냥 제가 까먹은겁니다 ... 추가하도록 할게요!!