Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewFeedList #23

Open
wants to merge 115 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
f34736f
对readme做了简单修改,添加的数据库基本的设计文档
Jun 3, 2022
fa00c00
design for database and project structure
BaiZe1998 Jun 5, 2022
8e8af85
增加follow的单元测试
BaiZe1998 Jun 5, 2022
7605443
为comment表增加status字段
BaiZe1998 Jun 5, 2022
a6428e2
修改database.md
BaiZe1998 Jun 5, 2022
c60664a
修改follow注释
BaiZe1998 Jun 5, 2022
338d7a4
Merge pull request #1 from BaiZe1998/yc_project_struct_design
TremblingV5 Jun 5, 2022
5f0bbb7
数据库索引设计
BaiZe1998 Jun 6, 2022
84148ff
Merge pull request #2 from BaiZe1998/yc_db_index_design
TremblingV5 Jun 6, 2022
ea37482
完成用户信息、用户注册和登录功能,添加jwt ,自定义中间件校验jwt
1753589103 Jun 7, 2022
eca9937
Add files via upload
1753589103 Jun 7, 2022
73478ce
Delete douyin.sql
1753589103 Jun 7, 2022
7df0727
Add files via upload
1753589103 Jun 7, 2022
164c6e4
Merge pull request #3 from 1753589103/main
Mr1q Jun 7, 2022
a8a6d3a
Merge branch 'main' into git-dev
BaiZe1998 Jun 9, 2022
0b55ad6
Merge pull request #4 from 1753589103/git-dev
BaiZe1998 Jun 9, 2022
5e41679
围绕关注接口添加了功能实现,修改了go.mod的module名;
Jun 9, 2022
e5b7e76
Merge branch 'main' of github.com:BaiZe1998/douyin-simple-demo into x…
Jun 9, 2022
24edbd2
Merge pull request #5 from BaiZe1998/xinzf-database-design
BaiZe1998 Jun 9, 2022
be5d806
调整项目代码结构、修正user和relation相关的bug
BaiZe1998 Jun 9, 2022
52ee695
Merge pull request #6 from BaiZe1998/yc_auth
TremblingV5 Jun 9, 2022
6419920
修改了用户注册一直显示用户已存在的bug
1753589103 Jun 9, 2022
9cee7bc
修改了feed路由被拦截的bug
1753589103 Jun 9, 2022
f367d3a
Merge pull request #7 from 1753589103/main
Mr1q Jun 9, 2022
42bdef4
修正数据库password字段问题
BaiZe1998 Jun 9, 2022
ac3b358
Merge pull request #8 from BaiZe1998/yc_auth
Mr1q Jun 9, 2022
9090529
添加评论、删除评论、修改了feed流的返回结果
Jun 10, 2022
a55353c
关注列表和粉丝列表
Jun 10, 2022
f9f7607
Merge pull request #10 from BaiZe1998/relation_list
BaiZe1998 Jun 10, 2022
6f765e0
Merge pull request #9 from BaiZe1998/qjh_comment
BaiZe1998 Jun 10, 2022
0e8958f
验证token时,在context中添加一个"user_id"字段记录token所属的user_id
Jun 10, 2022
1094519
Merge pull request #11 from BaiZe1998/relation_list
BaiZe1998 Jun 10, 2022
33a2255
项目结构调整,将数据实体全部放入dto,model只存放数据库模型及其CRUD方法,修正部分bug
BaiZe1998 Jun 10, 2022
1824464
Merge pull request #12 from BaiZe1998/yc_structure
TremblingV5 Jun 10, 2022
49cf97f
添加软删除
Jun 10, 2022
270139f
软删除,更改评论数据表
Jun 10, 2022
32a08a9
Merge pull request #14 from BaiZe1998/qjh_new
BaiZe1998 Jun 10, 2022
dae562c
添加视频上传功能 添加到阿里云
liufei2606 Jun 10, 2022
bbab2c3
添加了基于go-redis的redis封装
Jun 10, 2022
2ddcb32
Merge pull request #15 from BaiZe1998/redis-pool
BaiZe1998 Jun 11, 2022
ef2e1ca
添加了配置文件,通过config目录下的config.yml进行配置
Jun 11, 2022
bece33e
Merge pull request #16 from BaiZe1998/config
BaiZe1998 Jun 11, 2022
ce1a4a8
暴漏出Conf
Jun 11, 2022
cdca3f0
Merge pull request #18 from BaiZe1998/config
BaiZe1998 Jun 11, 2022
d8d90b8
更改了配置文件路径,创建了单独的test目录
Jun 11, 2022
b1108f8
Merge pull request #19 from BaiZe1998/test_folder
BaiZe1998 Jun 11, 2022
1ad1d14
初步完成点赞功能
BaiZe1998 Jun 11, 2022
66d9621
新增video表title字段
1753589103 Jun 11, 2022
541e3cb
Merge branch 'BaiZe1998:main' into main
1753589103 Jun 11, 2022
64f278a
点赞功能基本完成,但是部分功能依赖feed,添加了单元测试配置文件读取函数
BaiZe1998 Jun 11, 2022
dc8a46a
Merge pull request #20 from 1753589103/main
Mr1q Jun 11, 2022
257ba3c
添加视频上传功能 添加到阿里云
liufei2606 Jun 10, 2022
b974ceb
Merge pull request #21 from BaiZe1998/yc_favorite
TremblingV5 Jun 11, 2022
5027373
处理config文件路径
Jun 11, 2022
f53a27b
Merge pull request #22 from BaiZe1998/configPath
BaiZe1998 Jun 11, 2022
17eaa13
Merge remote-tracking branch 'origin/111' into 111
liufei2606 Jun 11, 2022
fef3a8a
Merge remote-tracking branch 'origin/main' into main
liufei2606 Jun 11, 2022
8aab7ce
修改了video类,大致完成了feed视频流请求 细节还没完成
1753589103 Jun 11, 2022
e5b144e
修改了video类,大致完成了feed视频流请求 细节还没完成
1753589103 Jun 11, 2022
c81601a
更改了test文件存放的目录,更改了获取配置文件路径的方式,需要在Mac以及Linux系统中测试一下是否可用
Jun 11, 2022
98124eb
新增针对publis路由的自定义jwt鉴权中间件
1753589103 Jun 11, 2022
349c7ca
Merge pull request #24 from BaiZe1998/branch_0611
BaiZe1998 Jun 11, 2022
1d45d95
修改配置文件
BaiZe1998 Jun 11, 2022
2efc869
Merge branch 'r' into main
liufei2606 Jun 11, 2022
262d5de
Merge remote-tracking branch 'douyin/git-dev' into git-dev
1753589103 Jun 11, 2022
1c5dabb
Merge pull request #25 from liufei2606/main
BaiZe1998 Jun 11, 2022
6eeba11
添加一些依赖
liufei2606 Jun 11, 2022
fc9be7b
Merge branch 'main' into git-dev
1753589103 Jun 12, 2022
3bbb2f0
Merge pull request #26 from 1753589103/git-dev
BaiZe1998 Jun 12, 2022
6b237e6
Merge remote-tracking branch 'origin/main'
BaiZe1998 Jun 12, 2022
adda232
Merge branch 'main' into dev
liufei2606 Jun 12, 2022
93d256d
修改视频上传,加入title
liufei2606 Jun 12, 2022
2b499a0
Merge pull request #27 from liufei2606/dev
BaiZe1998 Jun 12, 2022
147da61
添加视频列表评论数修改,添加事务操作
Jun 12, 2022
dd787c3
1
Jun 12, 2022
6bf558d
Merge remote-tracking branch 'origin/main'
BaiZe1998 Jun 12, 2022
5512be5
一些改动
BaiZe1998 Jun 12, 2022
4adfd4f
Merge branch 'main' into qjh_comment_new
BaiZe1998 Jun 12, 2022
ba60eae
Merge pull request #28 from BaiZe1998/qjh_comment_new
BaiZe1998 Jun 12, 2022
cd39728
Merge remote-tracking branch 'origin/main'
BaiZe1998 Jun 12, 2022
6233dad
Merge pull request #29 from BaiZe1998/yc_favorite
TremblingV5 Jun 12, 2022
5ac52fe
feed.go修成时间戳问题
liufei2606 Jun 12, 2022
056a16a
Merge branch 'main' into dev
liufei2606 Jun 12, 2022
eb80e85
Merge pull request #30 from liufei2606/dev
BaiZe1998 Jun 12, 2022
759df2a
增加事务
1753589103 Jun 12, 2022
3d6396e
Merge pull request #31 from 1753589103/git-dev
liufei2606 Jun 12, 2022
4507303
redis完成封装
BaiZe1998 Jun 12, 2022
12a4fed
结构调整
BaiZe1998 Jun 12, 2022
4dcae95
修改日期显示
Jun 12, 2022
a9d55a1
本地和yc_favorite合并发生冲突,预处理完成
BaiZe1998 Jun 12, 2022
66ac720
Merge pull request #32 from BaiZe1998/qjh_comment_ew
BaiZe1998 Jun 12, 2022
6be4449
完成redis封装
BaiZe1998 Jun 12, 2022
89b543b
修改feed bug
1753589103 Jun 12, 2022
fa9b90b
Merge remote-tracking branch 'douyin/git-dev' into git-dev
1753589103 Jun 12, 2022
f3eb784
Merge pull request #33 from 1753589103/git-dev
liufei2606 Jun 12, 2022
d72f540
加入publish
liufei2606 Jun 12, 2022
d2659cf
Merge remote-tracking branch 'origin/main'
BaiZe1998 Jun 12, 2022
ddb76ab
redis封装完成,编写了使用案例
BaiZe1998 Jun 12, 2022
0a30b55
Merge pull request #34 from BaiZe1998/yc_favorite
TremblingV5 Jun 12, 2022
51c63bc
增加了日志组件
Jun 12, 2022
3d57de5
Merge branch 'main' into log
BaiZe1998 Jun 12, 2022
f7b1fb1
Merge pull request #35 from BaiZe1998/log
BaiZe1998 Jun 12, 2022
6e5afdd
Merge branch 'main' into dev
liufei2606 Jun 12, 2022
4f3ffd5
加入publish
liufei2606 Jun 12, 2022
6fac9ad
Merge pull request #36 from liufei2606/dev
1753589103 Jun 12, 2022
94ce417
添加redis存储
Jun 12, 2022
fb496f8
Merge pull request #37 from BaiZe1998/new_comment_qjh
BaiZe1998 Jun 12, 2022
5c204ee
修改feed
liufei2606 Jun 12, 2022
e52b13e
Merge pull request #38 from liufei2606/dev
BaiZe1998 Jun 12, 2022
5bea769
修改feed bug
1753589103 Jun 12, 2022
ca44945
Merge pull request #39 from 1753589103/git-dev
BaiZe1998 Jun 12, 2022
ce23607
修改redis逻辑
Jun 12, 2022
8a27e9e
Merge pull request #40 from BaiZe1998/dev
BaiZe1998 Jun 12, 2022
4ef5447
在feed videolist时,采用多表联查的方式,性能提示比较明显
Jun 12, 2022
1ef2016
Merge branch 'main' into NewFeedList
TremblingV5 Jun 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
# Go workspace file
go.work

