feat:my thumbup List

main
wangqing 10 months ago
parent 18b2ce25da
commit 7d50e8a2cd

@ -229,7 +229,7 @@ public class CommentController extends BaseController {
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
}
@ApiOperation(value = "点赞/取消点赞评论",notes = "返回")
@PutMapping("/thumbup/{commentId}")
public Result thumbup(@PathVariable String commentId,@RequestHeader(value = "Authorization", required = true) String authorization) {
@ -240,6 +240,7 @@ public class CommentController extends BaseController {
return Result.unauthorized(null);
}
String userId = userLoginDto.getUserId();
String avatar = userLoginDto.getAvatar();
// if(redisTemplate.opsForValue().get("thumbup_"+commentId+"_"+userId)!=null){
//
@ -247,7 +248,7 @@ public class CommentController extends BaseController {
// }
// 判断当前用户是否已经点赞
Integer flag = likeService.likePublication(commentId,userId,2);
Integer flag = likeService.likePublication(commentId,userId,2,avatar);
if (flag==0) {
//当前用户已经点过赞,执行取消点赞
likeService.unlikePublication(commentId,userId,2);

@ -7,7 +7,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
@Data
public class PublicationLike implements Serializable {
@ -17,49 +17,19 @@ public class PublicationLike implements Serializable {
private String likedItemId;
private String userId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
public String get_id() {
return _id;
}
private String thumbupAt; //被点赞人userid
public void set_id(String _id) {
this._id = _id;
}
private String commentContent; //被点赞的评论内容
public Integer getType() {
return type;
}
private String avatar; //点赞人头像
public void setType(Integer type) {
this.type = type;
}
public String getLikedItemId() {
return likedItemId;
}
private String nickName; // 点赞人昵称
public void setLikedItemId(String likedItemId) {
this.likedItemId = likedItemId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
private String userId;
public Date getCreateTime() {
return createTime;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

@ -1,12 +1,15 @@
package com.luoo.comment.service;
import com.luoo.comment.pojo.Comment;
import com.luoo.comment.pojo.PublicationLike;
import constants.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import util.IdWorker;
import java.util.Date;
@ -16,7 +19,13 @@ public class LikeService {
@Autowired
private MongoTemplate mongoTemplate;
public Integer likePublication(String publicationId, String userId, Integer type) {
@Autowired
private CommentService commentService;
@Autowired
private IdWorker idWorker;
public Integer likePublication(String publicationId, String userId, Integer type,String avatar) {
// 构建查询条件
Criteria criteria = Criteria.where("userId").is(userId)
.and("type").is(type)
@ -29,12 +38,17 @@ public class LikeService {
// 重复点赞
return 0;
}
Comment comment = commentService.findById(publicationId);
// 将点赞记录保存到mongodb
PublicationLike publicationLike = new PublicationLike();
publicationLike.setType(type);
publicationLike.set_id(idWorker.nextId()+"");
publicationLike.setCreateTime(new Date());
publicationLike.setLikedItemId(publicationId);
publicationLike.setUserId(userId);
publicationLike.setAvatar(Constants.RESOURCE_PREFIX + avatar);
publicationLike.setThumbupAt(comment.getUserId());
publicationLike.setCommentContent(comment.getContent());
mongoTemplate.save(publicationLike);
return 1;

@ -11,6 +11,7 @@ import java.util.stream.Collectors;
import com.luoo.user.dto.TotalCommentVo;
import com.luoo.user.pojo.Feedback;
import com.luoo.user.pojo.UserCollectInfo;
import com.luoo.user.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -37,10 +38,6 @@ import controller.BaseController;
import com.luoo.user.dto.UserInfoUpdateDto;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.UserInfo;
import com.luoo.user.service.FeedbackService;
import com.luoo.user.service.S3Service;
import com.luoo.user.service.UserCollectInfoService;
import com.luoo.user.service.UserInfoService;
import com.luoo.user.util.IpUtil;
import annotation.GlobalInterceptor;
@ -81,6 +78,9 @@ public class MyController extends BaseController {
@Autowired
private FeedbackService feedbackService;
@Autowired
private MyService myService;
@Autowired
private MongoTemplate mongoTemplate;
@ -308,4 +308,38 @@ public class MyController extends BaseController {
return userRespDTO;
}
// 查询我的获赞
@ApiOperation(value = "9.查询我的获赞的分页列表", notes = "游客无法获取")
@GetMapping("/myThumbupList/{page}/{size}")
public Result getMyThumbupList(@PathVariable int page,@PathVariable int size,@RequestHeader(value = "Authorization", required = true) String authorization) {
//验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) {
return Result.unauthorized(null);
}
String userId = userLoginDto.getUserId();
myService.getMyThumbupList(userId);
return null;
}
// 查询我收到的评论
@ApiOperation(value = "10.查询我收到的评论分页列表", notes = "游客无法获取")
@GetMapping("/myCommentReplyList/{page}/{size}")
public Result getMyCommentReplyList(@PathVariable int page,@PathVariable int size,@RequestHeader(value = "Authorization", required = true) String authorization) {
//验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) {
return Result.unauthorized(null);
}
String userId = userLoginDto.getUserId();
myService.getMyCommentReplyList(userId);
return null;
}
}

@ -0,0 +1,7 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.PublicationLike;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface PublicationLikeDao extends MongoRepository<PublicationLike,String> {
}

@ -0,0 +1,38 @@
package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
@Data
public class PublicationLike implements Serializable {
@Id
private String _id;
private Integer type; // 1 期刊 2 评论
private String likedItemId;
private String thumbupAt; //被点赞人userid
private String commentContent; //被点赞的评论内容
private String avatar; //点赞人头像
private String nickName; // 点赞人昵称
private String userId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
}

@ -0,0 +1,31 @@
package com.luoo.user.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
@Service
public class MyService {
@Autowired
private MongoTemplate mongoTemplate;
/**
*
* @param userId
*/
public void getMyCommentReplyList(String userId) {
}
/**
*
* @param userId
*/
public void getMyThumbupList(String userId) {
}
}
Loading…
Cancel
Save