models

package
v0.0.0-...-21eabe8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

* @Descripttion:content数据库调用 * @version:1.0 * @Author: sunylin * @Date: 2020-12-15 17:25:48 * @LastEditors: sunylin * @LastEditTime: 2020-12-21 22:26:09

* @Descripttion: * @version: * @Author: sunylin * @Date: 2020-12-16 15:03:45 * @LastEditors: sunylin * @LastEditTime: 2020-12-18 23:36:50

* @Descripttion: * @version: * @Author: sunylin * @Date: 2020-12-14 23:13:17 * @LastEditors: sunylin * @LastEditTime: 2020-12-22 19:19:22

* @Descripttion: * @version: * @Author: sunylin * @Date: 2020-12-16 16:06:27 * @LastEditors: sunylin * @LastEditTime: 2020-12-22 19:19:49

* @Descripttion:user的数据库调用 * @version:1.0 * @Author: sunylin * @Date: 2020-12-15 02:41:11 * @LastEditors: sunylin * @LastEditTime: 2020-12-22 10:18:36

Index

Constants

View Source
const (
	StatusSuccess                = "success"
	StatusBadReq                 = "bad_req"
	StatusNotLogin               = "not_login"
	StatusUserNameExist          = "username_exist"
	StatusUserNameNotExist       = "username_notexist"
	StatusEmailExist             = "email_exist"
	StatusEmailFormatError       = "email_format_error"
	StatusPasswordError          = "password_error"
	StatusNoID                   = "no_this_id"
	StatusEmptyName              = "name_nil"
	StatusEmptyEmail             = "email_nil"
	StatusLikeExist              = "like_exist"
	StatusLikeNotExist           = "like_not_exist"
	StatusNoContent              = "no_this_content"
	StatusNoUser                 = "no_this_user"
	StatusNotificationExist      = "notification_exist"
	StatusUserContentNotMatching = "user_content_id_not_matching"
	StatusContentOutofRange      = "content_out_of_range"
)

Status

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonRes

type CommonRes struct {
	State string
	Data  string
}

CommonRes 通用回应

type Content

type Content struct {
	ID          bson.ObjectId `bson:"_id"`
	Detail      string        `bson:"detail"`      // 详情介绍
	OwnID       bson.ObjectId `bson:"ownId"`       // 作者ID [索引]
	PublishDate int64         `bson:"publishDate"` // 发布日期
	LikeNum     int64         `bson:"likeNum"`     // 点赞数
	Public      bool          `bson:"public"`      // 是否公开
	Tag         []string      `bson:"tag"`         // 标签
}

Content 正文信息

type ContentDB

type ContentDB struct {
	DB     *mgo.Collection
	DBuser *mgo.Collection
}

ContentDB content数据库

func (*ContentDB) AddContent

func (m *ContentDB) AddContent(detail string, tag []string, ownID string, isPublic bool) (string, error)

AddContent 增加内容

func (*ContentDB) GetContentByUser

func (m *ContentDB) GetContentByUser(id string, page, eachpage int) (res ContentListByUser, err error)

GetContentByUser 获取他人的文章列表

func (*ContentDB) GetContentSelf

func (m *ContentDB) GetContentSelf(id string, page, eachpage int) (res ContentListByUser, err error)

GetContentSelf 根据自己的用户id获取文章列表

func (*ContentDB) GetDetailByID

func (m *ContentDB) GetDetailByID(id string) (res ContentDetailres, err error)

GetDetailByID 获取指定内容

func (*ContentDB) GetPublic

func (m *ContentDB) GetPublic(page, eachpage int) (res ContentPublicList, err error)

GetPublic 获取公共内容

func (*ContentDB) RemoveContent

func (m *ContentDB) RemoveContent(id string) (err error)

RemoveContent 删除内容

func (*ContentDB) UpdateContent

func (m *ContentDB) UpdateContent(contentID, detail string, tag []string, ownID string, isPublic bool) error

UpdateContent 增加内容

type ContentDetailres

type ContentDetailres struct {
	State string          //状态
	Data  Contentres      //文档数据
	User  ContentUserInfo //用户数据(这里少一个bio字段)
}

ContentDetailres 返回详情

type ContentListByUser

type ContentListByUser struct {
	State string
	Data  []Contentres
}

ContentListByUser 根据用户返回文章

type ContentPublicList

type ContentPublicList struct {
	State string
	Data  []ContentDetailres
}

ContentPublicList 返回公共文章

type ContentUserInfo

type ContentUserInfo struct {
	Name   string `bson:"name"`   // 用户昵称
	Avatar string `bson:"avatar"` // 头像URL
	Gender int    `bson:"gender"` // 性别
}

ContentUserInfo 用于返回详情中的的用户信息

type Contentres

type Contentres struct {
	ID          string   `bson:"_id"`
	Detail      string   `bson:"detail"`      // 详情介绍
	OwnID       string   `bson:"ownId"`       // 作者ID [索引]
	PublishDate int64    `bson:"publishDate"` // 发布日期
	LikeNum     int64    `bson:"likeNum"`     // 点赞数
	Public      bool     `bson:"public"`      // 是否公开
	Tag         []string `bson:"tag"`         // 标签
}

Contentres 正文信息

type Like

