The project is continuously updated:
Table of contents
MongoDB page query system message list
System message storage
There is still one last like and comment left
If you like your comment here, the cover of your video will be sent back
Find the like route of CommentController
Two Services need to be injected:
Here we copy the code we wrote before and make some modifications:
Here we need to obtain a vlogId, which is not available here, so we need to write an interface to obtain it:
accomplish:
Then we can call it through commentService:
//系统消息:点赞评论
Comment comment =commentService.getComment(commentId);
Vlog vlog = vlogService.getVlog(comment.getVlogId());
Map msgContent = new HashMap();
msgContent.put("vlogId",vlog.getId());
msgContent.put("vlogCover",vlog.getCover());
msgContent.put("commentId",commentId);
msgService.createMsg(userId,
comment.getCommentUserId(),
MessageEnum.LIKE_COMMENT.type,
msgContent);
After writing, we do a test, like comments and like replies
Then go to our MongoDB to view
MongoDB page query system message list
After completing the operation of sending system messages, we need to have a query operation on the message interface, and the query is paginated
Let's write our service layer first:
Here we implement Repository, custom condition query
Then in the Service implementation:
In fact, there is still a need to make a judgment here, to judge whether I have paid attention to it before, if not, there will be a sign of returning fans
We only need to expand the field isFriend in MO,
@Override
public List<MessageMO> queryList(String toUserId, Integer page, Integer pageSize) {
Pageable pageable = (Pageable) PageRequest.of(page,
pageSize,
Sort.Direction.DESC,
"CreateTime");
List<MessageMO> list = messageRepository.findAllByToUserIdOrderByCreateTimeDesc(toUserId,pageable);
for(MessageMO msg: list){
//如果类型是关注消息,则需要查询我之前是否关注过他,用于在前端标记“互粉”
if(msg.getMsgType() != null &&msg.getMsgType() == MessageEnum.FOLLOW_YOU.type){
Map map = msg.getMsgContent();
if(map == null){
map = new HashMap();
}
String relationship = redis.get(REDIS_FANS_AND_VLOGGER_RELATIONSHIP+":"+msg.getToUserId()+":"+msg.getFromUserId());
if(StringUtils.isNotBlank(relationship)&&relationship.equalsIgnoreCase("1")){
map.put("isFriend",true);
}else {
map.put("isFriend",false);
}
msg.setMsgContent(map);
}
}
return list;
}
Here we can also check the front end
Here we can build our backend interface
We build a MsgController on the backend:
@Slf4j
@Api(tags = "MsgController 消息功能模块接口")
@RequestMapping("Msg")
@RestController
public class MsgController {
@Autowired
private MsgService msgService;
@GetMapping("list")
public GraceJSONResult list(@RequestParam String userId,
@RequestParam Integer page,
@RequestParam Integer pageSize){
//mongoDB 从0分页,区别于数据库
if(page == null){
page = COMMON_START_PAGE_ZERO;
}
if(pageSize == null){
pageSize=COMMON_PAGE_SIZE;
}
List<MessageMO> list = msgService.queryList(userId, page, pageSize);
return GraceJSONResult.ok(list);
}
}
Start the test:
delete system messages
We can first think about where the deletion can start
First, we can long press or swipe right on our message page to delete
The second type is bound to our user's behavior. If I unfollow you, then remove this attention message
Both types of messages can be triggered to delete, you can try it yourself.
We can use long press to delete here, try the method yourself.
So far, the production of the basic version of the Douyin-like short video APP has come to an end. From the first article of this column to the present, it took about a month to build the project from scratch, to write our code, and complete the test. Then Later I will update the advanced version and hope to upload it to the server.
In the past, if you have questions about the code, you can private message me if you don’t understand. Friends who want the source code can also chat with me privately~