Documentation
¶
Index ¶
- Constants
- Variables
- func Init()
- func InitDB()
- type Comment
- type CommentDAO
- func (c *CommentDAO) AddCommentAndUpdateCount(comment *Comment) error
- func (c *CommentDAO) DeleteCommentAndUpdateCountById(commentId, videoId int64) error
- func (c *CommentDAO) QueryCommentById(id int64, comment *Comment) error
- func (c *CommentDAO) QueryCommentListByVideoId(videoId int64, comments *[]*Comment) error
- type CommonResponse
- type T
- type UserInfo
- type UserInfoDAO
- func (u *UserInfoDAO) AddUserFollow(userId, userToId int64) error
- func (u *UserInfoDAO) AddUserInfo(userinfo *UserInfo) error
- func (u *UserInfoDAO) CancelUserFollow(userId, userToId int64) error
- func (u *UserInfoDAO) GetFollowListByUserId(userId int64, userList *[]*UserInfo) error
- func (u *UserInfoDAO) GetFollowerListByUserId(userId int64, userList *[]*UserInfo) error
- func (u *UserInfoDAO) IsUserExistById(id int64) bool
- func (u *UserInfoDAO) QueryUserInfoById(userId int64, userinfo *UserInfo) error
- type UserLogin
- type UserLoginDAO
- type Video
- type VideoDAO
- func (v *VideoDAO) AddVideo(video *Video) error
- func (v *VideoDAO) IsVideoExistById(id int64) bool
- func (v *VideoDAO) MinusOneFavorByUserIdAndVideoId(userId int64, videoId int64) error
- func (v *VideoDAO) PlusOneFavorByUserIdAndVideoId(userId int64, videoId int64) error
- func (v *VideoDAO) QueryFavorVideoListByUserId(userId int64, videoList *[]*Video) error
- func (v *VideoDAO) QueryVideoByVideoId(videoId int64, video *Video) error
- func (v *VideoDAO) QueryVideoCountByUserId(userId int64, count *int64) error
- func (v *VideoDAO) QueryVideoListByLimitAndTime(limit int, latestTime time.Time, videoList *[]*Video) error
- func (v *VideoDAO) QueryVideoListByUserId(userId int64, videoList *[]*Video) error
Constants ¶
const PageCount = 15
Variables ¶
var ( ErrIvdPtr = errors.New("空指针错误") ErrEmptyUserList = errors.New("用户列表为空") )
全局错误
var DB *gorm.DB
DB 全局参数 DB
var DemoUser = UserInfo{ Id: 1, Name: "TestUser", FollowCount: 0, FollowerCount: 0, IsFollow: false, }
var DemoUsersLoginInfo = map[string]UserInfo{ "zhangleidouyin": { Id: 1, Name: "zhanglei", FollowCount: 10, FollowerCount: 5, IsFollow: true, }, }
var DemoVideos = []*Video{ { Id: 1, Author: DemoUser, PlayUrl: "https://www.w3schools.com/html/movie.mp4", CoverUrl: "https://cdn.pixabay.com/photo/2016/03/27/18/10/bear-1283347_1280.jpg", FavoriteCount: 0, CommentCount: 0, IsFavorite: false, }, { Id: 2, Author: DemoUser, PlayUrl: "https://media.w3.org/2010/05/sintel/trailer.mp4", CoverUrl: "https://img-blog.csdnimg.cn/4192402992cc4f7294516943d696b1a4.png", FavoriteCount: 1, CommentCount: 1, IsFavorite: true, }, { Id: 3, Author: DemoUser, PlayUrl: "http://192.168.142.251:8080/static/BV1aS4y1j7Hs-rw978CGKX0RWi9zL.mp4", CoverUrl: "https://img-blog.csdnimg.cn/img_convert/c644e86b92d93fcc4173c23ce127e625.png#pic_center", FavoriteCount: 1, CommentCount: 1, IsFavorite: true, }, }
var VideoIndexMap map[int64]*Video
Functions ¶
Types ¶
type Comment ¶
type Comment struct { Id int64 `json:"id"` UserInfoId int64 `json:"-"` //用于一对多关系的id VideoId int64 `json:"-"` //一对多,视频对评论 User UserInfo `json:"user" gorm:"-"` Content string `json:"content"` CreatedAt time.Time `json:"-"` CreateDate string `json:"create_date" gorm:"-"` }
Comment 评论结构体
type CommentDAO ¶
type CommentDAO struct { }
CommentDAO dao结构体
func (*CommentDAO) AddCommentAndUpdateCount ¶
func (c *CommentDAO) AddCommentAndUpdateCount(comment *Comment) error
AddCommentAndUpdateCount 增加评论更新数量
func (*CommentDAO) DeleteCommentAndUpdateCountById ¶
func (c *CommentDAO) DeleteCommentAndUpdateCountById(commentId, videoId int64) error
DeleteCommentAndUpdateCountById 删除评论更新数量
func (*CommentDAO) QueryCommentById ¶
func (c *CommentDAO) QueryCommentById(id int64, comment *Comment) error
QueryCommentById 查询评论通过用户id
func (*CommentDAO) QueryCommentListByVideoId ¶
func (c *CommentDAO) QueryCommentListByVideoId(videoId int64, comments *[]*Comment) error
QueryCommentListByVideoId 查询评论列表通过视频id comments *[]*Comment 传入一个空的对面进行 进行赋值
type CommonResponse ¶
type CommonResponse struct { StatusCode int32 `json:"status_code"` StatusMsg string `json:"status_msg,omitempty"` }
CommonResponse 公共的响应
type T ¶
type T struct { Email string `json:"email"` Gender string `json:"gender"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Location struct { Street string `json:"street"` City string `json:"city"` State string `json:"state"` Postcode int `json:"postcode"` } `json:"location"` Username string `json:"username"` Password string `json:"password"` Picture string `json:"picture"` }
type UserInfo ¶
type UserInfo struct { Id int64 `json:"id" gorm:"id,omitempty"` Name string `json:"name" gorm:"name,omitempty"` FollowCount int64 `json:"follow_count" gorm:"follow_count,omitempty"` FollowerCount int64 `json:"follower_count" gorm:"follower_count,omitempty"` IsFollow bool `json:"is_follow" gorm:"is_follow,omitempty"` User *UserLogin `json:"-"` //用户与密码之间的多对多 Videos []*Video `json:"-"` //用户与投稿视频的一对多 Follows []*UserInfo `json:"-" gorm:"many2many:user_relations;"` //用户之间的多对多 FavorVideos []*Video `json:"-" gorm:"many2many:user_favor_videos;"` //用户与点赞视频之间的多对多 Comments []*Comment `json:"-"` //用户与评论的一对多 }
UserInfo 用户信息结构体
type UserInfoDAO ¶
type UserInfoDAO struct { }
UserInfoDAO 用户dao
func (*UserInfoDAO) AddUserFollow ¶
func (u *UserInfoDAO) AddUserFollow(userId, userToId int64) error
AddUserFollow 添加用户关注
func (*UserInfoDAO) AddUserInfo ¶
func (u *UserInfoDAO) AddUserInfo(userinfo *UserInfo) error
AddUserInfo 添加用户并返回用户信息
func (*UserInfoDAO) CancelUserFollow ¶
func (u *UserInfoDAO) CancelUserFollow(userId, userToId int64) error
CancelUserFollow 取消用户关注
func (*UserInfoDAO) GetFollowListByUserId ¶
func (u *UserInfoDAO) GetFollowListByUserId(userId int64, userList *[]*UserInfo) error
GetFollowListByUserId 通过用户id获取到关注列表
func (*UserInfoDAO) GetFollowerListByUserId ¶
func (u *UserInfoDAO) GetFollowerListByUserId(userId int64, userList *[]*UserInfo) error
GetFollowerListByUserId 按用户 ID 获取粉丝列表
func (*UserInfoDAO) IsUserExistById ¶
func (u *UserInfoDAO) IsUserExistById(id int64) bool
IsUserExistById 判断用户是否存在
func (*UserInfoDAO) QueryUserInfoById ¶
func (u *UserInfoDAO) QueryUserInfoById(userId int64, userinfo *UserInfo) error
QueryUserInfoById 查询用户信息通过id
type UserLogin ¶
type UserLogin struct { Id int64 `gorm:"primary_key"` UserInfoId int64 Username string `gorm:"primary_key"` Password string `gorm:"size:200;notnull"` }
UserLogin 用户登录表,和UserInfo属于一对一关系 UserLogin => user_logins 首字母小写+复数+下划线 [模型名和表名的映射关系]
type UserLoginDAO ¶
type UserLoginDAO struct { }
func NewUserLoginDao ¶
func NewUserLoginDao() *UserLoginDAO
func (*UserLoginDAO) IsUserExistByUsername ¶
func (u *UserLoginDAO) IsUserExistByUsername(username string) bool
func (*UserLoginDAO) QueryUserLogin ¶
func (u *UserLoginDAO) QueryUserLogin(username, password string, login *UserLogin) error
type Video ¶
type Video struct { Id int64 `json:"id,omitempty"` UserInfoId int64 `json:"-"` Author UserInfo `json:"author,omitempty" gorm:"-"` //这里应该是作者对视频的一对多的关系,而不是视频对作者,故gorm不能存他,但json需要返回它 PlayUrl string `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"` Title string `json:"title,omitempty"` Users []*UserInfo `json:"-" gorm:"many2many:user_favor_videos;"` Comments []*Comment `json:"-"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` }
Video `gorm:"-"` 读写操作均会忽略该字段
type VideoDAO ¶
type VideoDAO struct { }
func NewVideoDAO ¶
func NewVideoDAO() *VideoDAO
func (*VideoDAO) IsVideoExistById ¶
IsVideoExistById 视频是否存在
func (*VideoDAO) MinusOneFavorByUserIdAndVideoId ¶
MinusOneFavorByUserIdAndVideoId 用户某视频 减少一个赞
func (*VideoDAO) PlusOneFavorByUserIdAndVideoId ¶
PlusOneFavorByUserIdAndVideoId 用户某视频 增加一个赞
func (*VideoDAO) QueryFavorVideoListByUserId ¶
QueryFavorVideoListByUserId 查询用户点赞视频列表
func (*VideoDAO) QueryVideoByVideoId ¶
QueryVideoByVideoId 通过id查询视频
func (*VideoDAO) QueryVideoCountByUserId ¶
QueryVideoCountByUserId 通过用户id查询视频数量