Skip to content

Commit

Permalink
BE: [feat] 크루홈 - 공지 조회 CSID-DGU#83
Browse files Browse the repository at this point in the history
  • Loading branch information
Seoyoung2222 committed Nov 27, 2024
1 parent 1fb43c5 commit 6d5a548
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,4 +35,9 @@ public ResponseEntity<Long> createNoticePost(@PathVariable Long crewId, @Request
public ResponseEntity<NoticePostResponseDto> getNoticePostDetail(@PathVariable Long crewId, @PathVariable Long crewPostId) {
return ResponseEntity.ok(noticePostQueryService.getPostDetail(crewId, crewPostId));
}

@GetMapping
public ResponseEntity<CrewMainNoticeResponseDto> getNoticePostsByCrew(@PathVariable Long crewId) {
return ResponseEntity.ok(noticePostQueryService.getNoticePostsByCrew(crewId));
}
}
Original file line number Diff line number Diff line change
@@ -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<NoticePostSimpleResponseDto> noticePost;

public static CrewMainNoticeResponseDto of(String crewTitle, int postCount, int memberCount, List<NoticePostSimpleResponseDto> noticePost) {
return CrewMainNoticeResponseDto.builder()
.crewTitle(crewTitle)
.postCount(postCount)
.memberCount(memberCount)
.noticePost(noticePost)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CrewPost> noticePosts = crewPostRepository.findAllByCrewIdAndBoard(crewId, CrewBoard.NOTICE);

// 공지글 미리보기
List<NoticePostSimpleResponseDto> noticePostSimpleResponseDtos = noticePosts.stream()
.map(NoticePostSimpleResponseDto::fromEntity)
.collect(Collectors.toList());

return CrewMainNoticeResponseDto.of(
crew.getTitle(),
noticePosts.size(),
crew.getCrewUsers().size(),
noticePostSimpleResponseDtos
);
}
}

0 comments on commit 6d5a548

Please sign in to comment.