-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from CSID-DGU/backend/feature/crew
BE: [feat] 크루 갤러리 글 상세 조회 #83
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...n/java/RunningMachines/R2R/domain/crew/post/gallery/dto/GalleryPostDetailResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package RunningMachines.R2R.domain.crew.post.gallery.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class GalleryPostDetailResponseDto { | ||
private Long postId; | ||
private String authorNickName; | ||
private String authorProfileUrl; | ||
private String createdAt; | ||
private int likeCount; | ||
private List<String> imageUrls; | ||
private String content; | ||
} |
43 changes: 43 additions & 0 deletions
43
...in/java/RunningMachines/R2R/domain/crew/post/gallery/service/GalleryPostQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package RunningMachines.R2R.domain.crew.post.gallery.service; | ||
|
||
import RunningMachines.R2R.domain.crew.board.entity.CrewBoard; | ||
import RunningMachines.R2R.domain.crew.post.entity.CrewPost; | ||
import RunningMachines.R2R.domain.crew.post.gallery.dto.GalleryPostDetailResponseDto; | ||
import RunningMachines.R2R.domain.crew.post.repository.CrewPostRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GalleryPostQueryService { | ||
private final CrewPostRepository crewPostRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public GalleryPostDetailResponseDto getGalleryPostDetail(Long crewId, Long crewPostId) { | ||
CrewPost crewPost = crewPostRepository.findById(crewPostId) | ||
.orElseThrow(() -> new IllegalArgumentException("해당 게시글을 찾을 수 없습니다.")); | ||
|
||
if (!crewPost.getCrew().getId().equals(crewId)) { | ||
throw new IllegalArgumentException("요청한 크루에 해당하지 않는 게시글입니다."); | ||
} | ||
|
||
if (!CrewBoard.GALLERY.name().equals(crewPost.getBoard().name())) { | ||
throw new IllegalArgumentException("갤러리 게시판의 글이 아닙니다."); | ||
} | ||
|
||
return GalleryPostDetailResponseDto.builder() | ||
.postId(crewPost.getId()) | ||
.authorNickName(crewPost.getUser().getNickname()) | ||
.authorProfileUrl(crewPost.getUser().getProfileImageUrl()) | ||
.createdAt(crewPost.getCreatedAt().toString()) | ||
.likeCount(crewPost.getLikeCount()) | ||
.imageUrls(crewPost.getImages().stream() | ||
.map(image -> image.getImageUrl()) | ||
.collect(Collectors.toList())) | ||
.content(crewPost.getContent()) | ||
.build(); | ||
} | ||
} |