.idea
.idea

.vscode

log
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ go build && ./simple-demo

### 测试数据

测试数据写在 demo_data.go 中,用于列表接口的 mock 测试
测试数据写在 demo_data.go 中,用于列表接口的 mock 测试

### 目录结构说明

- document: 项目相关的一些文档记录
- model: gorm模型
34 changes: 34 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
env:
debug: true
server:
port: "8080"
mysql:
local:
host: "127.0.0.1"
port: "3306"
database: "douyin"
username: "root"
password: "root"
default:
host: "xinzf0520.top"
port: "20607"
database: "douyin"
username: "dyweadmin"
password: "JXU2MTNGJXU5NzUyJXU5Rjk5JXU2MzA3JXU1RjE1JXU0RjYw"
redis:
local:
host: "127.0.0.1"
port: "6379"
password: ""
default:
host: "xinzf0520.top"
port: "20606"
password: "JXU2MTNGJXU5NzUyJXU5Rjk5JXU2MzA3JXU1RjE1JXU0RjYw"
databases:
default: 0
log:
level: "debug"
filename: "./log/log.log"
max_size: 200
max_age: 7
max_backups: 10
71 changes: 46 additions & 25 deletions controller/comment.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,68 @@
package controller

import (
"github.com/gin-gonic/gin"
"context"
"fmt"
"net/http"
)
"strconv"
"sync"

