Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/community : 커뮤니티/댓글/좋아요 진짜 90% 완성 #10

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
//@EnableDiscoveryClient

@EnableJpaAuditing
@EnableFeignClients
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@

@RestController
@AllArgsConstructor
@RequestMapping("/topic/{topic}/community/{communityId}/comments")
@RequestMapping("/topic/{topicId}/community/{communityId}/comments")
public class CommentController {

private final CommentCreateUseCase commentCreateUseCase;
private final CommentReadUseCase commentReadUseCase;

@PostMapping
public ResponseEntity<SuccessResponse<List<CommentRes>>> createComment(@RequestHeader(value = "user-id") String socialId,
@PathVariable("topic") String topic,@PathVariable("communityId") Long communityId, @RequestBody CommentReq commentReq) {
@PathVariable("topicId") Long topicId,@PathVariable("communityId") Long communityId, @RequestBody CommentReq commentReq) {
return ResponseEntity.ok(SuccessResponse.create(CommentResponseMessage.CREATE_COMMENT_SUCCESS.getMessage(), this.commentCreateUseCase.create(socialId, communityId, commentReq)));
}

@GetMapping
public ResponseEntity<SuccessResponse<List<CommentRes>>> getComments(@RequestHeader(value = "user-id") String socialId,
@PathVariable("topic") String topic,@PathVariable("communityId") Long communityId) {
@PathVariable("topicId") Long topicId,@PathVariable("communityId") Long communityId) {
return ResponseEntity.ok(SuccessResponse.create(CommentResponseMessage.GET_COMMENT_SUCCESS.getMessage(), this.commentReadUseCase.getCommentsByCommunity(communityId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
@AllArgsConstructor
@NoArgsConstructor
public class CommunityReq {

private String title;
private String talk;
private String communityText;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,38 @@
public class CommunityRes {

private Long id;
private String title;
private String talk;
private String communityText;
private String date;

private String writerId;
private String nickname;
private String profileImg;

private String topic;
private String issue;
private String area;
private String subject;
private String keyword;

private Long heartsNum;
private Long commentsNum;
private Long likeCount;
private Long commentCount;

public CommunityRes(Long id, String title, String talk, LocalDateTime date, String writerId,
String topic, String issue, String keyword, Long heartsNum, Long commentsNum) {
private Long contentsId;
private String contents;

private String likeStatus;

public CommunityRes(Long id, String talk, LocalDateTime date, String writerId,
String topic, String issue, String keyword, Long heartsNum, Long commentsNum,Long contentsId, String likeStatus) {
this.id = id;
this.title = title;
this.talk = talk;
this.communityText = talk;
this.date = date.toString();
this.writerId = writerId;
this.topic = topic;
this.issue = issue;
this.area = topic;
this.subject = issue;
this.keyword = keyword;
this.heartsNum = heartsNum;
this.commentsNum = commentsNum;
this.likeCount = heartsNum;
this.commentCount = commentsNum;
this.contentsId = contentsId;
this.likeStatus = likeStatus;
}

public CommunityRes(String nickname, String profileImg) {
Expand All @@ -50,4 +55,11 @@ public void updateMemberDto(MemberDto memberDto) {
this.nickname = memberDto.getNickname();
this.profileImg = memberDto.getProfileImage();
}

public void updateContentsDto(ContentsDto contentsDto) {
this.area = contentsDto.getTopic();
this.subject = contentsDto.getIssue();
this.keyword = contentsDto.getKeyword();
this.contents = contentsDto.getContents();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ public class CommunityMapper {

public Community mapToCommunity(String memberId, ContentsDto contentsDto, CommunityReq communityReq){
return Community.builder()
.title(communityReq.getTitle())
.talk(communityReq.getTalk())
.talk(communityReq.getCommunityText())
.contentsId(contentsDto.getContentsId())
.contents(contentsDto.getContents())
.writerId(memberId)
.keyword(contentsDto.getKeyword())
.issue(contentsDto.getIssue())
Expand All @@ -26,16 +24,15 @@ public Community mapToCommunity(String memberId, ContentsDto contentsDto, Commun
public CommunityRes mapToCommunityRes(Community community, MemberDto memberDto, ContentsDto contentsDto) {
return CommunityRes.builder()
.id(community.getId())
.title(community.getTitle())
.talk(community.getTalk())
.communityText(community.getTalk())
.date(community.getCreatedAt().toString())
.writerId(memberDto.getMemberId())
.nickname(memberDto.getNickname())
.profileImg(memberDto.getProfileImage())

.contents(contentsDto.getContents())
.keyword(contentsDto.getKeyword())
.issue(contentsDto.getIssue())
.topic(contentsDto.getTopic())
.subject(contentsDto.getIssue())
.area(contentsDto.getTopic())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,28 @@ public class CommunityReadUseCase {
// private final DomainGetService domainGetService;


public List<CommunityRes> getCommunityList(String topic) {
public List<CommunityRes> getCommunityList(String memberId,Long topicId) {
// domainGetService.getDomainByName(domain)

return communityQueryService.getAllCommunityByTopic(topic);
String topic = "환경"; //topicId to topicString
return communityQueryService.getAllCommunityByTopic(memberId,topic);
}
public List<CommunityRes> getAllCommunityList() {
public List<CommunityRes> getAllCommunityList(String memberId) {
// domainGetService.getDomainByName(domain)

return communityQueryService.getAllCommunity();
return communityQueryService.getAllCommunity(memberId);
}
public CommunityRes getCommunityDetail(String domain,Long communityId) {
public CommunityRes getCommunityDetail(String memberId,Long topicId,Long communityId) {
// domainGetService.getDomainByName(domain)
return communityQueryService.getCommunity(communityId);

return communityQueryService.getCommunity(memberId,communityId);
}

public List<CommunityRes> getCommunityTop5ByHearts(String orderBy, String word) {
public List<CommunityRes> getCommunityTop5ByHearts(String memberId,String orderBy, Long wordId) {

// orderBy + word -> string
String word = "환경";

return communityQueryService.getCommunityTop5(CommunityOrderCondition.valueOf(orderBy), word);
return communityQueryService.getCommunityTop5(memberId,CommunityOrderCondition.valueOf(orderBy), word);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ public class Community extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "community_id")
private Long id;
private String title;
private String talk;

private String writerId;

private Long contentsId; //keyword,issue,domain 불러오기 위함
private String contents; // 인용하기 위함

// private String contents; // 인용하기 위함
//
private String keyword; //변하지 않음, contentsId로 가져오기
private String issue; //변하지 않음 , contentsId로 가져오기
private String topic; //변하지 않음, contentsId로 가져오기
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gwangjang.server.domain.community.domain.repository;

import gwangjang.server.domain.community.application.dto.res.CommunityRes;
import gwangjang.server.domain.community.domain.entity.Community;
import gwangjang.server.domain.community.domain.entity.constant.CommunityOrderCondition;

import java.util.List;
Expand All @@ -9,11 +10,11 @@
public interface CommunityCustomRepository {


Optional<List<CommunityRes>> findAllCommunityByTopic(String topic);
Optional<List<CommunityRes>> findAllCommunity();
Optional<CommunityRes> findCommunity(Long communityId);
Optional<List<CommunityRes>> findCommunityTop5ByHeartsAndTopic(String topic);
Optional<List<CommunityRes>> findAllCommunityByTopic(String memberId, String topic);
Optional<List<CommunityRes>> findAllCommunity(String memberId);
Optional<CommunityRes> findCommunity(String memberId,Long communityId);
Optional<List<CommunityRes>> findCommunityTop5ByHeartsAndTopic(String memberId,String topic);

Optional<List<CommunityRes>> findCommunityTop5(CommunityOrderCondition orderCondition, String word);
Optional<List<CommunityRes>> findCommunityTop5(String memberId,CommunityOrderCondition orderCondition, String word);

}
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
package gwangjang.server.domain.community.domain.repository;

import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import gwangjang.server.domain.community.application.dto.res.CommunityRes;
import gwangjang.server.domain.community.domain.entity.Community;
import gwangjang.server.domain.community.domain.entity.constant.CommunityOrderCondition;
import jakarta.persistence.EntityManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static gwangjang.server.domain.community.domain.entity.QCommunity.community;
import static gwangjang.server.domain.heart.domain.entity.QHeart.heart;

public class CommunityRepositoryImpl implements CommunityCustomRepository {
public class CommunityCustomRepositoryImpl implements CommunityCustomRepository {

private final JPAQueryFactory queryFactory;

public CommunityRepositoryImpl(EntityManager em) {
public CommunityCustomRepositoryImpl(EntityManager em) {
this.queryFactory = new JPAQueryFactory(em);
}


@Override
public Optional<List<CommunityRes>> findAllCommunityByTopic(String topic) {
public Optional<List<CommunityRes>> findAllCommunityByTopic(String memberId,String topic) {

BooleanExpression memberHeartExists = JPAExpressions
.selectOne()
.from(heart)
.where(
heart.community.id.eq(community.id),
heart.pusherId.eq(memberId),
heart.status.eq(Boolean.TRUE))
.exists();

return Optional.ofNullable(
queryFactory
.select(Projections.constructor(CommunityRes.class,
community.id,
community.title,
community.talk,
community.createdAt,
community.writerId,
community.topic,
community.issue,
community.keyword,
community.hearts.size().longValue(),
community.comments.size().longValue()
community.comments.size().longValue(),
community.contentsId,
memberHeartExists.stringValue()

))
.from(community)
.where(community.topic.eq(topic))
Expand All @@ -48,20 +59,31 @@ public Optional<List<CommunityRes>> findAllCommunityByTopic(String topic) {
);
}
@Override
public Optional<List<CommunityRes>> findAllCommunity() {
public Optional<List<CommunityRes>> findAllCommunity(String memberId) {

BooleanExpression memberHeartExists = JPAExpressions
.selectOne()
.from(heart)
.where(
heart.community.id.eq(community.id),
heart.pusherId.eq(memberId),
heart.status.eq(Boolean.TRUE))
.exists();

return Optional.ofNullable(
queryFactory
.select(Projections.constructor(CommunityRes.class,
community.id,
community.title,
community.talk,
community.createdAt,
community.writerId,
community.topic,
community.issue,
community.keyword,
community.hearts.size().longValue(),
community.comments.size().longValue()
community.comments.size().longValue(),
community.contentsId,
memberHeartExists.stringValue()
))
.from(community)
.orderBy(community.createdAt.desc())
Expand All @@ -70,20 +92,30 @@ public Optional<List<CommunityRes>> findAllCommunity() {
}

@Override
public Optional<CommunityRes> findCommunity(Long communityId) {
public Optional<CommunityRes> findCommunity(String memberId,Long communityId) {
BooleanExpression memberHeartExists = JPAExpressions
.selectOne()
.from(heart)
.where(
heart.community.id.eq(community.id),
heart.pusherId.eq(memberId),
heart.status.eq(Boolean.TRUE))
.exists();

return Optional.ofNullable(
queryFactory
.select(Projections.constructor(CommunityRes.class,
community.id,
community.title,
community.talk,
community.createdAt,
community.writerId,
community.topic,
community.issue,
community.keyword,
community.hearts.size().longValue(),
community.comments.size().longValue()
community.comments.size().longValue(),
community.contentsId,
memberHeartExists.stringValue()
))
.from(community)
.where(community.id.eq(communityId))
Expand All @@ -92,26 +124,36 @@ public Optional<CommunityRes> findCommunity(Long communityId) {
}

@Override
public Optional<List<CommunityRes>> findCommunityTop5ByHeartsAndTopic(String topic) {
public Optional<List<CommunityRes>> findCommunityTop5ByHeartsAndTopic(String memberId,String topic) {

return Optional.empty();
}

@Override
public Optional<List<CommunityRes>> findCommunityTop5(CommunityOrderCondition orderCondition, String word) {
public Optional<List<CommunityRes>> findCommunityTop5(String memberId,CommunityOrderCondition orderCondition, String word) {

BooleanExpression memberHeartExists = JPAExpressions
.selectOne()
.from(heart)
.where(
heart.community.id.eq(community.id),
heart.pusherId.eq(memberId),
heart.status.eq(Boolean.TRUE))
.exists();

return Optional.ofNullable(queryFactory
.select(Projections.constructor(CommunityRes.class,
community.id,
community.title,
community.talk,
community.createdAt,
community.writerId,
community.topic,
community.issue,
community.keyword,
community.hearts.size().longValue(),
community.comments.size().longValue()
community.comments.size().longValue(),
community.contentsId,
memberHeartExists.stringValue()
))
.from(community)
.where(
Expand Down
Loading