From 6d5a5487b8ed6f5aeeecca2d35ae78b1f57435d8 Mon Sep 17 00:00:00 2001 From: Seoyoung2222 Date: Wed, 27 Nov 2024 14:35:46 +0900 Subject: [PATCH] =?UTF-8?q?BE:=20[feat]=20=ED=81=AC=EB=A3=A8=ED=99=88=20-?= =?UTF-8?q?=20=EA=B3=B5=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20#83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NoticePostController.java | 6 +++++ .../notice/dto/CrewMainNoticeResponseDto.java | 24 ++++++++++++++++++ .../dto/NoticePostSimpleResponseDto.java | 25 +++++++++++++++++++ .../service/NoticePostQueryService.java | 25 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/CrewMainNoticeResponseDto.java create mode 100644 src/backend/src/main/java/RunningMachines/R2R/domain/crew/post/notice/dto/NoticePostSimpleResponseDto.java 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 + ); + } }