Skip to content
Open
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
12 changes: 7 additions & 5 deletions src/main/java/codesquad/controller/QuestionController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package codesquad.controller;

import java.util.List;
import java.util.NoSuchElementException;

import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -32,7 +33,8 @@ public String getForm() {
@GetMapping("/")
// @RequestMapping(value = "/", method = RequestMethod.GET)
public String list(Model model) {
model.addAttribute("questions", questionRepository.findAllByState(true));
List<Question> notDeletedQuestion = questionRepository.findNotDeletedStateQuestion(true);
model.addAttribute("questions", notDeletedQuestion);
return "index";
}

Expand Down Expand Up @@ -86,14 +88,14 @@ public String update(@PathVariable Long index, Question updatedQuestion, HttpSes
public String delete(@PathVariable Long index, HttpSession session) {
User sessionedUser = (User) session.getAttribute("sessionedUser");
Question question = questionRepository.findById(index).orElseThrow(NoSuchElementException::new);
if(!question.isSameWriter(sessionedUser)){
return "redircet:/questions/{index}";
}

if(sessionedUser == null) {
return "redirect:/login";
}

if(!question.isSameWriter(sessionedUser)){
return "redircet:/questions/{index}";
}

if(!question.checkEmptyAnswerList()){
if(!question.checkExistAnotherAnswerWriter(sessionedUser)){
return "redircet:/questions/{index}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package codesquad.domain.question;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

public interface QuestionRepository extends JpaRepository<Question, Long> {
Question findAllByState(boolean state);
List<Question> findNotDeletedStateQuestion(boolean state);

}