当前位置:网站首页>Tiktok practice ~ pay attention to bloggers
Tiktok practice ~ pay attention to bloggers
2022-06-28 04:12:00 【gblfy】
List of articles
One 、 Focus on my needs analysis
1. Follow my flowchart
2. Follow my process brief
- 1. Click to follow on the short video page
- 2. The front-end carries users ID And short video publishers ID Request backend
- 3. Parameter verification user ID And short video publishers ID Is it empty
- 3.1. It's empty , Directly return to the front prompt
- 3.2. Not empty , The process continues
- 4. Carry user ID Query the database
- 5. Carry a short video publisher ID Query the database
- 6. double ID Judge
- 6.1. It's empty , Directly return to the front prompt
- 6.2. Not empty , The process continues
- 7. Judge whether the other party pays attention to me
- 7.1. Not following me , Mutual friendship status bit 0
- 7.2. You've followed me , Mutual friendship status bit 1
- 7.2.1. Update the status of the relationship between the blogger and my fans to 1
- 7.2.2. Save and drop
- 8. Save my fan relationship with the blogger
- 9. My total number of concerns +1
- 10. The total number of bloggers' fans
- 11. My relationship with bloggers =1
- 12. Return response
3. Table structure design
CREATE TABLE `fans` (
`id` varchar(24) NOT NULL,
`vloger_id` varchar(24) NOT NULL COMMENT ' Author users id',
`fan_id` varchar(24) NOT NULL COMMENT ' Fans id',
`is_fan_friend_of_mine` int(1) NOT NULL COMMENT ' Whether the fans are vloger Friend, , If you become a friend , This field of both sides of the table should be set to 1, If one person takes the pass , Both sides need to be set to 0',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `writer_id` (`vloger_id`,`fan_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=' Fan list \n\n';
Two 、 Pay attention to my source code analysis
Follow the short video page , The status of the personal center is changed synchronously
2.1. front end
// Pay attention to me
followMe() {
var me = this;
var myUserInfo = getApp().getUserInfoSession();
if (myUserInfo == null) {
uni.showToast({
duration: 3000,
title: " Please log in ~",
icon: "none"
});
uni.navigateTo({
url: "../loginRegist/loginRegist",
animationType: "slide-in-bottom",
success() {
me.loginWords = " Please log in "
}
});
return;
}
var vlogerId = me.userPageId;
var userId = getApp().getUserInfoSession().id;
var serverUrl = app.globalData.serverUrl;
uni.request({
method: "POST",
header: {
headerUserId: userId,
headerUserToken: app.getUserSessionToken()
},
url: serverUrl + "/fans/follow?myId=" + userId + "&vlogerId=" + vlogerId,
success(result) {
if (result.data.status == 200) {
me.isFollow = true;
uni.setStorageSync("justFollowVlogerId", vlogerId);
// Refresh the number of fans on the current page
var pendingInfo = me.pageUserInfo;
me.pageUserInfo.myFansCounts = pendingInfo.myFansCounts + 1;
} else {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
}
});
},
2.2. Back end
controller
/**
* Focus on
*
* @param myId My users ID
* @param vlogerId Video publisher ID
* @return
*/
@PostMapping("follow")
public GraceJSONResult follow(@RequestParam String myId,
@RequestParam String vlogerId) {
// Whether two id Can't be empty
if (StringUtils.isBlank(myId) || StringUtils.isBlank(vlogerId)) {
return GraceJSONResult.errorCustom(ResponseStatusEnum.SYSTEM_ERROR);
}
// Judge the current user , You can't pay attention to yourself
if (myId.equalsIgnoreCase(vlogerId)) {
return GraceJSONResult.errorCustom(ResponseStatusEnum.SYSTEM_RESPONSE_NO_INFO);
}
// Whether two id Whether the corresponding user exists
Users vloger = userService.getUser(vlogerId);
Users myInfo = userService.getUser(myId);
// fixme: Two users id Judgment after database query , It's good to separate ? It's better to combine and judge ?
if (myInfo == null || vloger == null) {
return GraceJSONResult.errorCustom(ResponseStatusEnum.SYSTEM_RESPONSE_NO_INFO);
}
// Saving fans relates to the database
fansService.doFollow(myId, vlogerId);
// Blogger fans +1, My attention +1
// My total number of concerns
redis.increment(REDIS_MY_FOLLOWS_COUNTS + ":" + myId, 1);
// The total number of bloggers' fans
redis.increment(REDIS_MY_FANS_COUNTS + ":" + vlogerId, 1);
// My relationship with bloggers , rely on redis, Do not store databases , avoid db Performance bottlenecks
redis.set(REDIS_FANS_AND_VLOGGER_RELATIONSHIP + ":" + myId + ":" + vlogerId, "1");
return GraceJSONResult.ok();
}
/**
* Focus on
*
* @param myId my ID
* @param vlogerId Video Blogger ID
*/
@Transactional
@Override
public void doFollow(String myId, String vlogerId) {
String fid = sid.nextShort();
Fans fans = new Fans();
fans.setId(fid);
fans.setFanId(myId);
fans.setVlogerId(vlogerId);
// Judge whether the other party pays attention to me , If you pay attention to me , Then both sides should be friends with each other
//TODO Note the parameters here Judge whether the other party pays attention to me , If you pay attention to me , Then both sides should be friends with each other
Fans vloger = queryFansRelationship(vlogerId, myId);
if (vloger != null) {
fans.setIsFanFriendOfMine(YesOrNo.YES.type);
// Whether the fans are vloger Friend, , If you become a friend , This field of both sides of the table should be set to 1, If one person takes the pass , Both sides need to be set to 0
vloger.setIsFanFriendOfMine(YesOrNo.YES.type);
fansMapper.updateByPrimaryKeySelective(vloger);
} else {
// Whether the fans are vloger Friend, , If you become a friend , This field of both sides of the table should be set to 1, If one person takes the pass , Both sides need to be set to 0
fans.setIsFanFriendOfMine(YesOrNo.NO.type);
}
fansMapper.insert(fans);
// System message : Focus on
msgService.createMsg(myId, vlogerId, MessageEnum.FOLLOW_YOU.type, null);
}
/**
* Judge whether the other party pays attention to me , If you pay attention to me , Then both sides should be friends with each other
*
* @param fanId fans ID
* @param vlogerId Short video release ID
* @return
*/
public Fans queryFansRelationship(String fanId, String vlogerId) {
Example example = new Example(Fans.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("vlogerId", vlogerId);
criteria.andEqualTo("fanId", fanId);
List list = fansMapper.selectByExample(example);
Fans fan = null;
if (list != null && list.size() > 0 && !list.isEmpty()) {
fan = (Fans) list.get(0);
}
return fan;
}
3、 ... and 、 account number 1 Focus on actual combat
3.1. Record the data before attention
Find two accounts that you don't follow to test
account number : Tail number ~5217
nickname : The source of Xinze
Focus on the total amount :2
Number of fans :1
account number : Tail number ~0009
nickname : Little beauty
Focus on the total amount :0
Number of fans :1
2 Account relationships ~ They haven't paid attention yet
3.2. account number 1 Follow Account 2
- Use “ Ending with 5217” To login
View the homepage with the ending number 0009 My little beauty account posted a short video
Click to follow
3.3. account number 1 Pay attention to the data changes
Tail number ~5217 Focus on Tail number ~0009 After your account , Data changes
Tail number ~5217 Data changes
Focus on the total amount : from 2 Turned into 3
Number of fans :1
Tail number ~0009 Data changes
Focus on the total amount : It hasn't changed still 0
Number of fans : from 1 Turned into 2
Table data changes :
User table
Tail number ~0009 userid=21100598TZ9XG6RP
Tail number ~5217 userid=220620BZ2DH0KP94
Fan list
Add a piece of data , Video Blogger (21100598TZ9XG6RP) I am among the fans (220620BZ2DH0KP94)
2206279H48HX0T54 21100598TZ9XG6RP 220620BZ2DH0KP94 0
Four 、. account number 2 Focus on actual combat
4.1. account number 2 Follow Account 1
Use the suffix ~0009 The account login
Go to the home page ~ In the video list , Check whether the following status is - No attention
Click to follow
The attention status is - Followed
4.2. Pay attention to the data changes
Tail number ~0009 Focus on Tail number ~5217 After your account , Data changes
Tail number ~5217 Data changes
Focus on the total amount :3
Number of fans : from 1 Turned into 2
Tail number ~0009 Data changes
Focus on the total amount : from Turned into 1
Number of fans : still 2
Table data changes :
User table
Tail number ~0009 userid=21100598TZ9XG6RP
Tail number ~5217 userid=220620BZ2DH0KP94
Fan list
Add a piece of data ,
I (220620BZ2DH0KP94) There is a suffix in the fans of 0009(21100598TZ9XG6RP)
Video Blogger (21100598TZ9XG6RP) I am among the fans (220620BZ2DH0KP94)
And our relationship has been updated as a friend relationship , All States are 0
2206279P5FYBZYNC 220620BZ2DH0KP94 21100598TZ9XG6RP 1
2206279H48HX0T54 21100598TZ9XG6RP 220620BZ2DH0KP94 1
4.3. redis Storage data structure
边栏推荐
- What is the level 3 password complexity of ISO? How often is it replaced?
- Pychart shares third-party modules among different projects
- 揭开SSL的神秘面纱,了解如何用SSL保护数据
- Backtracking maze problem
- La norme européenne en 597 - 1 pour les meubles est - elle la même que les deux normes en 597 - 2 pour les ignifuges?
- 简单工厂模式
- In the era of video explosion, who is supporting the high-speed operation of video ecological network?
- 04 MongoDB各种查询操作 以及聚合操作总结
- Talking about cloud primitiveness, we have to talk about containers
- Sorting from one stack to another
猜你喜欢
电学基础知识整理(一)
使用tensorboard进行loss可视化
软件测试报告怎么编写?第三方性能报告范文模板来了
2022年6月对自己近况的一次总结
2021 year end summary and 2022 outlook
开关电源—Buck电路原理及其仿真
欧洲家具EN 597-1 跟EN 597-2两个阻燃标准一样吗?
MSc 307 (88) (2010 FTPC code) Part 2 smoke and toxicity test
美创入选“2022 CCIA中国网络安全竞争力50强”榜单
TFTLCD display experiment of mini plate based on punctual atom stm32
随机推荐
[MySQL] multi table connection query
Several important physical concepts
英语小记 - 表因果
Sorting from one stack to another
In the era of video explosion, who is supporting the high-speed operation of video ecological network?
指针链表
MySQL 主从复制、分离解析
Understanding and learning of parental delegation mechanism
AS 3744.1标准中提及ISO8191测试,两者测试一样吗?
【MySQL】多表连接查询
月赛补题
[small program practice series] e-commerce platform source code and function implementation
多项目设计开发·类库项目引入入门
Learning notes of digital circuit (II)
第一个.net core MVC项目
Leetcode: monotonic stack structure (Advanced)
11_ Deliberate practice and elaboration
Does the applet input box flash?
@Transactional失效的几种场景
设计一个有getMin功能的栈