Skip to content

Commit

Permalink
Merge pull request #95 from Chat-ITC/main
Browse files Browse the repository at this point in the history
feat: language의 id값으로 question 저장하는 로직 구현
  • Loading branch information
YongGoose authored Sep 22, 2023
2 parents d494e06 + 0997323 commit d50b460
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public ResponseEntity<QuestionRequestDto> saveQuestion(
.body(questionRequestDto);
}

@PostMapping("/question/save/id/{id}")
public ResponseEntity<QuestionRequestDto> saveQuestion(
@PathVariable Long id,
@RequestBody QuestionRequestDto questionRequestDto) {
questionService.saveQuestionById(questionRequestDto,id);

return ResponseEntity.ok()
.body(questionRequestDto);
}

@GetMapping("/question/get/language") // language를 이용해서 Question을 조회 *Question -> Language (many to one)
public ResponseEntity<?> getQuestionTitleFromLanguage(
@AuthenticationPrincipal MemberPrincipal memberPrincipal) throws UnsupportedEncodingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ public void saveQuestion(QuestionRequestDto questionRequestDto, String type) {
questionRepository.save(question);
}

@Transactional
public void saveQuestionById(QuestionRequestDto questionRequestDto, Long id) {
Language language = languageRepository.findLanguageById(id).orElseThrow(
() -> new CustomException(HttpStatus.BAD_REQUEST, "language가 존재하지 않습니다."));

Question question = Question.builder()
.title(questionRequestDto.getTitle())
.content(questionRequestDto.getContent())
.answer(questionRequestDto.getAnswer())
.language(language)
.level(questionRequestDto.getLevel())
.build();
questionRepository.save(question);
}

public List<QuestionTitleResponseDto> findRandomQuestionsByLanguage(String type, String level) {
Language language = languageRepository.findLanguageByType(type).orElseThrow(
() -> new CustomException(HttpStatus.BAD_REQUEST, "language가 존재하지 않습니다."));
Expand Down

0 comments on commit d50b460

Please sign in to comment.