database

package
v0.0.0-...-3056a10 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package database provides the internal database of DiscussionGo! The access times of topics are in an other module (accesstimes). This allows for both data sources to be operated separately.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddInvitation

func AddInvitation(user string) (string, error)

AddInvitation adds a new invitation from a user. It returns the ID of the new invitation.

func AddPost

func AddPost(topicID, user, content string) (string, error)

AddPost saves a post to the database.

func AddTopic

func AddTopic(name, creator string) (string, error)

AddTopic adds a new topic to the database. The modification time is set to the current time.

func AddUser

func AddUser(user, pw string, admin bool) error

AddUser adds a new user to the database. Admin status is automatically set to the provided value. Returns an error if the user alreasy exist.

func DeletePost

func DeletePost(topicID, ID string) error

DeletePost removes a post completely from the database. This action can not be undone.

func DeleteTopic

func DeleteTopic(ID string) error

DeleteTopic removes a topic and all associated posts from the database. This action can not be undone.

func DeleteUser

func DeleteUser(user string) (int64, error)

DeleteUser removes a user and all associated information from the database. It returns the number of removed informations. It can not be reverted.

func EditPassword

func EditPassword(user, pw string) error

EditPassword changes the password of a user. Returns an error if the user does not exist.

func GetInvitationCreator

func GetInvitationCreator(id string) (string, error)

GetInvitationCreator returns the creator of an invitation (identified by ID).

func GetInvitations

func GetInvitations(user string) ([]string, error)

GetInvitations returns all invitations (identified by ID) created by a user.

func GetLastUpdateTopicPost

func GetLastUpdateTopicPost() int64

GetLastUpdateTopicPost returns the time of the last update of any post/topic as an int64 in nano seconds.

func InitDB

func InitDB(config string) error

InitDB initialises the database. Must be called before any other function. This stub will return an error if no build tags are set.

func IsAdmin

func IsAdmin(user string) (bool, error)

IsAdmin returns whether a user is administrator. Returns an error if the user does not exist.

func ModifyLastSeen

func ModifyLastSeen(user string) error

ModifyLastSeen sets the 'last seen' status of a user to the current time. Returns an error if the user does not exist.

func RemoveAllInvitation

func RemoveAllInvitation() error

RemoveAllInvitation removes all invitations from the database, making all invalid.

func RemoveInvitation

func RemoveInvitation(id string) error

RemoveInvitation returns the invitation (identified by ID) from the database. It is no longer valid.

func RenameTopic

func RenameTopic(ID string, newName string) error

RenameTopic renames a topic. It does affect the modification time.

func SetAdmin

func SetAdmin(user string, admin bool) error

SetAdmin sets whether a user is administrator. Returns an error if the user does not exist.

func SetComment

func SetComment(user string, comment string) error

SetComment updates the comment of a user. Returns an error if the user does not exist.

func SetInvitedby

func SetInvitedby(user, invitedby string, direct bool) error

SetInvitedby sets which user invited the user. Returns an error if the target user does not exist. It does not check if the invitor does not exists. This is intentioal, allowing 'pseudo user' as an inviter.

func SetLastUpdateTopicPost

func SetLastUpdateTopicPost()

SetLastUpdateTopicPost updates the time of the last update of any post/topic. It is internally called by the functions of the database package. You only need to call it if you manually update a post (e.g. by adding data to the post which is stored in an other package).

func TestInvitation

func TestInvitation(id string) (bool, error)

TestInvitation returns whether an invitation is valid.

func TopicModifyTime

func TopicModifyTime(ID string) error

TopicModifyTime sets the modification time of a topic to the current time.

func TopicSetClosed

func TopicSetClosed(ID string, closed bool) error

TopicSetClosed sets the 'closed' property of a topic to the given value. It does not affect the modification time.

func TopicSetPinned

func TopicSetPinned(ID string, pinned bool) error

TopicSetPinned sets the 'pinned' property of a topic to the given value. It does not affect the modification time.

func UserExists

func UserExists(user string) (bool, error)

UserExists returns whether the user is known in the database. It only returns an error if a communication problem with the database occured. In all other cases, the bool signals whether the user is known.

func VerifyUser

func VerifyUser(user, pw string) (bool, error)

VerifyUser returns whether the user exists and the provided password is correct. It should only return an error on communication problems with the database, but not if any checks fail.

Types

type Post

type Post struct {
	ID      string
	TopicID string
	Poster  string
	Content string
	Time    time.Time
}

Post represents a post in the database.

func GetPosts

func GetPosts(topicID string) ([]Post, error)

GetPosts returns all posts of a topic from the database.

func GetPostsByUser

func GetPostsByUser(user string) ([]Post, error)

GetPostsByUser returns all posts of a user from the database.

func GetSinglePost

func GetSinglePost(ID string) (Post, error)

GetSinglePost returns the post associated with the given ID.

type Topic

type Topic struct {
	ID           string
	Name         string
	Creator      string
	Created      time.Time
	LastModified time.Time
	Closed       bool
	Pinned       bool
}

Topic represents a topic in the database.

func GetTopic

func GetTopic(ID string) (Topic, error)

GetTopic returns the topic currently associated by the ID.

func GetTopics

func GetTopics() ([]Topic, error)

GetTopics returns all topics currently saved in the database.

func GetTopicsByUser

func GetTopicsByUser(user string) ([]Topic, error)

GetTopicsByUser returns all topics belonging to a user currently saved in the database.

type User

type User struct {
	Name             string
	Admin            bool
	Comment          string
	InvidedBy        string
	InvitationDirect bool
	LastSeen         time.Time
}

User represents a user in the database. For security reasons, the password and the salt is not included.

func GetAllUser

func GetAllUser() ([]User, error)

GetAllUser returns all user currently known to the database.

func GetUser

func GetUser(user string) (User, error)

GetUser returns a user struct with all information of the associated user (except password hash and salt). Returns an error if the user does not exist.

Jump to

Keyboard shortcuts

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