前言
青训营项目只有最后几天了,为了复习开发过的基础API以及为之后开发API做个铺垫,我决定花一点时间来专门整理一下开发思路
视频流接口/douyin/feed/-------Get方法
video表单
type Video struct {
gorm.Model
UserID uint `gorm:"index:idx_user_created" json:"user_id"`
User User `gorm:"foreignKey:UserID"`
Title string `json:"title"`
PlayUrl string `json:"play_url"`
CoverUrl string `json:"cover_url"`
FavoriteCount uint `json:"favorite_count"`
CommentCount uint `json:"comment_count"`
PublishTime time.Time `gorm:"index:idx_publish_time;index:idx_user_created" json:"published_at"`
}
逻辑
接收数据latest_time和token,token用于用户鉴权可有可无,查找投稿时间<latest_time的视频,返回视频列表以及其他的基本信息
投稿接口/douyin/publish/action/-------Post方法
video表单同上
逻辑
这个接口当时最令我头疼,因为它要求接收的token数据为Body参数,我当时半天都没有接收到token数据,然后就是data视频数据,需要收到视频数据后保存到本地以及对应查找的位置,我们队伍选择minIO对象存储视频数据
发布列表/douyin/publish/list/-------Get方法
video表单同上
逻辑
获取token和user_id,通过user_id进入查询用户发布过的视频,返回视频列表
用户注册/douyin/user/register/-------Post方法
user表单
type User struct {
gorm.Model
Username string `gorm:"unique"`
Password string
Profile UserProfile `gorm:"foreignKey:UserID"`
}
userProfile表单(user的额外信息)
type UserProfile struct {
gorm.Model
UserID uint
Avatar string
Background string
Signature string
FollowCount int
FollowerCount int
TotalFavorited int
WorkCount int
FavoriteCount int
}
逻辑
接收username以及password字段,验证合理性之后检验数据库中是否以及拥有相同用户名的信息,若有则不能注册,要保证用户名的独一性,注册成功后返回user_id以及token
用户登录/douyin/user/login/-------Post方法
逻辑
与用户注册相差不多,不同的就是用户登录需要检验用户名的是否存在以及密码是否正确,登录成功后生成token然后返回user_id和token
用户信息/douyin/user/-------Get方法
逻辑
登录成功之后直接跳转用户信息界面,接收user_id和token,返回user的数据以及对应的userProfile表单