Skip to content

Commit

Permalink
Merge pull request #92 from dongkyun0713/dongkyun
Browse files Browse the repository at this point in the history
fix() : ์งˆ๋ฌธ ์‚ญ์ œ ์˜ค๋ฅ˜ ํ•ด๊ฒฐ
  • Loading branch information
dongkyun0713 authored Feb 26, 2024
2 parents 4ed0448 + caed92a commit 53b71c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.titto_backend.questionBoard.repository;

import com.example.titto_backend.questionBoard.domain.Answer;
import com.example.titto_backend.questionBoard.domain.Question;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AnswerRepository extends JpaRepository<Answer, Long> {
void deleteAllByQuestion(Question question);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.example.titto_backend.questionBoard.domain.Status;
import com.example.titto_backend.questionBoard.dto.QuestionDTO;
import com.example.titto_backend.questionBoard.dto.QuestionDTO.Response;
import com.example.titto_backend.questionBoard.repository.AnswerRepository;
import com.example.titto_backend.questionBoard.repository.QuestionRepository;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -31,6 +32,7 @@ public class QuestionService {

private final QuestionRepository questionRepository;
private final UserRepository userRepository;
private final AnswerRepository answerRepository;

private final ExperienceService experienceService;

Expand Down Expand Up @@ -113,7 +115,9 @@ private void validateAuthorIsLoggedInUser(Long id, Long userId) {
.orElseThrow(() -> new CustomException(ErrorCode.QUESTION_NOT_FOUND));

isAcceptAnswer(question, user);
if (question.getAuthor().getId().equals(user.getId())) {

answerRepository.deleteAllByQuestion(question);
if (!question.getAuthor().getId().equals(user.getId())) {
throw new CustomException(ErrorCode.MISMATCH_AUTHOR);
}
}
Expand Down

0 comments on commit 53b71c4

Please sign in to comment.