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 @@ -45,6 +45,19 @@ public CommonResponse<List<PostListResponseDTO>> getPosts(
}


@GetMapping("/my-posts")
@Operation(summary = "현재 로그인한 Club의 홍보글 조회 API")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "홍보글 조회 성공"),
@ApiResponse(responseCode = "401", description = "세션값이 잘못되었습니다."),
@ApiResponse(responseCode = "404", description = "현재 Club에 해당하는 홍보글이 없습니다.")
})
public CommonResponse<List<PostListResponseDTO>> getMyPosts(HttpSession session) {
List<PostListResponseDTO> myPosts = postService.getMyPosts(session);
return new CommonResponse<>(myPosts);
}


@GetMapping("/{post_id}")
@Operation(summary = "특정 홍보글 디테일 조회 api")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
import java.util.List;

public interface PostRepository extends JpaRepository<Post, Long>, JpaSpecificationExecutor<Post> {
List<Post> findByClubId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public List<PostListResponseDTO> getAllPosts(String clubName, Long categoryId, S
}



private int calculateDDay(LocalDateTime endTime) {
LocalDateTime now = LocalDateTime.now();

Expand Down Expand Up @@ -142,6 +141,26 @@ private PostListResponseDTO toPostResponseDTO(Post post) {
}


@Transactional
public List<PostListResponseDTO> getMyPosts(HttpSession session) {
// 현재 로그인한 유저가 Club인지 확인
Club club = checkClub(session);

// Club ID로 홍보글 필터링
List<Post> posts = postRepository.findByClubId(club.getId());

// 검색 결과가 없을 경우 예외 처리
if (posts.isEmpty()) {
throw new PostNotFoundException("현재 Club에 해당하는 홍보글이 없습니다.");
}

// Post 엔티티를 DTO로 변환
return posts.stream()
.map(this::toPostResponseDTO)
.collect(Collectors.toList());
}


// 특정 홍보글 디테일 조회
public PostDetailResponseDTO getPostById(Long postId) {
Post post = postRepository.findById(postId)
Expand Down
Loading