Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public PagedBoardInfo getBoardListByUserId(@JwtValidation Long loginUserId,
return boardService.getBoardListByUserId(loginUserId, userId, pageable);
}

@GetMapping("/temp/{boardId}")
@Operation(summary = "임시저장된 게시글 단일 조회 API", description = "임시저장된 게시글 단일 조회하는 API 구현.")
public BoardInfo getBoardListByUserId(@JwtValidation Long userId,
@PathVariable Long boardId) {
return boardService.getTempBoard(userId, boardId);
}

@PostMapping("/bookmark/{boardId}")
@Operation(summary = "원하는 게시글을 찜하는 API", description = "원하는 게시글을 찜하는 API 입니다.")
public StateResponse addBookMark(@JwtValidation Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface BoardRepository extends JpaRepository<Board, Long>, BoardReposi
Optional<Board> findByIdAndDeletedAtIsNull(Long boardId);

Page<Board> findAllByUserIdAndDeletedAtIsNullAndIsCompletedIsTrue(Long userId, Pageable pageable);

Optional<Board> findByIdAndUserIdAndIsCompletedIsFalse(Long boardId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public interface BoardService {

PagedBoardInfo getBoardListByUserId(Long loginUserId, Long userId, Pageable pageable);

BoardInfo getTempBoard(Long userId, Long boardId);

BoardDeleteInfo deleteBoard(Long userId, Long boardId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ public PagedBoardInfo getBoardListByUserId(Long loginUserId, Long userId, Pageab
return boardConverter.toPagedBoardInfoFromBoardList(boardList);
}

@Override
@Transactional
public BoardInfo getTempBoard(Long userId, Long boardId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));

Board tempBoard = boardRepository.findByIdAndUserIdAndIsCompletedIsFalse(boardId, user.getId())
.orElseThrow(() -> new BaseException(ErrorCode.TEMP_BOARD_NOT_FOUND));

if (user.isDifferentUserFrom(tempBoard.getUser())) {
throw new BaseException(ErrorCode.TEMP_BOARD_BAD_REQUEST);
}

return boardConverter.toBoardInfo(tempBoard, tempBoard.getGame());
}

@Override
@Transactional
public BoardDeleteInfo deleteBoard(Long userId, Long boardId) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/back/catchmate/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public enum ErrorCode {

// 게시글
BOARD_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 게시글입니다."),
TEMP_BOARD_NOT_FOUND(HttpStatus.NOT_FOUND, "임시 저장된 글이 존재하지 않습니다."),
TEMP_BOARD_BAD_REQUEST(HttpStatus.NOT_FOUND, "임시 저장된 글을 불러올 권한이 없습니다."),
BOARD_DELETED(HttpStatus.NOT_FOUND, "삭제된 게시글이거나 잘못된 접근입니다."),
BOARD_BAD_REQUEST(HttpStatus.BAD_REQUEST, "자신의 게시글만 수정할 수 있습니다."),
INVALID_ACCESS_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 액세스 토큰입니다."),
Expand Down
Loading