Skip to content

Commit

Permalink
Merge pull request #101 from dailylifev1/dm
Browse files Browse the repository at this point in the history
#100 DAILYLIFE2-51 by dm
  • Loading branch information
shihhhdm310 authored Aug 24, 2022
2 parents ec76f7a + 062ff38 commit 6aaeb58
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ public ResponseEntity<Boolean> deleteBoard(@PathVariable("boardNum")Long boardNu

return ResponseEntity.ok(boardService.delete(boardNum));
}

@ApiOperation(value = "페이징 게시글 가져오기 (비로그인용)", notes = "페이징 게시글 가져오기 (비로그인용)")
@GetMapping("/getBoardNotLogin")
public ResponseEntity<List<BoardCreateAndGetResponse>> boardList(@RequestParam(value = "pg", defaultValue = "1") int pg, @RequestParam(value = "keyword",defaultValue = "") String keyword, BoardPagination pagination) {
return ResponseEntity.ok(boardService.getPageNotLogin(pagination));
}

@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 , HttpServletRequest httpServletRequest) {
return ResponseEntity.ok(boardService.getPage(pagination , httpServletRequest.getHeader("X-ACCESS-TOKEN")));
public ResponseEntity<List<BoardCreateAndGetResponse>> list(@RequestParam(value = "pg", defaultValue = "1") int pg, @RequestParam(value = "keyword",defaultValue = "") String keyword, BoardPagination pagination) {
return ResponseEntity.ok(boardService.getPage(pagination));
}

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

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotBlank;
Expand All @@ -15,6 +12,7 @@
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "게시물 생성을 위한 요청 객체")
@Builder
public class BoardCreateRequest {

@NotBlank(message = "게시물 제목을 입력해주세요")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public interface BoardService {

boolean delete(Long boardNum);

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

int getBoardCount();

List<Board> TitleList(BoardPagination pagination);

List<BoardCreateAndGetResponse> getPageNotLogin(BoardPagination pagination);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,42 +79,44 @@ public boolean delete(Long boardNum) {
}

@Override
public List<BoardCreateAndGetResponse> getPage(BoardPagination pagination , String token) {
public List<BoardCreateAndGetResponse> getPage(BoardPagination pagination) {
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())));
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());
}
return BoardCreateAndGetResponseList;
BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl,heartService.getHeart(uno, board.getBoardNum())));
}
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));
return BoardCreateAndGetResponseList;
}

@Override
public List<BoardCreateAndGetResponse> getPageNotLogin(BoardPagination pagination) {
List<BoardCreateAndGetResponse> BoardCreateAndGetResponseList;
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());
}
return BoardCreateAndGetResponseList;
BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl,false));
}
return BoardCreateAndGetResponseList;

}


