-
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 #139 from devridge-team-project/main
Release v0.0.5
- Loading branch information
Showing
96 changed files
with
2,774 additions
and
210 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
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
23 changes: 23 additions & 0 deletions
23
.../java/org/devridge/api/application/community/project/ProjectCommentLikeDislikeMapper.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,23 @@ | ||
package org.devridge.api.application.community.project; | ||
|
||
import org.devridge.api.domain.community.entity.LikeStatus; | ||
import org.devridge.api.domain.community.entity.ProjectComment; | ||
import org.devridge.api.domain.community.entity.ProjectCommentLikeDislike; | ||
import org.devridge.api.domain.member.entity.Member; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ProjectCommentLikeDislikeMapper { | ||
|
||
public ProjectCommentLikeDislike toProjectCommentLikeDislike( | ||
Member member, | ||
ProjectComment comment, | ||
LikeStatus status | ||
) { | ||
return ProjectCommentLikeDislike.builder() | ||
.projectComment(comment) | ||
.member(member) | ||
.status(status) | ||
.build(); | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
...java/org/devridge/api/application/community/project/ProjectCommentLikeDislikeService.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,131 @@ | ||
package org.devridge.api.application.community.project; | ||
|
||
import javax.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.devridge.api.common.exception.common.DataNotFoundException; | ||
import org.devridge.api.common.util.SecurityContextHolderUtil; | ||
import org.devridge.api.domain.community.entity.LikeStatus; | ||
import org.devridge.api.domain.community.entity.Project; | ||
import org.devridge.api.domain.community.entity.ProjectComment; | ||
import org.devridge.api.domain.community.entity.ProjectCommentLikeDislike; | ||
import org.devridge.api.domain.community.entity.id.ProjectCommentLikeDislikeId; | ||
import org.devridge.api.domain.community.exception.MyCommunityForbiddenException; | ||
import org.devridge.api.domain.member.entity.Member; | ||
import org.devridge.api.infrastructure.community.project.ProjectCommentLikeDislikeRepository; | ||
import org.devridge.api.infrastructure.community.project.ProjectCommentRepository; | ||
import org.devridge.api.infrastructure.community.project.ProjectRepository; | ||
import org.devridge.api.infrastructure.member.MemberRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class ProjectCommentLikeDislikeService { | ||
|
||
private final ProjectCommentLikeDislikeRepository projectCommentLikeDislikeRepository; | ||
private final ProjectCommentRepository projectCommentRepository; | ||
private final MemberRepository memberRepository; | ||
private final ProjectCommentLikeDislikeMapper projectCommentLikeDislikeMapper; | ||
private final ProjectRepository projectRepository; | ||
|
||
@Transactional | ||
public void createProjectCommentLike(Long projectId, Long commentId) { | ||
Long accessMemberId = SecurityContextHolderUtil.getMemberId(); | ||
Member member = getMemberById(accessMemberId); | ||
Project project = getProjectById(projectId); | ||
ProjectComment comment = getCommentById(commentId); | ||
ProjectCommentLikeDislikeId projectCommentLikeDislikeId = | ||
new ProjectCommentLikeDislikeId(member.getId(), comment.getId()); | ||
|
||
if (accessMemberId.equals(comment.getMember().getId())) { | ||
throw new MyCommunityForbiddenException(403, "내가 작성한 글은 추천할 수 없습니다."); | ||
} | ||
|
||
projectCommentLikeDislikeRepository.findById(projectCommentLikeDislikeId).ifPresentOrElse( | ||
ProjectCommentLikeDislike -> { | ||
LikeStatus status = ProjectCommentLikeDislike.getStatus(); | ||
|
||
if (status == LikeStatus.G) { | ||
changeIsDeletedStatus(ProjectCommentLikeDislike); | ||
} | ||
|
||
if (status == LikeStatus.B) { | ||
if (ProjectCommentLikeDislike.getIsDeleted()) { | ||
projectCommentLikeDislikeRepository.restoreById(projectCommentLikeDislikeId); | ||
} | ||
projectCommentLikeDislikeRepository.updateLikeDislike(projectCommentLikeDislikeId, | ||
LikeStatus.G); | ||
} | ||
}, | ||
() -> { | ||
ProjectCommentLikeDislike commentLikeDislike = | ||
projectCommentLikeDislikeMapper.toProjectCommentLikeDislike(member, comment, LikeStatus.G); | ||
projectCommentLikeDislikeRepository.save(commentLikeDislike); | ||
} | ||
); | ||
updateLikeDislike(projectCommentLikeDislikeId.getCommentId()); | ||
} | ||
|
||
@Transactional | ||
public void createProjectCommentDislike(Long projectId, Long commentId) { | ||
Long accessMemberId = SecurityContextHolderUtil.getMemberId(); | ||
Member member = getMemberById(accessMemberId); | ||
Project project = getProjectById(projectId); | ||
ProjectComment comment = getCommentById(commentId); | ||
ProjectCommentLikeDislikeId projectCommentLikeDislikeId = | ||
new ProjectCommentLikeDislikeId(member.getId(), comment.getId()); | ||
|
||
if (accessMemberId.equals(comment.getMember().getId())) { | ||
throw new MyCommunityForbiddenException(403, "내가 작성한 글은 비추천할 수 없습니다."); | ||
} | ||
|
||
projectCommentLikeDislikeRepository.findById(projectCommentLikeDislikeId).ifPresentOrElse( | ||
ProjectCommentLikeDislike -> { | ||
LikeStatus status = ProjectCommentLikeDislike.getStatus(); | ||
|
||
if (status == LikeStatus.B) { | ||
changeIsDeletedStatus(ProjectCommentLikeDislike); | ||
} | ||
|
||
if (status == LikeStatus.G) { | ||
if (ProjectCommentLikeDislike.getIsDeleted()) { | ||
projectCommentLikeDislikeRepository.restoreById(projectCommentLikeDislikeId); | ||
} | ||
projectCommentLikeDislikeRepository.updateLikeDislike(projectCommentLikeDislikeId, LikeStatus.B); | ||
} | ||
}, | ||
() -> { | ||
ProjectCommentLikeDislike commentLikeDislike = | ||
projectCommentLikeDislikeMapper.toProjectCommentLikeDislike(member, comment, LikeStatus.B); | ||
projectCommentLikeDislikeRepository.save(commentLikeDislike); | ||
} | ||
); | ||
updateLikeDislike(projectCommentLikeDislikeId.getCommentId()); | ||
} | ||
|
||
private void updateLikeDislike(Long projectId) { | ||
Long likes = Long.valueOf(projectCommentLikeDislikeRepository.countProjectLikeDislikeById(projectId, LikeStatus.G)); | ||
Long disLikes = Long.valueOf(projectCommentLikeDislikeRepository.countProjectLikeDislikeById(projectId, LikeStatus.B)); | ||
projectCommentRepository.updateLikeDislike(likes, disLikes, projectId); | ||
} | ||
|
||
private void changeIsDeletedStatus(ProjectCommentLikeDislike projectCommentLikeDislike) { | ||
if (projectCommentLikeDislike.getIsDeleted()) { | ||
projectCommentLikeDislikeRepository.restoreById(projectCommentLikeDislike.getId()); | ||
} | ||
if (!projectCommentLikeDislike.getIsDeleted()) { | ||
projectCommentLikeDislikeRepository.deleteById(projectCommentLikeDislike.getId()); | ||
} | ||
} | ||
|
||
private Member getMemberById(Long memberId) { | ||
return memberRepository.findById(memberId).orElseThrow(() -> new DataNotFoundException()); | ||
} | ||
|
||
private ProjectComment getCommentById(Long commentId) { | ||
return projectCommentRepository.findById(commentId).orElseThrow(() -> new DataNotFoundException()); | ||
} | ||
|
||
private Project getProjectById(Long projectId) { | ||
return projectRepository.findById(projectId).orElseThrow(() -> new DataNotFoundException()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...le/src/main/java/org/devridge/api/application/community/project/ProjectCommentMapper.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 org.devridge.api.application.community.project; | ||
|
||
import org.devridge.api.domain.community.dto.request.ProjectCommentRequest; | ||
import org.devridge.api.domain.community.entity.Project; | ||
import org.devridge.api.domain.community.entity.ProjectComment; | ||
import org.devridge.api.domain.member.entity.Member; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ProjectCommentMapper { | ||
|
||
public ProjectComment toProjectComment(Project project, Member member, ProjectCommentRequest Request) { | ||
return ProjectComment.builder() | ||
.project(project) | ||
.content(Request.getContent()) | ||
.member(member) | ||
.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.