-
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 #23 from lotte-team6-onthefarm/feedDetail
feat : 피드 상세페이지 태그 정보 추가 및 댓글 기능 구현
- Loading branch information
Showing
18 changed files
with
319 additions
and
17 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
src/main/java/com/team6/onandthefarmsnsservice/controller/CommentController.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,110 @@ | ||
package com.team6.onandthefarmsnsservice.controller; | ||
|
||
import com.team6.onandthefarmsnsservice.dto.comment.CommentInfoDto; | ||
import com.team6.onandthefarmsnsservice.service.CommentService; | ||
import com.team6.onandthefarmsnsservice.utils.BaseResponse; | ||
import com.team6.onandthefarmsnsservice.vo.comment.CommentDetailResponse; | ||
import com.team6.onandthefarmsnsservice.vo.comment.CommentRequest; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import springfox.documentation.annotations.ApiIgnore; | ||
|
||
import java.security.Principal; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/user/sns/comment") | ||
public class CommentController { | ||
|
||
private final CommentService commentService; | ||
|
||
@Autowired | ||
public CommentController(CommentService commentService){ | ||
this.commentService = commentService; | ||
} | ||
|
||
@PostMapping | ||
@ApiOperation("피드 댓글 등록") | ||
public ResponseEntity<BaseResponse> addComment(@ApiIgnore Principal principal, @RequestBody CommentRequest commentUploadRequest){ | ||
|
||
Long memberId = null; | ||
String memberRole = null; | ||
CommentInfoDto commentInfoDto = CommentInfoDto.builder() | ||
.memberId(memberId) | ||
.memberRole(memberRole) | ||
.feedId(commentUploadRequest.getFeedId()) | ||
.feedCommentContent(commentUploadRequest.getFeedCommentContent()).build(); | ||
|
||
Long commentId = commentService.addComment(commentInfoDto); | ||
|
||
BaseResponse baseResponse = BaseResponse.builder() | ||
.httpStatus(HttpStatus.OK) | ||
.message("add comment success") | ||
.data(commentId) | ||
.build(); | ||
if(commentId == null){ | ||
baseResponse = BaseResponse.builder() | ||
.httpStatus(HttpStatus.BAD_REQUEST) | ||
.message("add comment fail") | ||
.build(); | ||
return new ResponseEntity(baseResponse, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
return new ResponseEntity(baseResponse, HttpStatus.OK); | ||
} | ||
|
||
@PutMapping | ||
@ApiOperation("피드 댓글 수정") | ||
public ResponseEntity<BaseResponse> modifyComment(@ApiIgnore Principal principal, @RequestBody CommentRequest commentModityRequest){ | ||
|
||
Long memberId = null; | ||
String memberRole = null; | ||
CommentInfoDto commentInfoDto = CommentInfoDto.builder() | ||
.memberId(memberId) | ||
.memberRole(memberRole) | ||
.feedCommentId(commentModityRequest.getFeedCommentId()) | ||
.feedCommentContent(commentModityRequest.getFeedCommentContent()).build(); | ||
|
||
Long commentId = commentService.modifyComment(commentInfoDto); | ||
|
||
BaseResponse baseResponse = BaseResponse.builder() | ||
.httpStatus(HttpStatus.OK) | ||
.message("add comment success") | ||
.data(commentId) | ||
.build(); | ||
if(commentId == null){ | ||
baseResponse = BaseResponse.builder() | ||
.httpStatus(HttpStatus.BAD_REQUEST) | ||
.message("add comment fail") | ||
.build(); | ||
return new ResponseEntity(baseResponse, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
return new ResponseEntity(baseResponse, HttpStatus.OK); | ||
} | ||
|
||
@GetMapping | ||
@ApiOperation("피드 댓글 조회") | ||
public ResponseEntity<BaseResponse<List<CommentDetailResponse>>> findComment(@RequestParam Long feedId){ | ||
|
||
List<CommentDetailResponse> commentList = commentService.findCommentDetail(feedId); | ||
|
||
BaseResponse baseResponse = BaseResponse.builder() | ||
.httpStatus(HttpStatus.OK) | ||
.message("find comment success") | ||
.data(commentList) | ||
.build(); | ||
if(commentList == null){ | ||
baseResponse = BaseResponse.builder() | ||
.httpStatus(HttpStatus.BAD_REQUEST) | ||
.message("find comment fail") | ||
.build(); | ||
return new ResponseEntity(baseResponse, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
return new ResponseEntity(baseResponse, HttpStatus.OK); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/team6/onandthefarmsnsservice/dto/FeedInfoDto.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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/team6/onandthefarmsnsservice/dto/comment/CommentInfoDto.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,15 @@ | ||
package com.team6.onandthefarmsnsservice.dto.comment; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class CommentInfoDto { | ||
|
||
private Long memberId; | ||
private String memberRole; | ||
private Long feedId; | ||
private Long feedCommentId; | ||
private String feedCommentContent; | ||
} |
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
src/main/java/com/team6/onandthefarmsnsservice/repository/FeedCommentRepository.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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package com.team6.onandthefarmsnsservice.repository; | ||
|
||
import com.team6.onandthefarmsnsservice.entity.FeedComment; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface FeedCommentRepository extends CrudRepository<FeedComment,Long> { | ||
|
||
@Query("select c from FeedComment c where c.feed.feedId=:feedId") | ||
List<FeedComment> findByFeedId(@Param("feedId") Long feedId); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/team6/onandthefarmsnsservice/repository/FeedTagRepository.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package com.team6.onandthefarmsnsservice.repository; | ||
|
||
import com.team6.onandthefarmsnsservice.entity.Feed; | ||
import com.team6.onandthefarmsnsservice.entity.FeedTag; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface FeedTagRepository extends JpaRepository<FeedTag, Long> { | ||
|
||
List<FeedTag> findByFeed(Feed feed); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/team6/onandthefarmsnsservice/service/CommentService.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,15 @@ | ||
package com.team6.onandthefarmsnsservice.service; | ||
|
||
import com.team6.onandthefarmsnsservice.dto.comment.CommentInfoDto; | ||
import com.team6.onandthefarmsnsservice.vo.comment.CommentDetailResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface CommentService { | ||
|
||
List<CommentDetailResponse> findCommentDetail(Long feedId); | ||
|
||
Long addComment(CommentInfoDto commentInfoDto); | ||
|
||
Long modifyComment(CommentInfoDto commentInfoDto); | ||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/com/team6/onandthefarmsnsservice/service/CommentServiceImpl.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,104 @@ | ||
package com.team6.onandthefarmsnsservice.service; | ||
|
||
import com.team6.onandthefarmsnsservice.dto.comment.CommentInfoDto; | ||
import com.team6.onandthefarmsnsservice.entity.Feed; | ||
import com.team6.onandthefarmsnsservice.entity.FeedComment; | ||
import com.team6.onandthefarmsnsservice.feignclient.MemberServiceClient; | ||
import com.team6.onandthefarmsnsservice.repository.FeedCommentRepository; | ||
import com.team6.onandthefarmsnsservice.repository.FeedRepository; | ||
import com.team6.onandthefarmsnsservice.utils.DateUtils; | ||
import com.team6.onandthefarmsnsservice.vo.comment.CommentDetailResponse; | ||
import com.team6.onandthefarmsnsservice.vo.user.Seller; | ||
import com.team6.onandthefarmsnsservice.vo.user.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@Transactional | ||
public class CommentServiceImpl implements CommentService { | ||
|
||
private final FeedRepository feedRepository; | ||
private final FeedCommentRepository feedCommentRepository; | ||
private final MemberServiceClient memberServiceClient; | ||
private DateUtils dateUtils; | ||
Environment env; | ||
|
||
@Autowired | ||
public CommentServiceImpl(FeedRepository feedRepository, | ||
FeedCommentRepository feedCommentRepository, | ||
MemberServiceClient memberServiceClient, | ||
DateUtils dateUtils, | ||
Environment env){ | ||
this.feedRepository = feedRepository; | ||
this.feedCommentRepository = feedCommentRepository; | ||
this.memberServiceClient = memberServiceClient; | ||
this.dateUtils = dateUtils; | ||
this.env = env; | ||
} | ||
|
||
@Override | ||
public List<CommentDetailResponse> findCommentDetail(Long feedId) { | ||
|
||
List<CommentDetailResponse> commentDetailList = new ArrayList<>(); | ||
|
||
List<FeedComment> feedCommentList = feedCommentRepository.findByFeedId(feedId); | ||
for(FeedComment feedComment : feedCommentList){ | ||
CommentDetailResponse commentDetail = CommentDetailResponse.builder() | ||
.memberId(feedComment.getMemberId()) | ||
.memberRole(feedComment.getMemberRole()) | ||
.feedCommnetId(feedComment.getFeedCommnetId()) | ||
.feedCommentContent(feedComment.getFeedCommentContent()) | ||
.feedCommentCreateAt(feedComment.getFeedCommentCreateAt()) | ||
.feedCommentModifiedAt(feedComment.getFeedCommentModifiedAt()) | ||
.build(); | ||
|
||
if(feedComment.getMemberRole().equals("user")){ | ||
User user = memberServiceClient.findByUserId(feedComment.getMemberId()); | ||
commentDetail.setMemberName(user.getUserName()); | ||
} | ||
else if(feedComment.getMemberRole().equals("seller")){ | ||
Seller seller = memberServiceClient.findBySellerId(feedComment.getMemberId()); | ||
commentDetail.setMemberName(seller.getSellerName()); | ||
} | ||
|
||
commentDetailList.add(commentDetail); | ||
} | ||
|
||
return commentDetailList; | ||
} | ||
|
||
@Override | ||
public Long addComment(CommentInfoDto commentInfoDto) { | ||
|
||
Optional<Feed> feed = feedRepository.findById(commentInfoDto.getFeedId()); | ||
|
||
FeedComment feedComment = new FeedComment(); | ||
feedComment.setMemberId(commentInfoDto.getMemberId()); | ||
feedComment.setMemberRole(commentInfoDto.getMemberRole()); | ||
feedComment.setFeed(feed.get()); | ||
feedComment.setFeedCommentContent(commentInfoDto.getFeedCommentContent()); | ||
feedComment.setFeedCommentCreateAt(dateUtils.transDate(env.getProperty("dateutils.format"))); | ||
|
||
FeedComment savedFeedComment = feedCommentRepository.save(feedComment); | ||
return savedFeedComment.getFeedCommnetId(); | ||
} | ||
|
||
@Override | ||
public Long modifyComment(CommentInfoDto commentInfoDto) { | ||
|
||
Optional<FeedComment> feedComment = feedCommentRepository.findById(commentInfoDto.getFeedCommentId()); | ||
|
||
if(feedComment.isPresent()){ | ||
feedComment.get().setFeedCommentContent(commentInfoDto.getFeedCommentContent()); | ||
feedComment.get().setFeedCommentModifiedAt(dateUtils.transDate(env.getProperty("dateutils.format"))); | ||
} | ||
|
||
return feedComment.get().getFeedCommnetId(); | ||
} | ||
} |
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
src/main/java/com/team6/onandthefarmsnsservice/vo/comment/CommentDetailResponse.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 com.team6.onandthefarmsnsservice.vo.comment; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class CommentDetailResponse { | ||
|
||
private Long memberId; | ||
|
||
private String memberRole; | ||
|
||
private String memberName; | ||
|
||
private Long feedCommnetId; | ||
|
||
private String feedCommentContent; | ||
|
||
private String feedCommentCreateAt; | ||
|
||
private String feedCommentModifiedAt; | ||
} |
Oops, something went wrong.