@Override
public int getBoardCount() {
return boardRepository.countAllByBoardNum();
Expand All @@ -124,4 +126,6 @@ public int getBoardCount() {
public List<Board> TitleList(BoardPagination pagination) {
return paginationRepository.findTitle(pagination);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@ public class HeartController {
@ApiOperation(value = "댓글 좋아요", notes = "replyNum값(tbl_reply)PK값만 넘겨주시면 됩니다. 한 번 누르면 좋아요 / 2번 클릭 시 좋아요 취소")
@PostMapping("/replyHeartPlus")
public ResponseEntity<Boolean> replyHeartPlus(@Valid @RequestBody HeartStateRequest heartStateRequest){
System.out.println("댓글 좋아요");
return ResponseEntity.ok(heartService.heartPlusReply(heartStateRequest));
}

@ApiOperation(value="게시글 좋아요", notes = "boardNum값(tbl_board)PK값 넘겨주시면 됩니다. 한 번 누르면 좋아요 / 2번 클릭 시 좋아요 취소")
@PostMapping("/boardHeartPlus")
public ResponseEntity<Boolean> boardHeartPlus(@Valid @RequestBody HeartStateRequest heartStateRequest){
System.out.println("게시글 좋아요");
return ResponseEntity.ok(heartService.heartPlusBoard(heartStateRequest));
}

@ApiOperation(value="대댓글 좋아요", notes = "replyReplyNum(tbl_replyReply)(대댓글)PK값 넘겨주시면 됩니다. 한 번 누르면 좋아요 / 2번 클릭 시 좋아요 취소")
@PostMapping("/replyReplyHeartPlus")
public ResponseEntity<Boolean> replyReplyHeartPlus(@Valid @RequestBody HeartStateRequest heartStateRequest){
System.out.println("대댓글 좋아요");
return ResponseEntity.ok(heartService.heartPlusReplyReply(heartStateRequest));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public boolean heartPlusReply(HeartStateRequest heartStateRequest) {
if(heartRepository.countByReplyReplyNumAndUserNum(reply.getReplyNum(), user.getUserNum()) == 0){
heartStateRequest.setHeartState(1L);
Heart heart = heartRepository.save(Heart.toEntityReply(heartStateRequest, reply));
return true;
}
else {
heartRepository.deleteByReplyReplyNumAndUserNum(reply.getReplyNum(), user.getUserNum());
return false;
}
return true;

}
/*게시글 좋아요*/
Expand All @@ -52,10 +53,11 @@ public boolean heartPlusBoard(HeartStateRequest heartStateRequest) {
if(heartRepository.countByBoardBoardNumAndUserNum(board.getBoardNum(),user.getUserNum())==0){
heartStateRequest.setHeartState(1L);
Heart heart = heartRepository.save(Heart.toEntityBoard(heartStateRequest,board));
return true;
}else {
heartRepository.deleteByBoardBoardNumAndUserNum(board.getBoardNum(), user.getUserNum());
return false;
}
return true;
}

/*대댓글 좋아요*/
Expand All @@ -69,10 +71,12 @@ public boolean heartPlusReplyReply(HeartStateRequest heartStateRequest) {
if(heartRepository.countByCommentReplyReplyNumAndUserNum(comment.getReplyReplyNum(),user.getUserNum())==0){
heartStateRequest.setHeartState(1L);
Heart heart = heartRepository.save(Heart.toEntityReplyReply(heartStateRequest, comment));
return true;
}else{
heartRepository.deleteByCommentReplyReplyNumAndUserNum(comment.getReplyReplyNum(),user.getUserNum());
return false;
}
return true;

}

/*댓글 좋아요 총 개수 출력*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class FileServiceImpl implements FileService {
@Override
public String saveImg(MultipartFile[] imgName) throws IOException{
List<String> images = multiUpload.FileUpload(imgName);
System.out.println(images);
return null;
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/dailylife/global/init/InitDB.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dailylife.global.init;

import com.dailylife.domain.board.dto.BoardCreateRequest;
import com.dailylife.domain.board.service.BoardService;
import com.dailylife.domain.user.dto.UserJoinRequest;
import com.dailylife.domain.user.entity.User;
import com.dailylife.domain.user.repository.UserRepository;
Expand All @@ -23,6 +25,8 @@ public class InitDB {

private final UserService userService;

private final BoardService boardService;

@PostConstruct
public void initDB() throws IOException {
if(ddlAutoConfig.equals("create")){
Expand All @@ -45,6 +49,7 @@ public void initDB() throws IOException {
.userName("dailyLife3")
.userEmail("[email protected]").userJoinDate(LocalDateTime.now()).build();


userService.join(userReq1);
userService.join(userReq2);
userService.join(userReq3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public String resolveAccessToken() {
@Override
public String getLoginId() {
String accessToken = resolveAccessToken();
log.info("accessToken = {}" , accessToken);
if (accessToken == null || accessToken.length() == 0)
throw new RuntimeException("토큰x");

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


}
Expand Down

0 comments on commit 6aaeb58

Please sign in to comment.