type CommentListResponse struct {
Response
CommentList []Comment `json:"comment_list,omitempty"`
}

type CommentActionResponse struct {
Response
Comment Comment `json:"comment,omitempty"`
}
"github.com/BaiZe1998/douyin-simple-demo/db/model"
"github.com/BaiZe1998/douyin-simple-demo/dto"
"github.com/BaiZe1998/douyin-simple-demo/pkg/util"
"github.com/BaiZe1998/douyin-simple-demo/service"
"github.com/gin-gonic/gin"
)

// CommentAction no practical effect, just check if token is valid
func CommentAction(c *gin.Context) {
token := c.Query("token")
actionType := c.Query("action_type")

if user, exist := usersLoginInfo[token]; exist {
videoId, _ := strconv.ParseInt(c.Query("video_id"), 10, 64)
userClaims, _ := util.ParseToken(token)
userModel, _ := model.QueryUserById(context.Background(), userClaims.ID)
users := dto.User{
Id: userModel.ID,
Name: userModel.Name,
FollowCount: userModel.FollowCount,
FollowerCount: userModel.FollowerCount,
IsFollow: false,
}
if userModel.ID > 0 {
if actionType == "1" {
text := c.Query("comment_text")
c.JSON(http.StatusOK, CommentActionResponse{Response: Response{StatusCode: 0},
Comment: Comment{
Id: 1,
User: user,
Content: text,
CreateDate: "05-01",
}})
return
//comment addcomment
responseComment := service.AddComment(text, users, videoId)
c.JSON(http.StatusOK,
dto.CommentActionResponse{
Response: dto.Response{StatusCode: 0},
Comment: responseComment,
})
} else {
commentId, _ := strconv.ParseInt(c.Query("comment_id"), 10, 64)
//comment delete
model.DeleteCommnet(context.Background(), videoId, commentId)

c.JSON(http.StatusOK, Response{StatusCode: 0})
}
c.JSON(http.StatusOK, Response{StatusCode: 0})
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
service.UpdatCacheCommentList(context.Background(), videoId, 10, 0)
}()
} else {
c.JSON(http.StatusOK, Response{StatusCode: 1, StatusMsg: "User doesn't exist"})
}
}

