Skip to content
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] 지원서 개별 조회 API #103

Merged
merged 6 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.co.preq.domain.application.controller;

import kr.co.preq.domain.application.dto.response.ApplicationGetResponseDto;
import kr.co.preq.domain.application.dto.response.ApplicationListGetResponseDto;
import kr.co.preq.domain.application.dto.request.ApplicationMemoUpdateRequestDto;
import kr.co.preq.domain.application.dto.request.ApplicationTitleUpdateRequestDto;
Expand Down Expand Up @@ -49,4 +50,11 @@ public ApiResponse<Object> updateApplicationMemo(@PathVariable Long applicationI

return ApiResponse.success(SuccessCode.APPLICATION_MEMO_UPDATE_SUCCESS);
}

@GetMapping("/{applicationId}")
public ApiResponse<ApplicationGetResponseDto> getDetailApplication(@PathVariable Long applicationId) {
ApplicationGetResponseDto application = applicationService.getDetailApplication(applicationId);

return ApiResponse.success(SuccessCode.APPLICATION_GET_SUCCESS, application);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kr.co.preq.domain.application.dto.response;

import kr.co.preq.domain.applicationChild.dto.response.ApplicationChildResponseDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Getter
@NoArgsConstructor(access = PRIVATE)
@AllArgsConstructor
@Builder
public class ApplicationGetResponseDto {
private Long id;
private String title;
private String memo;
private List<ApplicationChildResponseDto> applicationChild;
private List<String> keywordTop5;
private List<String> softSkills;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package kr.co.preq.domain.application.entity;

import kr.co.preq.domain.applicationChild.entity.StringListConverter;
import kr.co.preq.domain.member.entity.Member;
import kr.co.preq.global.common.entity.BaseEntity;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

import java.util.List;

import static lombok.AccessLevel.PROTECTED;

@Entity
Expand All @@ -25,6 +27,14 @@ public class Application extends BaseEntity {
@ManyToOne
private Member member;

@Column
@Convert(converter = StringListConverter.class)
private List<String> keywords;

@Column
@Convert(converter = StringListConverter.class)
private List<String> abilities;

@Builder
public Application(String title, String memo, Member member) {
this.title = title;
Expand All @@ -39,4 +49,12 @@ public void updateTitle(String title) {
public void updateMemo(String memo) {
this.memo = memo;
}

public void updateKeywords(List<String> keywords) {
this.keywords = keywords;
}

public void updateAbilities(List<String> abilities) {
this.abilities = abilities;
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
package kr.co.preq.domain.application.service;

import kr.co.preq.domain.application.dto.response.ApplicationGetResponseDto;
import kr.co.preq.domain.application.dto.response.ApplicationListGetResponseDto;
import kr.co.preq.domain.application.dto.request.ApplicationMemoUpdateRequestDto;
import kr.co.preq.domain.application.dto.request.ApplicationTitleUpdateRequestDto;
import kr.co.preq.domain.application.entity.Application;
import kr.co.preq.domain.application.repository.ApplicationRepository;
import kr.co.preq.domain.applicationChild.dto.response.ApplicationChildResponseDto;
import kr.co.preq.domain.applicationChild.entity.ApplicationChild;
import kr.co.preq.domain.applicationChild.repository.ApplicationChildRepository;
import kr.co.preq.domain.auth.service.AuthService;
import kr.co.preq.domain.member.entity.Member;
import kr.co.preq.domain.preq.dto.request.KeywordAndSoftskillsRequestDto;
import kr.co.preq.domain.preq.dto.response.KeywordAndSoftskillsResponseDto;
import kr.co.preq.domain.preq.service.PreqService;
import kr.co.preq.global.common.util.exception.BadRequestException;
import kr.co.preq.global.common.util.response.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Transactional
public class ApplicationService {
private final ApplicationRepository applicationRepository;
private final AuthService authService;

private final PreqService preqService;
private final ApplicationChildRepository applicationChildRepository;

public Long createApplication() {
String title = "지원서 제목";
String memo = "메모";

Member member = authService.findMember();

Application application = new Application(title, memo, member);
Expand All @@ -34,7 +46,7 @@ public Long createApplication() {
return application.getId();
}

@Transactional
@Transactional(readOnly = true)
public List<ApplicationListGetResponseDto> getApplicationList() {
Member member = authService.findMember();
Long memberId = member.getId();
Expand All @@ -47,18 +59,62 @@ public List<ApplicationListGetResponseDto> getApplicationList() {
@Transactional
public void updateApplicationTitle(Long applicationId, ApplicationTitleUpdateRequestDto requestDto) {
Member member = authService.findMember();
Application application = applicationRepository.findByIdAndMemberId(applicationId, member.getId())
.orElseThrow(() -> new BadRequestException(ErrorCode.BAD_PARAMETER));
Long memberId = member.getId();
Application application = getApplication(applicationId, memberId);

application.updateTitle(requestDto.getTitle());
}

@Transactional
public void updateApplicationMemo(Long applicationId, ApplicationMemoUpdateRequestDto requestDto) {
Member member = authService.findMember();
Application application = applicationRepository.findByIdAndMemberId(applicationId, member.getId())
.orElseThrow(() -> new BadRequestException(ErrorCode.BAD_PARAMETER));
Long memberId = member.getId();
Application application = getApplication(applicationId, memberId);

application.updateMemo(requestDto.getMemo());
}

@Transactional(readOnly = true)
public ApplicationGetResponseDto getDetailApplication(Long applicationId) {
Member member = authService.findMember();
Long memberId = member.getId();

Application application = getApplication(applicationId, memberId);

List<ApplicationChildResponseDto> applicationChild = applicationChildRepository.findApplicationChildByApplicationIdAndMemberIdOrderByCreatedAt(applicationId, memberId).stream()
.map(aChild -> ApplicationChildResponseDto.of(aChild.getId(), aChild.getQuestion(), aChild.getAnswer()))
.collect(Collectors.toList());

StringBuilder allAnswer = new StringBuilder();
for (ApplicationChild answer : applicationChildRepository.findApplicationChildByApplicationIdAndMemberIdOrderByCreatedAt(applicationId, memberId)) {
allAnswer.append(answer.getAnswer());
}

// extract keywords
KeywordAndSoftskillsResponseDto keywordAndSoftskillsInfo = preqService.sendRequestToFlask(KeywordAndSoftskillsRequestDto.builder()
.application(allAnswer.toString())
.build());

// update application keywords and abilities
application.updateKeywords(keywordAndSoftskillsInfo.getData().getKeywordTop5());
application.updateAbilities(keywordAndSoftskillsInfo.getData().getSoftSkills()
.stream().map(String::valueOf).collect(Collectors.toList()));

List<String> resultKeywords = application.getKeywords();
List<String> resultAbilities = application.getAbilities();

return ApplicationGetResponseDto.builder()
.id(application.getId())
.title(application.getTitle())
.memo(application.getMemo())
.applicationChild(applicationChild)
.keywordTop5(resultKeywords)
.softSkills(resultAbilities)
.build();
}

private Application getApplication(Long applicationId, Long memberId) {
return applicationRepository.findByIdAndMemberId(applicationId, memberId)
.orElseThrow(() -> new BadRequestException(ErrorCode.BAD_PARAMETER));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import java.util.ArrayList;
import java.util.List;

import kr.co.preq.domain.applicationChild.dto.response.ApplicationChildInfoResponseDto;
import kr.co.preq.domain.applicationChild.dto.response.ApplicationChildListResponseDto;
import org.springframework.stereotype.Component;

import kr.co.preq.domain.applicationChild.entity.ApplicationChild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public class ApplicationChildResponseDto {
private Long applicationChildId;
private String question;
private String answer;

public static ApplicationChildResponseDto of(Long applicationChildId, String question, String answer) {
return new ApplicationChildResponseDto(applicationChildId, question, answer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@

public interface ApplicationChildRepository extends JpaRepository<ApplicationChild, Long> {
Optional<ApplicationChild> findApplicationChildByIdAndApplicationIdAndMemberId(Long id, Long applicationId, Long memberId);

List<ApplicationChild> findByApplicationId(Long applicationId);

List<ApplicationChild> findApplicationChildByApplicationIdAndMemberIdOrderByCreatedAt(Long applicationId, Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ public class PreqService {
private final PreqRepository preqRepository;
private final ApplicationChildRepository applicationChildRepository;
private final OpenAIService openAIService;
private final AuthService authService;
private final PreqMapper preqMapper;

@Value("${flask.url}") private String FLASK_URL;




@Transactional
public PreqAndKeywordResponseDto createPreqAndKeyword(Long applicationChildId) {

Expand Down Expand Up @@ -92,7 +88,7 @@ public PreqAndKeywordResponseDto createPreqAndKeyword(Long applicationChildId) {
return preqMapper.toResponseDto(cutQuestions, keywordAndSoftskillsInfo);
}

private KeywordAndSoftskillsResponseDto sendRequestToFlask(KeywordAndSoftskillsRequestDto requestDto) {
public KeywordAndSoftskillsResponseDto sendRequestToFlask(KeywordAndSoftskillsRequestDto requestDto) {
try {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-type", "application/json; charset=UTF-8");
Expand All @@ -109,5 +105,4 @@ private KeywordAndSoftskillsResponseDto sendRequestToFlask(KeywordAndSoftskillsR
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum SuccessCode {
// 지원서
APPLICATION_CREATE_SUCCESS(CREATED, "지원서 생성 성공"),
APPLICATION_LIST_GET_SUCCESS(OK, "지원서 리스트 조회 성공"),
APPLICATION_GET_SUCCESS(OK, "지원서 상세 조회 성공"),
APPLICATION_TITLE_UPDATE_SUCCESS(OK, "지원서 제목 수정 성공"),
APPLICATION_MEMO_UPDATE_SUCCESS(OK, "지원서 메모 수정 성공");

Expand Down