diff --git a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/controller/NoticePostController.java b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/controller/NoticePostController.java index 5276a9d..f9edf9b 100644 --- a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/controller/NoticePostController.java +++ b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/controller/NoticePostController.java @@ -1,6 +1,7 @@ package RunningMachines.R2R.domain.crew.post.notice.controller; import RunningMachines.R2R.domain.crew.post.entity.CrewPost; +import RunningMachines.R2R.domain.crew.post.notice.dto.CrewMainNoticeResponseDto; import RunningMachines.R2R.domain.crew.post.notice.dto.NoticePostCreateRequestDto; import RunningMachines.R2R.domain.crew.post.notice.dto.NoticePostResponseDto; import RunningMachines.R2R.domain.crew.post.notice.service.NoticePostCommandService; @@ -34,4 +35,9 @@ public ResponseEntity createNoticePost(@PathVariable Long crewId, @Request public ResponseEntity getNoticePostDetail(@PathVariable Long crewId, @PathVariable Long crewPostId) { return ResponseEntity.ok(noticePostQueryService.getPostDetail(crewId, crewPostId)); } + + @GetMapping + public ResponseEntity getNoticePostsByCrew(@PathVariable Long crewId) { + return ResponseEntity.ok(noticePostQueryService.getNoticePostsByCrew(crewId)); + } } diff --git a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/CrewMainNoticeResponseDto.java b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/CrewMainNoticeResponseDto.java new file mode 100644 index 0000000..0ad6bb6 --- /dev/null +++ b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/CrewMainNoticeResponseDto.java @@ -0,0 +1,24 @@ +package RunningMachines.R2R.domain.crew.post.notice.dto; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class CrewMainNoticeResponseDto { + private String crewTitle; + private int postCount; + private int memberCount; + private List noticePost; + + public static CrewMainNoticeResponseDto of(String crewTitle, int postCount, int memberCount, List noticePost) { + return CrewMainNoticeResponseDto.builder() + .crewTitle(crewTitle) + .postCount(postCount) + .memberCount(memberCount) + .noticePost(noticePost) + .build(); + } +} diff --git a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/NoticePostSimpleResponseDto.java b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/NoticePostSimpleResponseDto.java new file mode 100644 index 0000000..ce52fdf --- /dev/null +++ b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/NoticePostSimpleResponseDto.java @@ -0,0 +1,25 @@ +package RunningMachines.R2R.domain.crew.post.notice.dto; + +import RunningMachines.R2R.domain.crew.post.entity.CrewPost; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@Builder +public class NoticePostSimpleResponseDto { + private long crewPostId; + private String title; + private String author; + private LocalDateTime lastModified; + + public static NoticePostSimpleResponseDto fromEntity(CrewPost crewPost) { + return NoticePostSimpleResponseDto.builder() + .crewPostId(crewPost.getId()) + .title(crewPost.getTitle()) + .author(crewPost.getUser().getNickname()) + .lastModified(crewPost.getUpdatedAt()) + .build(); + } +} diff --git a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/service/NoticePostQueryService.java b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/service/NoticePostQueryService.java index 7254dfe..b6ae941 100644 --- a/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/service/NoticePostQueryService.java +++ b/src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/service/NoticePostQueryService.java @@ -2,8 +2,11 @@ import RunningMachines.R2R.domain.crew.board.entity.CrewBoard; import RunningMachines.R2R.domain.crew.common.entity.Crew; +import RunningMachines.R2R.domain.crew.common.repository.CrewRepository; import RunningMachines.R2R.domain.crew.post.entity.CrewPost; +import RunningMachines.R2R.domain.crew.post.notice.dto.CrewMainNoticeResponseDto; import RunningMachines.R2R.domain.crew.post.notice.dto.NoticePostResponseDto; +import RunningMachines.R2R.domain.crew.post.notice.dto.NoticePostSimpleResponseDto; import RunningMachines.R2R.domain.crew.post.repository.CrewPostRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -15,10 +18,32 @@ @RequiredArgsConstructor public class NoticePostQueryService { private final CrewPostRepository crewPostRepository; + private final CrewRepository crewRepository; public NoticePostResponseDto getPostDetail(Long crewId, Long crewpostId) { CrewPost noticePost = crewPostRepository.findByIdAndCrewIdAndBoard(crewpostId, crewId, CrewBoard.NOTICE) .orElseThrow(() -> new IllegalArgumentException("공지글을 찾을 수 없습니다.")); return NoticePostResponseDto.fromEntity(noticePost); } + + public CrewMainNoticeResponseDto getNoticePostsByCrew(Long crewId) { + // 크루 정보 조회 + Crew crew = crewRepository.findById(crewId) + .orElseThrow(() -> new IllegalArgumentException("크루를 찾을 수 없습니다.")); + + // 공지글 조회 + List noticePosts = crewPostRepository.findAllByCrewIdAndBoard(crewId, CrewBoard.NOTICE); + + // 공지글 미리보기 + List noticePostSimpleResponseDtos = noticePosts.stream() + .map(NoticePostSimpleResponseDto::fromEntity) + .collect(Collectors.toList()); + + return CrewMainNoticeResponseDto.of( + crew.getTitle(), + noticePosts.size(), + crew.getCrewUsers().size(), + noticePostSimpleResponseDtos + ); + } }