forked from CSID-DGU/2024-2-OSSProj-Running-Machines-04
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cde3fc7
commit 0b268b2
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...a/RunningMachines/R2R/domain/crew/post/gallery/comment/dto/CrewPostCommentRequestDto.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,12 @@ | ||
package RunningMachines.R2R.domain.crew.post.gallery.comment.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CrewPostCommentRequestDto { | ||
private String content; | ||
} |
16 changes: 16 additions & 0 deletions
16
.../RunningMachines/R2R/domain/crew/post/gallery/comment/dto/CrewPostCommentResponseDto.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,16 @@ | ||
package RunningMachines.R2R.domain.crew.post.gallery.comment.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class CrewPostCommentResponseDto { | ||
private Long commentId; | ||
private String content; | ||
private String authorName; | ||
private String authorProfile; | ||
private String createdAt; | ||
} |
7 changes: 7 additions & 0 deletions
7
...ngMachines/R2R/domain/crew/post/gallery/comment/repository/CrewPostCommentRepository.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,7 @@ | ||
package RunningMachines.R2R.domain.crew.post.gallery.comment.repository; | ||
|
||
import RunningMachines.R2R.domain.crew.post.entity.CrewPostComment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CrewPostCommentRepository extends JpaRepository<CrewPostComment, Long> { | ||
} |
52 changes: 52 additions & 0 deletions
52
.../RunningMachines/R2R/domain/crew/post/gallery/comment/service/CrewPostCommentService.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,52 @@ | ||
package RunningMachines.R2R.domain.crew.post.gallery.comment.service; | ||
|
||
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.entity.CrewPostComment; | ||
import RunningMachines.R2R.domain.crew.post.gallery.comment.dto.CrewPostCommentRequestDto; | ||
import RunningMachines.R2R.domain.crew.post.gallery.comment.dto.CrewPostCommentResponseDto; | ||
import RunningMachines.R2R.domain.crew.post.gallery.comment.repository.CrewPostCommentRepository; | ||
import RunningMachines.R2R.domain.crew.post.repository.CrewPostRepository; | ||
import RunningMachines.R2R.domain.user.entity.User; | ||
import RunningMachines.R2R.domain.user.service.AuthCommandService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CrewPostCommentService { | ||
private final CrewPostRepository crewPostRepository; | ||
private final CrewPostCommentRepository crewPostCommentRepository; | ||
private final CrewRepository crewRepository; | ||
private final AuthCommandService authCommandService; | ||
|
||
@Transactional | ||
public Long createComment(Long crewId, Long postId, CrewPostCommentRequestDto requestDto) { | ||
User currentUser = authCommandService.getCurrentUser(); | ||
|
||
CrewPost crewPost = crewPostRepository.findById(postId) | ||
.orElseThrow(() -> new IllegalArgumentException("게시글을 찾을 수 없습니다.")); | ||
Crew crew = crewRepository.findById(crewId) | ||
.orElseThrow(() -> new IllegalArgumentException("크루를 찾을 수 없습니다.")); | ||
|
||
boolean isMember = crew.getCrewUsers().stream() | ||
.anyMatch(crewUser -> crewUser.getUser().equals(currentUser)); | ||
if (!isMember) { | ||
throw new IllegalArgumentException("댓글 작성은 크루 유저만 가능합니다."); | ||
} | ||
|
||
CrewPostComment comment = CrewPostComment.builder() | ||
.content(requestDto.getContent()) | ||
.crewPost(crewPost) | ||
.user(currentUser) | ||
.build(); | ||
CrewPostComment savedComment = crewPostCommentRepository.save(comment); | ||
|
||
return savedComment.getId(); | ||
} | ||
|
||
} |
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