db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFetchingPost = errors.New("somethings bad append while fetching post")
View Source
var ErrNoDocument = errors.New("the selected post doesn't exist")
View Source
var ErrNoPost = errors.New("the selected user has no post shared")
View Source
var ErrUserAlreadyRegistered = errors.New("the selected user is already registered in the database")
View Source
var ErrWrongUserDbId = errors.New("the provided user db id is different from the wanted one")

Functions

func CheckUser

func CheckUser(userDiscordId string) (err error, isUserExist bool, userId primitive.ObjectID)

CheckUser function check if a user exists in the database according to his discord id

func CountScorePost

func CountScorePost(postRecord PostRecordFetchT, userId primitive.ObjectID) (globalVote int, userVote string)

CountScorePost function calculate the total score of a post according to the provided post (postRecord), it can also return the score of a specific user on this post according to the provided db id (userDbId)

func DeletePost

func DeletePost(postId, userId primitive.ObjectID, isBotAdmin bool) (err error)

func GetDiscordId

func GetDiscordId(userId primitive.ObjectID) (err error, userDiscordId string)

GetDiscordId function get and return the user discord id according to the provided mongodb _id

func Post

func Post(userId primitive.ObjectID, postType, postUrl string) (postAlreadyExist bool, postId string)

The Post function check if post exist in the database according to his link.

1. If it not exists the post will be added and the function will return (false, OBJECTID)

2. Else it will return (true, "")

func RegisterUser

func RegisterUser(userDiscordId string) (err error)

RegisterUser register a user if it doesn't exist in the database using his discord id

func SetVote

func SetVote(postId, userVote string, userId primitive.ObjectID) (error, bool)

The SetVote function add or remove a like to post (set with the Post function)

NOTE: it will return true if the vote has been added and false if not

Types

type PostRecordFetchT

type PostRecordFetchT struct {
	ID       primitive.ObjectID `bson:"_id" json:"id,omitempty"`
	Type     string
	Url      string
	User     primitive.ObjectID
	VoteList []postVote
}

func GetVote

func GetVote(postId string, userId primitive.ObjectID) (err error, globalVote int, userVote string, postFetch PostRecordFetchT)

GetVote function fetch and return all the information about a post according to the provided postId and userId

type UserInfoFetch

type UserInfoFetch struct {
	ID          primitive.ObjectID `bson:"_id" json:"id,omitempty"`
	Posts       []PostRecordFetchT
	GlobalScore int
}

func GetUserInfo

func GetUserInfo(userId primitive.ObjectID) (err error, userStats UserInfoFetch)

GetUserInfo function get and return all the user infos according to the provided mongodb _id

Jump to

Keyboard shortcuts

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