Skip to content

Commit aca1ed3

Browse files
authored
Merge pull request #139 from devridge-team-project/main
Release v0.0.5
2 parents 342a3f9 + be73664 commit aca1ed3

File tree

96 files changed

+2774
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2774
-210
lines changed

api-module/src/main/java/org/devridge/api/application/community/freeboard/CommunityCommentService.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package org.devridge.api.application.community.freeboard;
22

3+
import java.util.List;
34
import lombok.RequiredArgsConstructor;
4-
5+
import org.devridge.api.common.exception.common.DataNotFoundException;
6+
import org.devridge.api.common.util.SecurityContextHolderUtil;
57
import org.devridge.api.domain.community.dto.request.CommunityCommentRequest;
68
import org.devridge.api.domain.community.dto.response.CommunityCommentResponse;
79
import org.devridge.api.domain.community.entity.Community;
810
import org.devridge.api.domain.community.entity.CommunityComment;
911
import org.devridge.api.domain.community.exception.MyCommunityForbiddenException;
12+
import org.devridge.api.domain.member.entity.Member;
1013
import org.devridge.api.infrastructure.community.freeboard.CommunityCommentQuerydslReopsitory;
1114
import org.devridge.api.infrastructure.community.freeboard.CommunityCommentRepository;
1215
import org.devridge.api.infrastructure.community.freeboard.CommunityRepository;
13-
import org.devridge.api.domain.member.entity.Member;
1416
import org.devridge.api.infrastructure.member.MemberRepository;
15-
import org.devridge.api.common.exception.common.DataNotFoundException;
16-
import org.devridge.api.common.util.SecurityContextHolderUtil;
17-
1817
import org.springframework.data.domain.Pageable;
19-
import org.springframework.data.domain.Slice;
2018
import org.springframework.stereotype.Service;
2119

2220
@RequiredArgsConstructor
@@ -39,7 +37,7 @@ public Long createComment(Long communityId, CommunityCommentRequest commentReque
3937
return communityCommentRepository.save(communityComment).getId();
4038
}
4139

