Skip to content

Commit

Permalink
Merge pull request #170 from Team-Capple/feat/#169/updateBoardAPI
Browse files Browse the repository at this point in the history
[FEAT] 게시글 수정 API 구현
  • Loading branch information
jaewonLeeKOR authored Oct 1, 2024
2 parents b4f4718 + 57a6e1d commit 23277b9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public BaseResponse<BoardId> createBoard(@AuthMember Member member,
return BaseResponse.onSuccess(boardService.createBoard(member, request.getBoardType(), request.getContent()));
}

@Operation(summary = "게시글 수정 API", description = "게시글을 수정합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "COMMON200", description = "성공"),
})
@PostMapping("/update")
private BaseResponse<BoardId> updateBoard(@AuthMember Member member,
@RequestBody @Valid BoardRequest.BoardUpdate request) {
return BaseResponse.onSuccess(boardService.updateBoard(member, request.getBoardId(), request.getContent()));
}

@Operation(summary = "카테고리별 게시글 조회 with REDIS API(프론트 사용 X, 성능 테스트 용)", description = "카테고리별 게시글을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "COMMON200", description = "성공"),
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/server/capple/domain/board/dto/BoardRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.server.capple.domain.board.entity.BoardType;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -18,4 +19,15 @@ public static class BoardCreate {
private String content;
private BoardType boardType;
}

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class BoardUpdate {
@NotNull
private Long boardId;
@NotEmpty
private String content;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.server.capple.domain.board.entity;

import com.server.capple.domain.answer.dto.AnswerRequest;
import com.server.capple.domain.board.dto.BoardRequest;
import com.server.capple.domain.member.entity.Member;
import com.server.capple.global.common.BaseEntity;
import jakarta.persistence.*;
Expand Down Expand Up @@ -58,4 +60,11 @@ public void increaseCommentCount() {
public void decreaseCommentCount() {
this.commentCount--;
}

public void updateBoardType(BoardType boardType) {
this.boardType = boardType;
}
public void updateContent(String content) {
this.content = content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface BoardService {
ToggleBoardHeart toggleBoardHeart(Member member, Long boardId);

Board findBoard(Long boardId);

BoardId updateBoard(Member member, Long boardId, String content);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public BoardId createBoard(Member member, BoardType boardType, String content) {
}

@Override
@Transactional
public BoardId updateBoard(Member member, Long boardId, String content) {
Board board = findBoard(boardId);
checkPermission(member, board);
board.updateContent(content);

return new BoardId(board.getId());
}

public SliceResponse<BoardInfo> getBoardsByBoardType(Member member, BoardType boardType, Long lastIndex, Pageable pageable) {
lastIndex = getLastIndex(lastIndex);
Slice<BoardInfoInterface> sliceBoardInfos = boardRepository.findBoardInfosByMemberAndBoardTypeAndIdIsLessThanEqual(member, boardType, lastIndex, pageable);
Expand Down

0 comments on commit 23277b9

Please sign in to comment.