diff --git a/src/main/java/gwangjang/server/CommunityServiceApplication.java b/src/main/java/gwangjang/server/CommunityServiceApplication.java index 13328bd..21620b1 100644 --- a/src/main/java/gwangjang/server/CommunityServiceApplication.java +++ b/src/main/java/gwangjang/server/CommunityServiceApplication.java @@ -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 diff --git a/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java b/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java index 3d277af..908e58f 100644 --- a/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java +++ b/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java @@ -20,7 +20,7 @@ @RestController @AllArgsConstructor -@RequestMapping("/topic/{topic}/community/{communityId}/comments") +@RequestMapping("/topic/{topicId}/community/{communityId}/comments") public class CommentController { private final CommentCreateUseCase commentCreateUseCase; @@ -28,13 +28,13 @@ public class CommentController { @PostMapping public ResponseEntity>> 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>> 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))); } } diff --git a/src/main/java/gwangjang/server/domain/community/application/dto/req/CommunityReq.java b/src/main/java/gwangjang/server/domain/community/application/dto/req/CommunityReq.java index 9519fb4..7d63e3f 100644 --- a/src/main/java/gwangjang/server/domain/community/application/dto/req/CommunityReq.java +++ b/src/main/java/gwangjang/server/domain/community/application/dto/req/CommunityReq.java @@ -11,8 +11,6 @@ @AllArgsConstructor @NoArgsConstructor public class CommunityReq { - - private String title; - private String talk; + private String communityText; } diff --git a/src/main/java/gwangjang/server/domain/community/application/dto/res/CommunityRes.java b/src/main/java/gwangjang/server/domain/community/application/dto/res/CommunityRes.java index b99ba3e..f984929 100644 --- a/src/main/java/gwangjang/server/domain/community/application/dto/res/CommunityRes.java +++ b/src/main/java/gwangjang/server/domain/community/application/dto/res/CommunityRes.java @@ -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) { @@ -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(); + } } diff --git a/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java b/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java index b6ebf31..ee211d8 100644 --- a/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java +++ b/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java @@ -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()) @@ -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(); } diff --git a/src/main/java/gwangjang/server/domain/community/application/service/CommunityReadUseCase.java b/src/main/java/gwangjang/server/domain/community/application/service/CommunityReadUseCase.java index 4828be5..8ee99f7 100644 --- a/src/main/java/gwangjang/server/domain/community/application/service/CommunityReadUseCase.java +++ b/src/main/java/gwangjang/server/domain/community/application/service/CommunityReadUseCase.java @@ -18,23 +18,28 @@ public class CommunityReadUseCase { // private final DomainGetService domainGetService; - public List getCommunityList(String topic) { + public List getCommunityList(String memberId,Long topicId) { // domainGetService.getDomainByName(domain) - return communityQueryService.getAllCommunityByTopic(topic); + String topic = "환경"; //topicId to topicString + return communityQueryService.getAllCommunityByTopic(memberId,topic); } - public List getAllCommunityList() { + public List 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 getCommunityTop5ByHearts(String orderBy, String word) { + public List 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); } } diff --git a/src/main/java/gwangjang/server/domain/community/domain/entity/Community.java b/src/main/java/gwangjang/server/domain/community/domain/entity/Community.java index 706a901..936a417 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/entity/Community.java +++ b/src/main/java/gwangjang/server/domain/community/domain/entity/Community.java @@ -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로 가져오기 diff --git a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepository.java b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepository.java index ffacbf5..635a3d9 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepository.java +++ b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepository.java @@ -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; @@ -9,11 +10,11 @@ public interface CommunityCustomRepository { - Optional> findAllCommunityByTopic(String topic); - Optional> findAllCommunity(); - Optional findCommunity(Long communityId); - Optional> findCommunityTop5ByHeartsAndTopic(String topic); + Optional> findAllCommunityByTopic(String memberId, String topic); + Optional> findAllCommunity(String memberId); + Optional findCommunity(String memberId,Long communityId); + Optional> findCommunityTop5ByHeartsAndTopic(String memberId,String topic); - Optional> findCommunityTop5(CommunityOrderCondition orderCondition, String word); + Optional> findCommunityTop5(String memberId,CommunityOrderCondition orderCondition, String word); } diff --git a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepositoryImpl.java similarity index 65% rename from src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java rename to src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepositoryImpl.java index ea6a112..5556362 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java +++ b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepositoryImpl.java @@ -1,37 +1,45 @@ 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> findAllCommunityByTopic(String topic) { + public Optional> 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, @@ -39,7 +47,10 @@ public Optional> findAllCommunityByTopic(String 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)) @@ -48,12 +59,21 @@ public Optional> findAllCommunityByTopic(String topic) { ); } @Override - public Optional> findAllCommunity() { + public Optional> 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, @@ -61,7 +81,9 @@ public Optional> findAllCommunity() { 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()) @@ -70,12 +92,20 @@ public Optional> findAllCommunity() { } @Override - public Optional findCommunity(Long communityId) { + public Optional 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, @@ -83,7 +113,9 @@ public Optional findCommunity(Long communityId) { 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)) @@ -92,18 +124,26 @@ public Optional findCommunity(Long communityId) { } @Override - public Optional> findCommunityTop5ByHeartsAndTopic(String topic) { + public Optional> findCommunityTop5ByHeartsAndTopic(String memberId,String topic) { return Optional.empty(); } @Override - public Optional> findCommunityTop5(CommunityOrderCondition orderCondition, String word) { + public Optional> 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, @@ -111,7 +151,9 @@ public Optional> findCommunityTop5(CommunityOrderCondition or community.issue, community.keyword, community.hearts.size().longValue(), - community.comments.size().longValue() + community.comments.size().longValue(), + community.contentsId, + memberHeartExists.stringValue() )) .from(community) .where( diff --git a/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java b/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java index 5a092a0..8601a65 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java +++ b/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java @@ -20,14 +20,12 @@ public class CommunityQueryService { private final CommunityRepository communityRepository; private final FindMemberFeignClient findMemberFeignClient; - private final CommunityMapper communityMapper = new CommunityMapper(); - public Community getCommunityById(Long communityId) { return communityRepository.findById(communityId).orElseThrow(NotFoundCommunityException::new ); } - public List getAllCommunityByTopic(String topic) { - List communityRes = communityRepository.findAllCommunityByTopic(topic).orElseThrow(NotFoundCommunityException::new); + public List getAllCommunityByTopic(String memberId,String topic) { + List communityRes = communityRepository.findAllCommunityByTopic(memberId,topic).orElseThrow(NotFoundCommunityException::new); communityRes.stream().forEach( communityRes1 -> { @@ -39,8 +37,8 @@ public List getAllCommunityByTopic(String topic) { return communityRes; } - public List getAllCommunity() { - List communityRes = communityRepository.findAllCommunity().orElseThrow(NotFoundCommunityException::new); + public List getAllCommunity(String memberId) { + List communityRes = communityRepository.findAllCommunity(memberId).orElseThrow(NotFoundCommunityException::new); communityRes.stream().forEach( communityRes1 -> { @@ -54,16 +52,19 @@ public List getAllCommunity() { } - public CommunityRes getCommunity(Long communityId) { - return communityRepository.findCommunity(communityId).orElseThrow(NotFoundCommunityException::new); - } + public CommunityRes getCommunity(String memberId,Long communityId) { + CommunityRes communityRes = communityRepository.findCommunity(memberId, communityId).orElseThrow(NotFoundCommunityException::new); + + String writerId = communityRes.getWriterId(); + MemberDto memberDto = findMemberFeignClient.getMemberBySocialId(writerId); + communityRes.updateMemberDto(memberDto); - public List getCommunityTop5ByHeartsAndTopic(String topic) { - return communityRepository.findCommunityTop5ByHeartsAndTopic(topic).orElseThrow(NotFoundCommunityException::new); + return communityRes; } - public List getCommunityTop5(CommunityOrderCondition communityOrderCondition, String with) { - List communityRes = communityRepository.findCommunityTop5(communityOrderCondition, with).orElseThrow(NotFoundCommunityException::new); + + public List getCommunityTop5(String memberId,CommunityOrderCondition communityOrderCondition, String with) { + List communityRes = communityRepository.findCommunityTop5(memberId,communityOrderCondition, with).orElseThrow(NotFoundCommunityException::new); communityRes.stream().forEach( communityRes1 -> diff --git a/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java b/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java index 07fa797..4b9a50a 100644 --- a/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java +++ b/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java @@ -39,40 +39,40 @@ public ResponseEntity> createCommunity(@RequestHea * @return */ @GetMapping("") - public ResponseEntity>> getCommunityList() { - return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getAllCommunityList())); + public ResponseEntity>> getCommunityList(@RequestHeader(value = "user-id") String socialId ) { + return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getAllCommunityList(socialId))); } /** * 커뮤니티 글 리스트업(영역별) - * @param topic 영역 정보 + * @param topicId 영역 정보 * @return */ - @GetMapping("/topic/{topic}") - public ResponseEntity>> getCommunityListByDomain(@PathVariable("topic") String topic) { - return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityList(topic))); + @GetMapping("/topic/{topicId}") + public ResponseEntity>> getCommunityListByDomain(@RequestHeader(value = "user-id") String socialId,@PathVariable("topicId") Long topicId) { + return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityList(socialId,topicId))); } /** * 커뮤니티 글 리스트텁(상세) - * @param topic 영역 정보 + * @param topicId 영역 정보 * @return */ - @GetMapping("/topic/{topic}/community/{communityId}") - public ResponseEntity> getCommunityDetail(@PathVariable("topic") String topic, @PathVariable("communityId") Long communityId) { - return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityDetail(topic,communityId))); + @GetMapping("/topic/{topicId}/community/{communityId}") + public ResponseEntity> getCommunityDetail(@RequestHeader(value = "user-id") String socialId, @PathVariable("topicId") Long topicId, @PathVariable("communityId") Long communityId) { + return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityDetail(socialId,topicId,communityId))); } /** * 커뮤니티 글 top5(영역/주제/키워드) * @param sortBy 정렬 조건 - * @param word 정렬 단어 + * @param wordId 정렬 단어 * @return */ - @GetMapping("/sortBy/{sortBy}/word/{word}") - public ResponseEntity>> getCommunityTop5(@PathVariable("sortBy") String sortBy,@PathVariable("word") String word ) { - return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityTop5ByHearts(sortBy,word))); + @GetMapping("/sortBy/{sortBy}/word/{wordId}") + public ResponseEntity>> getCommunityTop5(@RequestHeader(value = "user-id") String socialId, @PathVariable("sortBy") String sortBy,@PathVariable("wordId") Long wordId ) { + return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityTop5ByHearts(socialId,sortBy,wordId))); } diff --git a/src/main/java/gwangjang/server/domain/heart/application/mapper/HeartMapper.java b/src/main/java/gwangjang/server/domain/heart/application/mapper/HeartMapper.java index 2666291..84c3733 100644 --- a/src/main/java/gwangjang/server/domain/heart/application/mapper/HeartMapper.java +++ b/src/main/java/gwangjang/server/domain/heart/application/mapper/HeartMapper.java @@ -17,11 +17,11 @@ public HeartRes mapToHeartRes(Heart heart) { .build(); } - public Heart mapToHeart(String pusherId, Community community, String status) { + public Heart mapToHeart(String pusherId, Community community) { return Heart.builder() .pusherId(pusherId) .community(community) - .status(Boolean.parseBoolean(status)) + .status(Boolean.TRUE) .build(); } } diff --git a/src/main/java/gwangjang/server/domain/heart/application/service/HeartUpdateUseCase.java b/src/main/java/gwangjang/server/domain/heart/application/service/HeartUpdateUseCase.java index 94579d5..917a0a8 100644 --- a/src/main/java/gwangjang/server/domain/heart/application/service/HeartUpdateUseCase.java +++ b/src/main/java/gwangjang/server/domain/heart/application/service/HeartUpdateUseCase.java @@ -27,19 +27,19 @@ public class HeartUpdateUseCase { private final HeartMapper heartMapper = new HeartMapper(); - public HeartRes pushHeart(String pusherId, Long communityId, String heartStatus) { + public HeartRes pushHeart(String pusherId, Long communityId) { Optional heart = heartQueryService.getHeartById(pusherId, communityId); if (heart.isPresent()) { // update Heart updateHeart = heart.get(); - updateHeart.updateHeart(heartStatus); + updateHeart.updateHeart(); return heartMapper.mapToHeartRes(updateHeart); } else{ // new Community community = communityQueryService.getCommunityById(communityId); - Heart save = heartSaveService.save(heartMapper.mapToHeart(pusherId, community, heartStatus)); + Heart save = heartSaveService.save(heartMapper.mapToHeart(pusherId, community)); community.updateHearts(save); return heartMapper.mapToHeartRes(save); } diff --git a/src/main/java/gwangjang/server/domain/heart/domain/entity/Heart.java b/src/main/java/gwangjang/server/domain/heart/domain/entity/Heart.java index 1f0f6c2..d05cd1d 100644 --- a/src/main/java/gwangjang/server/domain/heart/domain/entity/Heart.java +++ b/src/main/java/gwangjang/server/domain/heart/domain/entity/Heart.java @@ -31,7 +31,11 @@ public class Heart extends BaseEntity { private boolean status; - public void updateHeart(String status) { - this.status = Boolean.parseBoolean(status); + public void updateHeart() { + if (this.status) { + this.status = Boolean.FALSE; + } else{ + this.status = Boolean.TRUE; + } } } diff --git a/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java b/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java index a9ccf3a..a3df9ac 100644 --- a/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java +++ b/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java @@ -16,16 +16,15 @@ @RestController @AllArgsConstructor -@RequestMapping("/topic/{topic}/community/{communityId}/heart") +@RequestMapping("/topic/{topicId}/community/{communityId}/heart") public class HeartController { private final HeartUpdateUseCase heartUpdateUseCase; - @PutMapping("/{heartStatus}") + @PutMapping public ResponseEntity> pushHeart(@RequestHeader(value = "user-id") String socialId, - @PathVariable("topic") String topic, @PathVariable("communityId") Long communityId, - @PathVariable("heartStatus") String heartStatus) { - return ResponseEntity.ok(SuccessResponse.create(PUSH_HEART_SUCCESS.getMessage(), this.heartUpdateUseCase.pushHeart(socialId, communityId,heartStatus))); + @PathVariable("topicId") Long topicId, @PathVariable("communityId") Long communityId) { + return ResponseEntity.ok(SuccessResponse.create(PUSH_HEART_SUCCESS.getMessage(), this.heartUpdateUseCase.pushHeart(socialId, communityId))); } }