질문과 답변 영역을 맡게 되었다.
현재 질문 조회기능을 추가하였다.
추가하기 위해서 QuestionListResponseDto 클래스를 넣었다.
package kr.ac.cnu.swacademy.cagong.dto;
import kr.ac.cnu.swacademy.cagong.entity.Question;
import lombok.Getter;
import java.time.LocalDateTime;
@Getter
public class QuestionListResponseDto {
private Long id;
private String title;
private LocalDateTime createdAt;
public QuestionListResponseDto(Question entity){
this.id = entity.getId();
this.title = entity.getTitle();
this.createdAt = entity.getCreatedAt();
}
}
QuestionController 클래스에 @GetMapping을 추가하였다.
@GetMapping("/question")
public String questionList(Model model){
model.addAttribute("questionList", questionService.findAllDesc());
return "question/questionList";
}
@GetMapping
public String question(@PathVariable Long id, Model model){
model.addAttribute("question", questionService.findById(id));
return "question/detail";
}
QuestionService에도 코드를 추가했다.
@Transactional(readOnly = true)
public List<QuestionListResponseDto> findAllDesc(){
return questionRepository.findAllDesc().stream()
.map(QuestionListResponseDto::new)
.collect(Collectors.toList());
}
'CNU_SW_모각코' 카테고리의 다른 글
15주차 모각코 학습 결과(22.10.12 14:00 ~ 17:00) (0) | 2022.10.25 |
---|---|
15주차 모각코 학습 목표(22.10.12 14:00 ~ 17:00) (0) | 2022.10.25 |
14주차 모각코 학습 목표(22.10.05 14:00 ~ 17:00) (0) | 2022.10.06 |
13주차 모각코 학습 결과(22.09.28 13:30 ~ 16:30) (1) | 2022.10.01 |
13주차 모각코 학습 목표(22.09.28 13:30 ~ 16:30) (0) | 2022.09.28 |