Skip to content

Commit

Permalink
Merge pull request #131 from CSID-DGU/backend/feature/crew
Browse files Browse the repository at this point in the history
BE: [feat] 크루 갤러리 글 상세 조회 #83
  • Loading branch information
Seoyoung2222 authored Nov 30, 2024
2 parents b5ff7eb + d8c8ec3 commit eb76bd8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package RunningMachines.R2R.domain.crew.post.gallery.controller;

import RunningMachines.R2R.domain.crew.post.gallery.dto.GalleryPostCreateRequestDto;
import RunningMachines.R2R.domain.crew.post.gallery.dto.GalleryPostDetailResponseDto;
import RunningMachines.R2R.domain.crew.post.gallery.service.GalleryPostCommandService;
import RunningMachines.R2R.domain.crew.post.gallery.service.GalleryPostQueryService;
import RunningMachines.R2R.domain.crew.post.repository.CrewPostRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -15,10 +17,17 @@
@RequiredArgsConstructor
public class GalleryPostController {
private final GalleryPostCommandService galleryPostCommandService;
private final GalleryPostQueryService galleryPostQueryService;

@PostMapping
public ResponseEntity<Long> createGalleryPost(@PathVariable Long crewId, @RequestPart("content") GalleryPostCreateRequestDto contentDto, @RequestPart("images") List<MultipartFile> images) {
Long crewPostId = galleryPostCommandService.createGalleryPost(crewId, contentDto, images);
return ResponseEntity.ok(crewPostId);
}

@GetMapping("/{postId}")
public ResponseEntity<GalleryPostDetailResponseDto> getGalleryPost(@PathVariable Long crewId, @PathVariable Long postId) {
GalleryPostDetailResponseDto responseDto = galleryPostQueryService.getGalleryPostDetail(crewId, postId);
return ResponseEntity.ok(responseDto);
}
}
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;
}
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();
}
}

0 comments on commit eb76bd8

Please sign in to comment.