type Like struct {
	ID        bson.ObjectId `bson:"_id"`
	UserID    bson.ObjectId `bson:"userId"`    // 用户ID
	ContentID bson.ObjectId `bson:"contentId"` // 内容ID
}

Like 点赞信息

type LikeDB

type LikeDB struct {
	DBU *mgo.Collection //用户数据库
	DBL *mgo.Collection //点赞数据库
	DBC *mgo.Collection //文章数据库
	DBN *mgo.Collection //通知数据库
}

LikeDB like数据库

func (*LikeDB) CancelLikeByID

func (m *LikeDB) CancelLikeByID(Contentid, Userid string) (err error)

CancelLikeByID 通过用户id和文章id取消点赞

func (*LikeDB) GetUserListByContentID

func (m *LikeDB) GetUserListByContentID(Contentid string) (user []string, err error)

GetUserListByContentID 通过文章id获取点赞的用户列表

func (*LikeDB) LikeByID

func (m *LikeDB) LikeByID(Contentid, Userid string) (err error)

LikeByID 通过用户id和文章id点赞

type NotifiationDB

type NotifiationDB struct {
	DBN *mgo.Collection //通知数据库
	DBU *mgo.Collection //用户数据库
}

NotifiationDB 通知数据库

func (*NotifiationDB) DeleteNotificationByID

func (m *NotifiationDB) DeleteNotificationByID(id string) (err error)

DeleteNotificationByID 删除指定的内容

func (*NotifiationDB) GetNotificationByUserID

func (m *NotifiationDB) GetNotificationByUserID(id string) (res UserNotificationres, err error)

GetNotificationByUserID 获取指定用户通知

type NotificationDetail

type NotificationDetail struct {
	ID         bson.ObjectId `bson:"_id"`
	CreateTime int64         `bson:"time"`
	Content    string        `bson:"content"`   // 通知内容
	SourceID   bson.ObjectId `bson:"sourceId"`  // 源ID (点赞用户)
	TargetID   bson.ObjectId `bson:"targetId"`  // 目标ID (被点赞用户)
	ContentID  bson.ObjectId `bson:"contentId"` //点赞文章ID
	Type       string        `bson:"type"`      // 类型:暂时只有like
}

NotificationDetail 通知详情

type Notificationres

type Notificationres struct {
	Notification NotificationDetail
	User         ContentUserInfo
}

Notificationres 通知集合

type RootRes

type RootRes struct {
	UserGetInfo      string `json:"user_information_url"`
	UserPostLogin    string `json:"user_login_url"`
	UserPostRegister string `json:"user_register_url"`
	UserPostLogout   string `json:"user_logout_url"`
	UserPostName     string `json:"user_rename_url"`

	ContentDeleteBy    string `json:"content_url"`
	ContentGetDetailBy string `json:"content_detail_url"`
	ContentGetPublic   string `json:"content_public_url"`
	ContentGetTexts    string `json:"content_text_url"`
	ContentPostUpdate  string `json:"content_upadate_url"`

	Like string `json:"like_url"`

	Notification       string `json:"notification_url"`
	NotificationGetAll string `json:"notification_all_url"`
}

RootRes 简单 API 服务列表

type User

type User struct {
	ID           bson.ObjectId `bson:"_id"`          // 用户ID
	Pwd          string        `bson:"password"`     //用户密码
	Email        string        `bson:"email"`        // 用户唯一邮箱
	Info         UserInfo      `bson:"info"`         // 用户个性信息
	LikeCount    int64         `bson:"likeCount"`    // 被点赞数
	ContentCount int64         `bson:"contentCount"` // 内容数量
}

User 用户信息

type UserDB

type UserDB struct {
	DB *mgo.Collection
}

UserDB user数据库

func (*UserDB) AddUser

func (m *UserDB) AddUser(email, pwd, name, avatar, bio string, gender int) (newUser bson.ObjectId, err error)

AddUser 添加用户,返回新用户ID和错误信息

func (*UserDB) GetUserByID

func (m *UserDB) GetUserByID(id string) (User, error)

GetUserByID 根据ID查询用户

func (*UserDB) GetUserInfo

func (m *UserDB) GetUserInfo(id string) (res UserInfoRes, err error)

GetUserInfo 获取用户信息

func (*UserDB) Login

func (m *UserDB) Login(username, pwd string) (string, error)

Login 登陆

func (*UserDB) Register

func (m *UserDB) Register(username, pwd, email string) (err error)

Register 注册

func (*UserDB) SetUserInfo

func (m *UserDB) SetUserInfo(id string, info UserInfo) error

SetUserInfo 设置用户信息

func (*UserDB) SetUserName

func (m *UserDB) SetUserName(id, name string) error

SetUserName 设置用户名

type UserInfo

type UserInfo struct {
	Name   string `bson:"name"`   // 用户昵称
	Avatar string `bson:"avatar"` // 头像URL
	Bio    string `bson:"bio"`    // 个人简介
	Gender int    `bson:"gender"` // 性别
}

UserInfo 用户个性信息

type UserInfoRes

type UserInfoRes struct {
	State string
	ID    string
	Email string
	Info  UserInfo
}

UserInfoRes 获取用户信息的回应

type UserNotificationres

type UserNotificationres struct {
	State         string
	Notifications []Notificationres
}

UserNotificationres 响应用户通知集合

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL