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

[fix] get question list 시 req application id 추가 #83

Merged
merged 1 commit into from
Sep 10, 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
Expand Up @@ -26,9 +26,9 @@ public ApiResponse<PreqResponseDto> saveCoverLetter(@RequestBody @Valid PreqRequ
return ApiResponse.success(SuccessCode.COVERLETTER_CREATE_SUCCESS, responseDto);
}

@GetMapping("/list")
public ApiResponse<List<CoverLetterResponseDto>> getList() {
List<CoverLetterResponseDto> responseDtoList = preqService.getPreqList();
@GetMapping("/list/{applicationId}")
public ApiResponse<List<CoverLetterResponseDto>> getList(@PathVariable Long applicationId) {
List<CoverLetterResponseDto> responseDtoList = preqService.getPreqList(applicationId);
return ApiResponse.success(SuccessCode.GET_SUCCESS, responseDtoList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.springframework.util.Assert;

import kr.co.preq.domain.application.entity.Application;
import kr.co.preq.domain.member.entity.Member;
import kr.co.preq.global.common.entity.BaseEntity;
import lombok.AccessLevel;
Expand All @@ -24,6 +25,9 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ApplicationChild extends BaseEntity {

@ManyToOne(fetch = FetchType.LAZY)
private Application application;

@ManyToOne(fetch = FetchType.LAZY)
private Member member;

Expand All @@ -42,14 +46,15 @@ public class ApplicationChild extends BaseEntity {
private List<String> abilities;

@Builder
ApplicationChild(Member member, String question, String answer, List<String> keywords, List<String> abilities) {
ApplicationChild(Application application, Member member, String question, String answer, List<String> keywords, List<String> abilities) {
Assert.notNull(application, "application must not be null");
Assert.notNull(member, "member must not be null");
Assert.notNull(question, "question must not be null");
Assert.notNull(answer, "answer must not be null");
Assert.notNull(keywords, "keywords must not be null");
Assert.notNull(abilities, "abilities must not be null");


this.application = application;
this.member = member;
this.question = question;
this.answer = answer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
import java.util.Optional;

public interface ApplicationChildRepository extends JpaRepository<ApplicationChild, Long> {
Optional<ApplicationChild> findCoverLetterById(Long cletterId);
List<ApplicationChild> findCoverLettersByMemberId(Long memberId);
Optional<ApplicationChild> findApplicationChildById(Long cletterId);
List<ApplicationChild> findApplicationChildByMemberIdAndApplicationId(Long memberId, Long applicationId);
}
6 changes: 3 additions & 3 deletions src/main/java/kr/co/preq/domain/preq/service/PreqService.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public PreqResponseDto saveCoverLetter(PreqRequestDto requestDto) {
}

@Transactional(readOnly = true)
public List<CoverLetterResponseDto> getPreqList() {
public List<CoverLetterResponseDto> getPreqList(Long applicationId) {
Member member = authService.findMember();

List<ApplicationChild> applicationChildren = applicationChildRepository.findCoverLettersByMemberId(member.getId());
List<ApplicationChild> applicationChildren = applicationChildRepository.findApplicationChildByMemberIdAndApplicationId(member.getId(), applicationId);
return applicationChildren.stream()
.map(preqMapper::toResponseDto)
.collect(Collectors.toList());
Expand All @@ -80,7 +80,7 @@ public List<CoverLetterResponseDto> getPreqList() {
public PreqResponseDto getPreq(Long achildId) {
Member member = authService.findMember();

ApplicationChild applicationChild = applicationChildRepository.findCoverLetterById(achildId)
ApplicationChild applicationChild = applicationChildRepository.findApplicationChildById(achildId)
.orElseThrow(() -> new CustomException(ErrorCode.NO_ID));

if (!member.equals(applicationChild.getMember())) throw new CustomException(ErrorCode.NOT_AUTHORIZED);
Expand Down