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

[#46] 내 문의 조회 기능 구현 #209

Merged
merged 7 commits into from
Sep 23, 2024
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 @@ -63,4 +63,12 @@ public BaseResponse<List<QuestionDto.QuestionListResponse>> getCompanyQuestions(
List<QuestionDto.QuestionListResponse> questionList = questionService.getQuestionsByCompanyEmail(companyEmail);
return new BaseResponse<>(questionList);
}

@Operation(summary = "로그인된 사용자의 문의 목록 조회 API", description = "로그인된 사용자가 작성한 문의 목록만 조회합니다.")
@GetMapping("/list/my")
public BaseResponse<List<QuestionDto.QuestionListResponse>> getMyQuestions(@AuthenticationPrincipal UserDetails userDetails) {
String userEmail = userDetails.getUsername(); // 인증된 사용자의 이메일 가져오기
List<QuestionDto.QuestionListResponse> questionList = questionService.getQuestionsByUserEmail(userEmail);
return new BaseResponse<>(questionList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public static class QuestionListResponse {
private LocalDateTime createdAt;
private String email;
private Long productBoardIdx;
private String productTitle;

private List<AnswerDto.AnswerResponse> answers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public QuestionDto.QuestionListResponse toListResponse() {
.email(this.user.getEmail())
.answers(answerResponses) // 답변 리스트 포함
.productBoardIdx(getProductBoard().getIdx())
.productTitle(getProductBoard().getTitle())

.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.example.backend.domain.board.model.entity.ProductBoard;
import org.example.backend.domain.qna.model.entity.Question;
import org.example.backend.domain.user.model.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface QuestionRepository extends JpaRepository<Question, Long> {
List<Question> findByProductBoardIn(List<ProductBoard> productBoards);
List<Question> findByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ public List<QuestionDto.QuestionListResponse> getQuestionsByCompanyEmail(String
.map(Question::toListResponse) // 엔티티의 변환 메서드 사용
.collect(Collectors.toList());
}

public List<QuestionDto.QuestionListResponse> getQuestionsByUserEmail(String userEmail) {
User user = userRepository.findByEmail(userEmail)
.orElseThrow(() -> new InvalidCustomException(BaseResponseStatus.QNA_USER_NOT_FOUND));

return questionRepository.findByUser(user).stream()
.map(Question::toListResponse) // 엔티티의 변환 메서드 사용
.collect(Collectors.toList());
}
}