Skip to content

Commit

Permalink
feat : 질문 리스트 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
programmerDH-github committed Aug 18, 2023
1 parent 9b18bb9 commit 0e21a5e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 60 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.util.List;

import com.bside.BSIDE.contents.domain.*;
import org.apache.ibatis.annotations.Mapper;

import com.bside.BSIDE.contents.domain.CountAnsweredQuestionsByMonthDto;
import com.bside.BSIDE.contents.domain.QuestionAndAnswerDto;
import com.bside.BSIDE.contents.domain.QuestionCountDto;
import com.bside.BSIDE.contents.domain.QuestionDto;


@Mapper
public interface QuestionMapper {
Expand All @@ -23,6 +27,7 @@ public interface QuestionMapper {
List<QuestionAndAnswerDto> getQuestionsAndAnswersByMonthAndEmail(String email, String date);
List<QuestionAndAnswerDto> getQuestionsAndAnswersByDayAndEmail(String email, String date);

List<QuestionDto> selectListQuestion(QuestionListInDto questionListInDto);
List<QuestionDto> selectListQuestion();
// List<QuestionDto> selectListQuestion(QuestionListInDto questionListInDto);
// List<QuestionDto> selectListQuestion(int pageNo, int pageSize);
}
64 changes: 45 additions & 19 deletions src/main/java/com/bside/BSIDE/contents/web/QuestionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
import java.util.List;
import java.util.Map;

import com.bside.BSIDE.contents.domain.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bside.BSIDE.contents.domain.CountAnsweredQuestionsByMonthDto;
import com.bside.BSIDE.contents.domain.PagedResponse;
import com.bside.BSIDE.contents.domain.QuestionAndAnswerDto;
import com.bside.BSIDE.contents.domain.QuestionCountDto;
import com.bside.BSIDE.contents.domain.QuestionDto;
import com.bside.BSIDE.service.QuestionService;

import io.swagger.v3.oas.annotations.Operation;

/**
Expand Down Expand Up @@ -160,25 +176,35 @@ else if (dateArr.length == 2) {
}

}

/* 질문 리스트 조회 */
@GetMapping("/questions")
@Operation(summary = "질문 리스트 조회")
public ResponseEntity<?> getQuestions(@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "15") int size) {

List<QuestionDto> question = questionService.selectListQuestion();

System.out.println(question);

if (page > 0) {
// 페이징 처리를 위한 Pageable 생성
int totalElements = question.size();
int totalPages = (int) Math.ceil((double) totalElements / size);
int currentPage = Math.min(Math.max(1, page), totalPages);
int startIndex = (currentPage - 1) * size;
int endIndex = Math.min(startIndex + size, totalElements);

@PostMapping("/getETCQuestionList")
@ResponseBody
@Operation(summary = "등록되어져 있는 질문 목록 조회")
public ResponseEntity<?> selectListQuestion(@RequestBody QuestionListInDto questionListInDto) {
System.out.println("------- questionListInDto :: ---- " + questionListInDto);
List<QuestionDto> outDto;
QuestionListOutDto output = new QuestionListOutDto();
try {
outDto = questionService.selectListQuestion(questionListInDto);
System.out.println(outDto);
output.setGrid(outDto);
// output.getClass().getField("grid").set(outDto);
} catch (Exception e) {
// return ResponseEntity.ok(e);
System.out.println(e);
return ResponseEntity.status(400).build();
// 해당 페이지에 맞게 데이터 분할
List<QuestionDto> pageContent = question.subList(startIndex, endIndex);

// PagedResponse 객체 생성
PagedResponse<QuestionDto> pagedResponse = new PagedResponse<>(pageContent, currentPage, size,
totalElements);
return ResponseEntity.ok(pagedResponse);
} else {
return ResponseEntity.ok(question);
}
return ResponseEntity.ok(output);

}
}
7 changes: 5 additions & 2 deletions src/main/java/com/bside/BSIDE/service/QuestionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import java.util.List;

import com.bside.BSIDE.contents.domain.*;
import com.bside.BSIDE.contents.domain.CountAnsweredQuestionsByMonthDto;
import com.bside.BSIDE.contents.domain.QuestionAndAnswerDto;
import com.bside.BSIDE.contents.domain.QuestionCountDto;
import com.bside.BSIDE.contents.domain.QuestionDto;

public interface QuestionService {
void insertQuestion(QuestionDto questionDto);
Expand All @@ -20,5 +23,5 @@ public interface QuestionService {
List<QuestionAndAnswerDto> getQuestionsAndAnswersByMonthAndEmail(String email, String date);
List<QuestionAndAnswerDto> getQuestionsAndAnswersByDayAndEmail(String email, String date);

List<QuestionDto> selectListQuestion(QuestionListInDto input);
List<QuestionDto> selectListQuestion();
}
18 changes: 6 additions & 12 deletions src/main/java/com/bside/BSIDE/service/QuestionServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import java.util.List;

import com.bside.BSIDE.contents.domain.*;
import org.springframework.stereotype.Service;

import com.bside.BSIDE.contents.domain.CountAnsweredQuestionsByMonthDto;
import com.bside.BSIDE.contents.domain.QuestionAndAnswerDto;
import com.bside.BSIDE.contents.domain.QuestionCountDto;
import com.bside.BSIDE.contents.domain.QuestionDto;
import com.bside.BSIDE.contents.persistence.QuestionMapper;

@Service
Expand Down Expand Up @@ -78,17 +81,8 @@ public List<QuestionAndAnswerDto> getQuestionsAndAnswersByDayAndEmail(String ema
}

@Override
public List<QuestionDto> selectListQuestion(QuestionListInDto input) {
int pageNo = input.getPageNo();
int pageSize = input.getPageSize();
QuestionListInDto inDto = new QuestionListInDto();
inDto.setPageNo(pageNo);
inDto.setPageSize(pageSize);
System.out.println("serviceImpl ------- pageNo: " + pageNo + " pageSize: " + pageSize);
List<QuestionDto> list = questionMapper.selectListQuestion(inDto);
System.out.println("serviceImpl ------- end");
System.out.println(list);
return list;
public List<QuestionDto> selectListQuestion() {
return questionMapper.selectListQuestion();
}

}
Expand Down
15 changes: 3 additions & 12 deletions src/main/resources/sqlmap/mapper/question/QuestionMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,10 @@
</select>

<!-- 질문목록 조회 -->
<select id="selectListQuestion"
resultType="com.bside.BSIDE.contents.domain.QuestionDto"
parameterType="com.bside.BSIDE.contents.domain.QuestionListInDto" >
SELECT
q_no as qNo
,q_question as qQuestion
, q_category as qCategory
, q_writer as qWriter
, q_created_at as qCreatedAt
FROM question
<select id="selectListQuestion" resultType="com.bside.BSIDE.contents.domain.QuestionDto">
SELECT q_no AS qNo, q_question AS qQuestion, q_category AS qCategory, q_writer AS qWriter, q_created_at AS qCreatedAt
FROM bside.question
ORDER BY q_created_at DESC
LIMIT #{pageSize}
OFFSET #{pageNo} - 1
</select>

</mapper>

0 comments on commit 0e21a5e

Please sign in to comment.