42-
public Slice<CommunityCommentResponse> getAllCommunityComment(Long communityId, Long lastId, Pageable pageable) {
40+
public List<CommunityCommentResponse> getAllCommunityComment(Long communityId, Long lastId, Pageable pageable) {
4341
return communityCommentQuerydslReopsitory.searchBySlice(communityId, lastId, pageable);
4442
}
4543

api-module/src/main/java/org/devridge/api/application/community/freeboard/CommunityMapper.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package org.devridge.api.application.community.freeboard;
22

3+
import static org.devridge.api.common.util.MemberUtil.toMember;
4+
35
import java.util.ArrayList;
46
import java.util.List;
57
import java.util.stream.Collectors;
6-
78
import org.devridge.api.common.dto.UserInformation;
89
import org.devridge.api.domain.community.dto.request.CreateCommunityRequest;
910
import org.devridge.api.domain.community.dto.response.CommunityDetailResponse;
1011
import org.devridge.api.domain.community.dto.response.CommunityListResponse;
1112
import org.devridge.api.domain.community.entity.Community;
1213
import org.devridge.api.domain.member.entity.Member;
13-
1414
import org.springframework.stereotype.Component;
1515

16-
import static org.devridge.api.common.util.MemberUtil.toMember;
17-
1816
@Component
1917
public class CommunityMapper {
2018

@@ -26,9 +24,9 @@ public CommunityDetailResponse toCommunityDetailResponse(Community community) {
2624
.userInformation(memberInfoResponse)
2725
.title(community.getTitle())
2826
.content(community.getContent())
29-
.likeCount(community.getLikeCount())
30-
.dislikeCount(community.getDislikeCount())
31-
.viewCount(community.getViewCount() + 1)
27+
.likes(community.getLikes())
28+
.dislikes(community.getDislikes())
29+
.views(community.getViews() + 1)
3230
.createdAt(community.getCreatedAt())
3331
.updatedAt(community.getUpdatedAt())
3432
.hashtags(toHashtags(community))
@@ -47,9 +45,9 @@ public CommunityListResponse toCommunityListResponse(Community community) {
4745
return CommunityListResponse.builder()
4846
.id(community.getId())
4947
.title(community.getTitle())
50-
.commentCount(Long.valueOf(community.getComments().size()))
51-
.viewCount(community.getViewCount())
52-
.likeCount(community.getLikeCount())
48+
.comments(Long.valueOf(community.getComments().size()))
49+
.views(community.getViews())
50+
.likes(community.getLikes())
5351
.build();
5452
}
5553

api-module/src/main/java/org/devridge/api/application/community/freeboard/CommunityService.java

+6-25
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import java.util.Map;
88
import java.util.Objects;
99
import java.util.stream.Collectors;
10-
1110
import lombok.RequiredArgsConstructor;
12-
11+
import org.devridge.api.application.s3.S3Service;
12+
import org.devridge.api.common.exception.common.DataNotFoundException;
13+
import org.devridge.api.common.util.SecurityContextHolderUtil;
1314
import org.devridge.api.domain.community.dto.request.CreateCommunityRequest;
1415
import org.devridge.api.domain.community.dto.response.CommunityDetailResponse;
1516
import org.devridge.api.domain.community.dto.response.CommunitySliceResponse;
@@ -19,19 +20,13 @@
1920
import org.devridge.api.domain.community.entity.Hashtag;
2021
import org.devridge.api.domain.community.entity.id.CommunityHashtagId;
2122
import org.devridge.api.domain.community.exception.MyCommunityForbiddenException;
23+
import org.devridge.api.domain.member.entity.Member;
2224
import org.devridge.api.infrastructure.community.freeboard.CommunityHashtagRepository;
2325
import org.devridge.api.infrastructure.community.freeboard.CommunityQuerydslRepository;
2426
import org.devridge.api.infrastructure.community.freeboard.CommunityRepository;
2527
import org.devridge.api.infrastructure.community.hashtag.HashtagRepository;
26-
import org.devridge.api.domain.member.entity.Member;
2728
import org.devridge.api.infrastructure.member.MemberRepository;
28-
import org.devridge.api.application.s3.S3Service;
29-
import org.devridge.api.common.exception.common.DataNotFoundException;
30-
import org.devridge.api.common.util.SecurityContextHolderUtil;
31-
3229
import org.springframework.data.domain.Pageable;
33-
import org.springframework.data.domain.Slice;
34-
import org.springframework.data.domain.SliceImpl;
3530
import org.springframework.stereotype.Service;
3631
import org.springframework.transaction.annotation.Transactional;
3732

@@ -94,25 +89,11 @@ public void deleteCommunity(Long communityId) {
9489
}
9590
}
9691

97-
public Slice<CommunitySliceResponse> getAllCommunity(Long lastId, Pageable pageable) {
92+
public List<CommunitySliceResponse> getAllCommunity(Long lastId, Pageable pageable) {
9893
List<CommunitySliceResponse> communitySliceResponses = communityQuerydslRepository.searchByCommunity(lastId, pageable);
9994
List<Long> communityIds = toCommunityIds(communitySliceResponses);
10095
List<CommunityHashtag> communityHashtags = communityQuerydslRepository.findCommunityHashtagsInCommunityIds(communityIds);
101-
List<CommunitySliceResponse> groupedByCommunitySliceResponses = groupByCommunityId(communityHashtags, communitySliceResponses);
102-
return checkLastPage(pageable, groupedByCommunitySliceResponses);
103-
}
104-
105-
private Slice<CommunitySliceResponse> checkLastPage(Pageable pageable, List<CommunitySliceResponse> results) {
106-
107-
boolean hasNext = false;
108-
109-
// 조회한 결과 개수가 요청한 페이지 사이즈보다 크면 뒤에 더 있음, next = true
110-
if (results.size() > pageable.getPageSize()) {
111-
hasNext = true;
112-
results.remove(pageable.getPageSize());
113-
}
114-
115-
return new SliceImpl<>(results, pageable, hasNext);
96+
return groupByCommunityId(communityHashtags, communitySliceResponses);
11697
}
11798

11899
private List<CommunitySliceResponse> groupByCommunityId(List<CommunityHashtag> communityHashtags, List<CommunitySliceResponse> communitySliceResponses) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.devridge.api.application.community.project;
2+
3+
import org.devridge.api.domain.community.entity.LikeStatus;
4+
import org.devridge.api.domain.community.entity.ProjectComment;
5+
import org.devridge.api.domain.community.entity.ProjectCommentLikeDislike;
6+
import org.devridge.api.domain.member.entity.Member;
7+
import org.springframework.stereotype.Component;
8+
9+
@Component
10+
public class ProjectCommentLikeDislikeMapper {
11+
12+
public ProjectCommentLikeDislike toProjectCommentLikeDislike(
13+
Member member,
14+
ProjectComment comment,
15+
LikeStatus status
16+
) {
17+
return ProjectCommentLikeDislike.builder()
18+
.projectComment(comment)
19+
.member(member)
20+
.status(status)
21+
.build();
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package org.devridge.api.application.community.project;
2+
3+
import javax.transaction.Transactional;
4+
import lombok.RequiredArgsConstructor;
5+
import org.devridge.api.common.exception.common.DataNotFoundException;
6+
import org.devridge.api.common.util.SecurityContextHolderUtil;
7+
import org.devridge.api.domain.community.entity.LikeStatus;
8+
import org.devridge.api.domain.community.entity.Project;
9+
import org.devridge.api.domain.community.entity.ProjectComment;
10+
import org.devridge.api.domain.community.entity.ProjectCommentLikeDislike;
11+
import org.devridge.api.domain.community.entity.id.ProjectCommentLikeDislikeId;
12+
import org.devridge.api.domain.community.exception.MyCommunityForbiddenException;
13+
import org.devridge.api.domain.member.entity.Member;
14+
import org.devridge.api.infrastructure.community.project.ProjectCommentLikeDislikeRepository;
15+
import org.devridge.api.infrastructure.community.project.ProjectCommentRepository;
16+
import org.devridge.api.infrastructure.community.project.ProjectRepository;
17+
import org.devridge.api.infrastructure.member.MemberRepository;
18+
import org.springframework.stereotype.Service;
19+
20+
@RequiredArgsConstructor
21+
@Service
22+
public class ProjectCommentLikeDislikeService {
23+
24+
private final ProjectCommentLikeDislikeRepository projectCommentLikeDislikeRepository;
25+
private final ProjectCommentRepository projectCommentRepository;
26+
private final MemberRepository memberRepository;
27+
private final ProjectCommentLikeDislikeMapper projectCommentLikeDislikeMapper;
28+
private final ProjectRepository projectRepository;
29+
30+
@Transactional
31+
public void createProjectCommentLike(Long projectId, Long commentId) {
32+
Long accessMemberId = SecurityContextHolderUtil.getMemberId();
33+
Member member = getMemberById(accessMemberId);
34+
Project project = getProjectById(projectId);
35+
ProjectComment comment = getCommentById(commentId);
36+
ProjectCommentLikeDislikeId projectCommentLikeDislikeId =
37+
new ProjectCommentLikeDislikeId(member.getId(), comment.getId());
38+
39+
if (accessMemberId.equals(comment.getMember().getId())) {
40+
throw new MyCommunityForbiddenException(403, "내가 작성한 글은 추천할 수 없습니다.");
41+
}
42+
43+
projectCommentLikeDislikeRepository.findById(projectCommentLikeDislikeId).ifPresentOrElse(
44+
ProjectCommentLikeDislike -> {
45+
LikeStatus status = ProjectCommentLikeDislike.getStatus();
46+
47+
if (status == LikeStatus.G) {
48+
changeIsDeletedStatus(ProjectCommentLikeDislike);
49+
}
50+
51+
if (status == LikeStatus.B) {
52+
if (ProjectCommentLikeDislike.getIsDeleted()) {
53+
projectCommentLikeDislikeRepository.restoreById(projectCommentLikeDislikeId);
54+
}
55+
projectCommentLikeDislikeRepository.updateLikeDislike(projectCommentLikeDislikeId,
56+
LikeStatus.G);
57+
}
58+
},
59+
() -> {
60+
ProjectCommentLikeDislike commentLikeDislike =
61+
projectCommentLikeDislikeMapper.toProjectCommentLikeDislike(member, comment, LikeStatus.G);
62+
projectCommentLikeDislikeRepository.save(commentLikeDislike);
63+
}
64+
);
65+
updateLikeDislike(projectCommentLikeDislikeId.getCommentId());
66+
}
67+
68+
@Transactional
69+
public void createProjectCommentDislike(Long projectId, Long commentId) {
70+
Long accessMemberId = SecurityContextHolderUtil.getMemberId();
71+
Member member = getMemberById(accessMemberId);
72+
Project project = getProjectById(projectId);
73+
ProjectComment comment = getCommentById(commentId);
74+
ProjectCommentLikeDislikeId projectCommentLikeDislikeId =
75+
new ProjectCommentLikeDislikeId(member.getId(), comment.getId());
76+
77+
if (accessMemberId.equals(comment.getMember().getId())) {
78+
throw new MyCommunityForbiddenException(403, "내가 작성한 글은 비추천할 수 없습니다.");
79+
}
80+
81+
projectCommentLikeDislikeRepository.findById(projectCommentLikeDislikeId).ifPresentOrElse(
82+
ProjectCommentLikeDislike -> {
83+
LikeStatus status = ProjectCommentLikeDislike.getStatus();
84+
85+
if (status == LikeStatus.B) {
86+
changeIsDeletedStatus(ProjectCommentLikeDislike);
87+
}
88+
89+
if (status == LikeStatus.G) {
90+
if (ProjectCommentLikeDislike.getIsDeleted()) {
91+
projectCommentLikeDislikeRepository.restoreById(projectCommentLikeDislikeId);
92+
}
93+
projectCommentLikeDislikeRepository.updateLikeDislike(projectCommentLikeDislikeId, LikeStatus.B);
94+
}
95+
},
96+
() -> {
97+
ProjectCommentLikeDislike commentLikeDislike =
98+
projectCommentLikeDislikeMapper.toProjectCommentLikeDislike(member, comment, LikeStatus.B);
99+
projectCommentLikeDislikeRepository.save(commentLikeDislike);
100+
}
101+
);
102+
updateLikeDislike(projectCommentLikeDislikeId.getCommentId());
103+
}
104+
105+
private void updateLikeDislike(Long projectId) {
106+
Long likes = Long.valueOf(projectCommentLikeDislikeRepository.countProjectLikeDislikeById(projectId, LikeStatus.G));
107+
Long disLikes = Long.valueOf(projectCommentLikeDislikeRepository.countProjectLikeDislikeById(projectId, LikeStatus.B));
108+
projectCommentRepository.updateLikeDislike(likes, disLikes, projectId);
109+
}
110+
111+
private void changeIsDeletedStatus(ProjectCommentLikeDislike projectCommentLikeDislike) {
112+
if (projectCommentLikeDislike.getIsDeleted()) {
113+
projectCommentLikeDislikeRepository.restoreById(projectCommentLikeDislike.getId());
114+
}
115+
if (!projectCommentLikeDislike.getIsDeleted()) {
116+
projectCommentLikeDislikeRepository.deleteById(projectCommentLikeDislike.getId());
117+
}
118+
}
119+
120+
private Member getMemberById(Long memberId) {
121+
return memberRepository.findById(memberId).orElseThrow(() -> new DataNotFoundException());
122+
}
123+
124+
private ProjectComment getCommentById(Long commentId) {
125+
return projectCommentRepository.findById(commentId).orElseThrow(() -> new DataNotFoundException());
126+
}
127+
128+
private Project getProjectById(Long projectId) {
129+
return projectRepository.findById(projectId).orElseThrow(() -> new DataNotFoundException());
130+
}
131+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.devridge.api.application.community.project;
2+
3+
import org.devridge.api.domain.community.dto.request.ProjectCommentRequest;
4+
import org.devridge.api.domain.community.entity.Project;
5+
import org.devridge.api.domain.community.entity.ProjectComment;
6+
import org.devridge.api.domain.member.entity.Member;
7+
import org.springframework.stereotype.Component;
8+
9+
@Component
10+
public class ProjectCommentMapper {
11+
12+
public ProjectComment toProjectComment(Project project, Member member, ProjectCommentRequest Request) {
13+
return ProjectComment.builder()
14+
.project(project)
15+
.content(Request.getContent())
16+
.member(member)
17+
.build();
18+
}
19+
20+
}

0 commit comments

Comments
 (0)