// CommentList all videos have same demo comment list
func CommentList(c *gin.Context) {
c.JSON(http.StatusOK, CommentListResponse{
Response: Response{StatusCode: 0},
CommentList: DemoComments,
videoId, _ := strconv.ParseInt(c.Query("video_id"), 10, 64)
res, total, _ := service.GetCacheCommentList(context.Background(), videoId, 10, 0)
c.JSON(http.StatusOK, dto.CommentListResponse{
Response: dto.Response{StatusCode: 0, StatusMsg: ""},
CommentList: res,
})
fmt.Println(total)
}
27 changes: 15 additions & 12 deletions controller/common.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
package controller

import "github.com/BaiZe1998/douyin-simple-demo/dto"

type Response struct {
StatusCode int32 `json:"status_code"`
StatusMsg string `json:"status_msg,omitempty"`
NextTime int64 `json:"next_time,omitempty"`
}

type Video struct {
Id int64 `json:"id,omitempty"`
Author User `json:"author"`
PlayUrl string `json:"play_url" json:"play_url,omitempty"`
CoverUrl string `json:"cover_url,omitempty"`
FavoriteCount int64 `json:"favorite_count,omitempty"`
CommentCount int64 `json:"comment_count,omitempty"`
IsFavorite bool `json:"is_favorite,omitempty"`
Id int64 `json:"id,omitempty"`
Author dto.User `json:"author"`
PlayUrl string `json:"play_url" json:"play_url,omitempty"`
CoverUrl string `json:"cover_url,omitempty"`
FavoriteCount int64 `json:"favorite_count,omitempty"`
CommentCount int64 `json:"comment_count,omitempty"`
IsFavorite bool `json:"is_favorite,omitempty"`
}

type Comment struct {
Id int64 `json:"id,omitempty"`
User User `json:"user"`
Content string `json:"content,omitempty"`
CreateDate string `json:"create_date,omitempty"`
Id int64 `json:"id,omitempty"`
User dto.User `json:"dto.user"`
Content string `json:"content,omitempty"`
CreateDate string `json:"create_date,omitempty"`
}

type User struct {
Id int64 `json:"id,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
FollowCount int64 `json:"follow_count,omitempty"`
FollowerCount int64 `json:"follower_count,omitempty"`
Expand Down
43 changes: 29 additions & 14 deletions controller/demo_data.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
package controller

var DemoVideos = []Video{
import "github.com/BaiZe1998/douyin-simple-demo/dto"

var DemoVideos = []dto.Video{
{
Id: 1,
Author: DemoUser,
PlayUrl: "https://www.w3schools.com/html/movie.mp4",
Author: DemoUser1,
PlayUrl: "http://niuyefan.oss-cn-beijing.aliyuncs.com/douyin/bear.mp4",
CoverUrl: "https://cdn.pixabay.com/photo/2016/03/27/18/10/bear-1283347_1280.jpg",
FavoriteCount: 0,
CommentCount: 0,
FavoriteCount: 2,
CommentCount: 2,
IsFavorite: false,
},
}

var DemoComments = []Comment{
{
Id: 1,
User: DemoUser,
Content: "Test Comment",
CreateDate: "05-01",
},
}
// var DemoComments = []Comment{
// {
// Id: 1,
// User: DemoUser1,
// Content: "Test Comment",
// CreateDate: "05-01",
// },
// {
// Id: 2,
// User: DemoUser1,
// Content: "Test Commen22",
// CreateDate: "05-012",
// },
// }

var DemoUser = User{
var DemoUser1 = dto.User{
Id: 1,
Name: "TestUser",
FollowCount: 0,
FollowerCount: 0,
IsFollow: false,
}
var DemoUser = User{
Id: "1",
Name: "TestUser",
FollowCount: 0,
FollowerCount: 0,
IsFollow: false,
}
29 changes: 22 additions & 7 deletions controller/favorite.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
package controller

import (
"github.com/BaiZe1998/douyin-simple-demo/dto"
"github.com/BaiZe1998/douyin-simple-demo/service"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)

// FavoriteAction no practical effect, just check if token is valid
func FavoriteAction(c *gin.Context) {
token := c.Query("token")

if _, exist := usersLoginInfo[token]; exist {
c.JSON(http.StatusOK, Response{StatusCode: 0})
} else {
c.JSON(http.StatusOK, Response{StatusCode: 1, StatusMsg: "User doesn't exist"})
UserIdFromC, _ := c.Get("user_id")
UserID, _ := UserIdFromC.(int64)
VideoID, _ := strconv.ParseInt(c.Query("video_id"), 10, 64)
actionType, _ := strconv.ParseInt(c.Query("action_type"), 10, 64)
if err := service.FavoriteAction(c, UserID, VideoID, int(actionType)); err != nil {
c.JSON(http.StatusBadRequest, dto.Response{
StatusCode: 1,
StatusMsg: err.Error(),
})
}
c.JSON(http.StatusOK, VideoListResponse{
Response: Response{
StatusCode: 0,
StatusMsg: "操作成功",
},
})
}

// FavoriteList all users have same favorite video list
func FavoriteList(c *gin.Context) {
UserIdFromC, _ := c.Get("user_id")
UserID, _ := UserIdFromC.(int64)
videoList, _ := service.GetFavoriteList(c, UserID)
c.JSON(http.StatusOK, VideoListResponse{
Response: Response{
StatusCode: 0,
},
VideoList: DemoVideos,
VideoList: videoList,
})
}
35 changes: 23 additions & 12 deletions controller/feed.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package controller

import (
"github.com/gin-gonic/gin"
"log"
"net/http"
"time"
)

type FeedResponse struct {
Response
VideoList []Video `json:"video_list,omitempty"`
NextTime int64 `json:"next_time,omitempty"`
}
"github.com/BaiZe1998/douyin-simple-demo/dto"
"github.com/BaiZe1998/douyin-simple-demo/pkg/util"
"github.com/BaiZe1998/douyin-simple-demo/service"
"github.com/gin-gonic/gin"
)

// Feed same demo video list for every request
func Feed(c *gin.Context) {
c.JSON(http.StatusOK, FeedResponse{
Response: Response{StatusCode: 0},
VideoList: DemoVideos,
NextTime: time.Now().Unix(),
lastTime := c.Query("latest_time")
token := c.Query("token")
userInfo, parseTokenErr := util.ParseToken(token)

if parseTokenErr != nil {
dto.WriteLog(
"error", "解析token错误",
)
}

videoList, reTime := service.QueryFeedResponse1(userInfo.ID, lastTime)
log.Println(reTime.Unix())
c.JSON(http.StatusOK, dto.FeedResponse{
Response: dto.Response{StatusCode: 0,
StatusMsg: "",
NextTime: reTime.Unix()},
VideoList: videoList,
})
}
Loading