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 @@ -74,6 +74,38 @@ public ResponseEntity<BoardListResponse> getBoardList(

return ResponseEntity.ok(boardService.getBoardList(page, size));
}

/**
* 요청 사용자가 작성한 게시글 목록을 조회합니다.
*
* @param page 페이지 번호
* @param size 페이지 크기
* @param userDetails 인증된 사용자 정보
* @return 내가 쓴 게시글 목록 조회 응답
*/
@Operation(summary = "내가 쓴 게시글 목록 조회", description = "인증된 사용자가 작성한 게시글 목록을 페이지 단위로 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "내가 쓴 게시글 목록을 성공적으로 조회했습니다.",
content = @Content(schema = @Schema(implementation = BoardListResponse.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "401", description = "로그인이 필요한 기능입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류가 발생했습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/me")
public ResponseEntity<BoardListResponse> getMyBoards(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@AuthenticationPrincipal UserDetails userDetails
) {
UUID userId = UUID.fromString(userDetails.getUsername());
log.info("내가 쓴 게시글 목록 조회 요청 수신 - User: {}, Page: {}, Size: {}", userId, page, size);

return ResponseEntity.ok(boardService.getMyBoards(userId, page, size));
}

/**
* 새 게시글을 작성합니다.
*
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/dodo/backend/board/mapper/BoardMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.UUID;

/**
* 게시글(Board) 도메인의 동적 수정 쿼리를 담당하는 MyBatis Mapper 인터페이스입니다.
Expand All @@ -32,6 +33,28 @@ List<BoardListQueryResponse> findBoardList(
*/
long countPublishedBoards();

/**
* 특정 사용자가 작성한 게시글 목록을 페이지 단위로 조회합니다.
*
* @param userId 조회할 사용자 ID
* @param offset 조회 시작 위치
* @param size 조회 개수
* @return 내가 쓴 게시글 목록 조회 결과
*/
List<BoardListQueryResponse> findMyBoardList(
@Param("userId") UUID userId,
@Param("offset") int offset,
@Param("size") int size
);

/**
* 특정 사용자가 작성한 게시글 전체 개수를 조회합니다.
*
* @param userId 조회할 사용자 ID
* @return 내가 쓴 게시글 전체 개수
*/
long countMyBoards(@Param("userId") UUID userId);

/**
* 게시글 제목과 내용을 선택적으로 수정합니다.
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/dodo/backend/board/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public interface BoardService {
*/
BoardListResponse getBoardList(int page, int size);

/**
* 요청 사용자가 작성한 게시글 목록을 조회합니다.
*
* @param userId 요청 사용자 ID
* @param page 조회할 페이지 번호
* @param size 페이지 크기
* @return 내가 쓴 게시글 목록 조회 응답 DTO
*/
BoardListResponse getMyBoards(UUID userId, int page, int size);

/**
* 새 게시글을 생성하고 이미지 URL 목록을 게시글에 연결합니다.
*
Expand Down
57 changes: 29 additions & 28 deletions src/main/java/com/dodo/backend/board/service/BoardServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,13 @@
@RequiredArgsConstructor
public class BoardServiceImpl implements BoardService {

/**
* Redis에 임시 저장 게시글 데이터를 저장할 때 사용하는 키 접두사입니다.
*/
private static final String TEMP_SAVE_KEY_PREFIX = "board:temp-save:";

/**
* 임시 저장 데이터의 Redis 유지 기간입니다.
*/
private static final long TEMP_SAVE_TTL_DAYS = 7L;

private static final int MAX_BOARD_LIST_SIZE = 100;

/**
* 게시글 저장 및 단건 조회를 처리하는 JPA Repository입니다.
*/
private final BoardRepository boardRepository;

/**
* 사용자 엔티티 조회를 처리하는 서비스입니다.
*/
private final UserService userService;

/**
* 게시글 이미지 URL 저장, 조회, 교체, 삭제를 처리하는 서비스입니다.
*/
private final ImageFileService imageFileService;

/**
* 게시글 수정, 삭제, 조회수 증가처럼 동적 SQL이 필요한 작업을 처리하는 MyBatis Mapper입니다.
*/
private final BoardMapper boardMapper;

/**
* 게시글 임시 저장 데이터를 Redis에 저장하고 조회하기 위한 Template입니다.
*/
private final RedisTemplate<String, Object> redisTemplate;

/**
Expand Down Expand Up @@ -124,6 +96,35 @@ public BoardListResponse getBoardList(int page, int size) {
);
}

/**
* 요청 사용자가 작성한 게시글 목록을 조회합니다.
*
* @param userId 요청 사용자 ID
* @param page 조회할 페이지 번호
* @param size 페이지 크기
* @return 내가 쓴 게시글 목록 조회 응답 DTO
*/
@Override
@Transactional(readOnly = true)
public BoardListResponse getMyBoards(UUID userId, int page, int size) {
if (userId == null) {
throw new BoardException(INVALID_REQUEST);
}
validateBoardListRequest(page, size);

int offset = page * size;
List<BoardListQueryResponse> queryResponses = boardMapper.findMyBoardList(userId, offset, size);
long totalElements = boardMapper.countMyBoards(userId);

return BoardListResponse.toDto(
queryResponses,
totalElements,
page,
size,
"내가 쓴 게시글 목록을 성공적으로 조회했습니다."
);
}

/**
* 새 게시글을 생성하고 요청에 포함된 이미지 URL 목록을 게시글에 연결합니다.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dodo.backend.comment.dto.response.CommentResponse.CommentCreateResponse;
import com.dodo.backend.comment.dto.response.CommentResponse.CommentListResponse;
import com.dodo.backend.comment.dto.response.CommentResponse.CommentSimpleResponse;
import com.dodo.backend.comment.dto.response.CommentResponse.MyCommentListResponse;
import com.dodo.backend.comment.service.CommentService;
import com.dodo.backend.common.exception.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -74,6 +75,37 @@ public ResponseEntity<CommentCreateResponse> createComment(
return ResponseEntity.ok(commentService.createComment(userId, request));
}

/**
* 요청 사용자가 작성한 댓글 목록을 조회합니다.
*
* @param page 페이지 번호
* @param size 페이지 크기
* @param userDetails 인증된 사용자 정보
* @return 내가 쓴 댓글 목록 조회 응답
*/
@Operation(summary = "내가 쓴 댓글 목록 조회", description = "인증된 사용자가 작성한 댓글 목록을 페이지 단위로 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "내가 쓴 댓글 목록을 성공적으로 조회했습니다.",
content = @Content(schema = @Schema(implementation = MyCommentListResponse.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "401", description = "로그인이 필요한 기능입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류가 발생했습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/me")
public ResponseEntity<MyCommentListResponse> getMyComments(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@AuthenticationPrincipal UserDetails userDetails
) {
UUID userId = UUID.fromString(userDetails.getUsername());
log.info("내가 쓴 댓글 목록 조회 요청 수신 - User: {}, Page: {}, Size: {}", userId, page, size);

return ResponseEntity.ok(commentService.getMyComments(userId, page, size));
}

/**
* 특정 게시글의 댓글 목록을 조회합니다.
*
Expand Down
Loading
Loading