-
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.
Merge pull request #85 from SWM-Flash/integration
Integration
- Loading branch information
Showing
29 changed files
with
593 additions
and
53 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/main/java/com/first/flash/climbing/solution/application/SolutionCommentService.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,91 @@ | ||
package com.first.flash.climbing.solution.application; | ||
|
||
import com.first.flash.account.member.application.MemberService; | ||
import com.first.flash.account.member.domain.Member; | ||
import com.first.flash.climbing.solution.application.dto.SolutionCommentCreateRequestDto; | ||
import com.first.flash.climbing.solution.application.dto.SolutionCommentCreateResponseDto; | ||
import com.first.flash.climbing.solution.application.dto.SolutionCommentResponseDto; | ||
import com.first.flash.climbing.solution.application.dto.SolutionCommentUpdateRequestDto; | ||
import com.first.flash.climbing.solution.application.dto.SolutionCommentsResponseDto; | ||
import com.first.flash.climbing.solution.domain.Solution; | ||
import com.first.flash.climbing.solution.domain.SolutionComment; | ||
import com.first.flash.climbing.solution.exception.exceptions.SolutionCommentAccessDeniedException; | ||
import com.first.flash.climbing.solution.exception.exceptions.SolutionCommentNotFoundException; | ||
import com.first.flash.climbing.solution.infrastructure.SolutionCommentRepository; | ||
import com.first.flash.global.util.AuthUtil; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class SolutionCommentService { | ||
|
||
private final MemberService memberService; | ||
private final SolutionCommentRepository solutionCommentRepository; | ||
private final SolutionService solutionService; | ||
|
||
@Transactional | ||
public SolutionCommentCreateResponseDto createComment(final Long solutionId, | ||
final SolutionCommentCreateRequestDto request) { | ||
UUID id = AuthUtil.getId(); | ||
Member member = memberService.findById(id); | ||
|
||
Solution solution = solutionService.findSolutionById(solutionId); | ||
SolutionComment solutionComment = SolutionComment.of(request.content(), | ||
member.getNickName(), member.getProfileImageUrl(), member.getId(), solution); | ||
SolutionComment savedSolutionComment = solutionCommentRepository.save(solutionComment); | ||
|
||
return SolutionCommentCreateResponseDto.toDto(savedSolutionComment); | ||
} | ||
|
||
public SolutionComment findById(final Long id) { | ||
return solutionCommentRepository.findById(id) | ||
.orElseThrow( | ||
() -> new SolutionCommentNotFoundException(id)); | ||
} | ||
|
||
public SolutionCommentsResponseDto findBySolutionId(final Long solutionId) { | ||
List<SolutionComment> comments = solutionService.findSolutionById(solutionId) | ||
.getComments(); | ||
List<SolutionCommentResponseDto> commentsResponse = comments.stream() | ||
.map( | ||
SolutionCommentResponseDto::toDto) | ||
.toList(); | ||
return SolutionCommentsResponseDto.from(commentsResponse); | ||
} | ||
|
||
@Transactional | ||
public SolutionCommentResponseDto updateComment(final Long commentId, | ||
final SolutionCommentUpdateRequestDto request) { | ||
SolutionComment comment = findById(commentId); | ||
if (!AuthUtil.isSameId(comment.getCommenterDetail().getCommenterId())) { | ||
throw new SolutionCommentAccessDeniedException(); | ||
} | ||
comment.updateContent(request.content()); | ||
return SolutionCommentResponseDto.toDto(comment); | ||
} | ||
|
||
@Transactional | ||
public void deleteComment(final Long commentId) { | ||
SolutionComment comment = findById(commentId); | ||
if (!AuthUtil.isSameId(comment.getCommenterDetail().getCommenterId())) { | ||
throw new SolutionCommentAccessDeniedException(); | ||
} | ||
solutionCommentRepository.delete(comment); | ||
} | ||
|
||
@Transactional | ||
public void deleteByCommenterId(final UUID commenterId) { | ||
solutionCommentRepository.deleteByCommenterId(commenterId); | ||
} | ||
|
||
@Transactional | ||
public void updateCommenterInfo(final UUID commenterId, final String nickName, | ||
final String profileImageUrl) { | ||
solutionCommentRepository.updateCommenterInfo(commenterId, nickName, profileImageUrl); | ||
} | ||
} |
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
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
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
7 changes: 7 additions & 0 deletions
7
...va/com/first/flash/climbing/solution/application/dto/SolutionCommentCreateRequestDto.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 com.first.flash.climbing.solution.application.dto; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
public record SolutionCommentCreateRequestDto(@NotEmpty String content) { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...a/com/first/flash/climbing/solution/application/dto/SolutionCommentCreateResponseDto.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 com.first.flash.climbing.solution.application.dto; | ||
|
||
import com.first.flash.climbing.solution.domain.SolutionComment; | ||
import java.util.UUID; | ||
|
||
public record SolutionCommentCreateResponseDto(Long id, String content, UUID commenterId, | ||
String nickName, String profileImageUrl) { | ||
|
||
public static SolutionCommentCreateResponseDto toDto( | ||
final SolutionComment comment) { | ||
return new SolutionCommentCreateResponseDto(comment.getId(), comment.getContent(), | ||
comment.getCommenterDetail().getCommenterId(), | ||
comment.getCommenterDetail().getCommenter(), | ||
comment.getCommenterDetail().getProfileImageUrl()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...in/java/com/first/flash/climbing/solution/application/dto/SolutionCommentResponseDto.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,18 @@ | ||
package com.first.flash.climbing.solution.application.dto; | ||
|
||
import com.first.flash.climbing.solution.domain.SolutionComment; | ||
import com.first.flash.global.util.AuthUtil; | ||
import java.util.UUID; | ||
|
||
public record SolutionCommentResponseDto(Long id, String content, UUID commenterId, String nickName, | ||
String profileImageUrl, boolean isMine) { | ||
|
||
public static SolutionCommentResponseDto toDto(final SolutionComment solutionComment) { | ||
return new SolutionCommentResponseDto(solutionComment.getId(), solutionComment.getContent(), | ||
solutionComment.getCommenterDetail().getCommenterId(), | ||
solutionComment.getCommenterDetail().getCommenter(), | ||
solutionComment.getCommenterDetail().getProfileImageUrl(), | ||
solutionComment.getCommenterDetail().getCommenterId().equals(AuthUtil.getId()) | ||
); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...va/com/first/flash/climbing/solution/application/dto/SolutionCommentUpdateRequestDto.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 com.first.flash.climbing.solution.application.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record SolutionCommentUpdateRequestDto(@NotNull String content) { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...n/java/com/first/flash/climbing/solution/application/dto/SolutionCommentsResponseDto.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,11 @@ | ||
package com.first.flash.climbing.solution.application.dto; | ||
|
||
import java.util.List; | ||
|
||
public record SolutionCommentsResponseDto(List<SolutionCommentResponseDto> comments) { | ||
|
||
public static SolutionCommentsResponseDto from( | ||
final List<SolutionCommentResponseDto> commentsResponse) { | ||
return new SolutionCommentsResponseDto(commentsResponse); | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
src/main/java/com/first/flash/climbing/solution/application/dto/SolutionsResponseDto.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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/first/flash/climbing/solution/domain/CommenterDetail.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,32 @@ | ||
package com.first.flash.climbing.solution.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import java.util.UUID; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Embeddable | ||
@NoArgsConstructor | ||
@EqualsAndHashCode | ||
@Getter | ||
@ToString | ||
public class CommenterDetail { | ||
|
||
@Column(columnDefinition = "BINARY(16)") | ||
private UUID commenterId; | ||
private String commenter; | ||
private String profileImageUrl; | ||
|
||
protected CommenterDetail(final UUID commenterId, final String commenter, final String profileImageUrl) { | ||
this.commenterId = commenterId; | ||
this.commenter = commenter; | ||
this.profileImageUrl = profileImageUrl; | ||
} | ||
|
||
public static CommenterDetail of(final UUID commenterId, final String commenter, final String profileImageUrl) { | ||
return new CommenterDetail(commenterId, commenter, profileImageUrl); | ||
} | ||
} |
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
Oops, something went wrong.