Skip to content

Commit

Permalink
#92 DAILYLIFE2-46 by dm 2022.08.23
Browse files Browse the repository at this point in the history
  • Loading branch information
shihhhdm310 committed Aug 23, 2022
1 parent 05eed0b commit 5609c5c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -43,9 +44,8 @@ public ResponseEntity<Boolean> deleteBoard(@PathVariable("boardNum")Long boardNu
}
@ApiOperation(value = "페이징 게시글 가져오기", notes = "한 페이지 당 15개 게시글 가져옴, queryString 사용하여 pg(몇 페이지)는 필수로 넘겨주시고 query(검색어)는 있으면 채워서 보내주시면 됩니다(선택)")
@GetMapping("/getBoard")
public ResponseEntity<List<BoardCreateAndGetResponse>> list(@RequestParam(value = "pg", defaultValue = "1") int pg,@RequestParam(value = "keyword",defaultValue = "") String keyword, BoardPagination pagination) {
System.out.println(pagination.getKeyword());
return ResponseEntity.ok(boardService.getPage(pagination));
public ResponseEntity<List<BoardCreateAndGetResponse>> list(@RequestParam(value = "pg", defaultValue = "1") int pg, @RequestParam(value = "keyword",defaultValue = "") String keyword, BoardPagination pagination , HttpServletRequest httpServletRequest) {
return ResponseEntity.ok(boardService.getPage(pagination , httpServletRequest.getHeader("X-ACCESS-TOKEN")));
}

@ApiOperation(value = "전체 게시글 수 가져오기", notes = "등록된 게시물 수 가져오기")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface BoardService {

boolean delete(Long boardNum);

List<BoardCreateAndGetResponse> getPage(BoardPagination pagination);
List<BoardCreateAndGetResponse> getPage(BoardPagination pagination , String token);

int getBoardCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,40 @@ public boolean delete(Long boardNum) {
}

@Override
public List<BoardCreateAndGetResponse> getPage(BoardPagination pagination) {
String loginId = jwtService.getLoginId();
User user = userRepository.findByUserId(loginId);
Long uno = user.getUserNum();
List<BoardCreateAndGetResponse> BoardCreateAndGetResponseList = new ArrayList<>();
for (Board board : paginationRepository.findAll(pagination)) {

List<String> serverFileUrl = new ArrayList<>();
List<String> imageNameList = new ArrayList<>();
List<Image> byBoardBoardNum = imageRepository.findByBoardBoardNum(board.getBoardNum());
for (Image image : byBoardBoardNum) {
imageNameList.add(image.getImageName());
serverFileUrl.add(ServerUrl+image.getImageName());
public List<BoardCreateAndGetResponse> getPage(BoardPagination pagination , String token) {
List<BoardCreateAndGetResponse> BoardCreateAndGetResponseList;
if(token != null) {
String loginId = jwtService.getLoginId();
User user = userRepository.findByUserId(loginId);
Long uno = user.getUserNum();
BoardCreateAndGetResponseList = new ArrayList<>();
for (Board board : paginationRepository.findAll(pagination)) {
List<String> serverFileUrl = new ArrayList<>();
List<String> imageNameList = new ArrayList<>();
List<Image> byBoardBoardNum = imageRepository.findByBoardBoardNum(board.getBoardNum());
for (Image image : byBoardBoardNum) {
imageNameList.add(image.getImageName());
serverFileUrl.add(ServerUrl+image.getImageName());
}
BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl,heartService.getHeart(uno, board.getBoardNum())));
}
return BoardCreateAndGetResponseList;
}
else {
BoardCreateAndGetResponseList= new ArrayList<>();
for (Board board : paginationRepository.findAll(pagination)) {
List<String> serverFileUrl = new ArrayList<>();
List<String> imageNameList = new ArrayList<>();
List<Image> byBoardBoardNum = imageRepository.findByBoardBoardNum(board.getBoardNum());
for (Image image : byBoardBoardNum) {
imageNameList.add(image.getImageName());
serverFileUrl.add(ServerUrl+image.getImageName());
}
BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl, false));
}
BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl,heartService.getHeart(uno, board.getBoardNum())));
return BoardCreateAndGetResponseList;
}
return BoardCreateAndGetResponseList;

}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/dailylife/global/web/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public void addInterceptors(InterceptorRegistry registry) {
"/boardImg/**",
"/api/board/getBoardCount",
"/api/heart/countHeartReply/**",
"/api/heart/countHeartBoard/**");
"/api/heart/countHeartBoard/**"
,"/api/board/getBoard");


}
Expand Down

0 comments on commit 5609c5c

Please sign in to comment.