database

package
v0.0.0-...-5e5badb Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Collections = struct {
	Users, Migrations, Hubs, Servers, Messages string
}{
	Users:      "users",
	Hubs:       "hubs",
	Servers:    "servers",
	Migrations: "migrations",
	Messages:   "messages",
}

Collections is pseudo enum to specify collection name

Functions

func MigrationRun

func MigrationRun(mc *MongoClient)

MigrationRun runs all migrations before starting service for backend to be ready for presentation

Types

type Hub

type Hub struct {
	ID       primitive.ObjectID   `bson:"_id" json:"id,omitempty"`
	UserIDS  []primitive.ObjectID `bson:"userIds" json:"userIds"`
	Name     string               `bson:"name" json:"name"`
	AdminIds []primitive.ObjectID `bson:"adminIds" json:"adminIds"`
}

Hub represents mongo document which stores hub information containing all ids of users that can connect to the hub

type IDS

type IDS struct {
	IDS []string `json:"ids"`
}

IDS allows for casting ReadMany request

type Message

type Message struct {
	ID        primitive.ObjectID  `bson:"_id" json:"_id"`
	UserID    primitive.ObjectID  `bson:"userId" json:"userId"`
	HubID     primitive.ObjectID  `bson:"hubId" json:"hubId"`
	Text      string              `bson:"text" json:"text"`
	WrittenAt primitive.Timestamp `bson:"writtenAt" json:"writtenAT"`
}

Message represents mongo document which stores message information in messages collection

type Migration

type Migration struct {
	ID   primitive.ObjectID `bson:"_id" json:"id,omitempty"`
	Name string             `json:"name"`
}

Migration specifies if migration of certain name is applied on database

type ModelID

type ModelID struct {
	ID string `bson:"_id" json:"id,omitempty"`
}

ModelID allows for all database models to query by id, or map document to id

type MongoClient

type MongoClient struct {
	// contains filtered or unexported fields
}

MongoClient handles connection to database

func NewMongoClient

func NewMongoClient(uri string, database string) (*MongoClient, error)

NewMongoClient creates instance of MongoClient Connects to mongo db database and returns pointer to new instance structure of MongoClient

func (*MongoClient) AddNewHub

func (mc *MongoClient) AddNewHub(name string, userID primitive.ObjectID, serverID primitive.ObjectID) (bool, error)

AddNewHub adds new hub to database collection and to actual server

func (*MongoClient) AddUserToHub

func (mc *MongoClient) AddUserToHub(adminID primitive.ObjectID, userID primitive.ObjectID, hubID primitive.ObjectID) (bool, error)

AddUserToHub add user by id to hub if performing action user is an admin of a hub

func (*MongoClient) CreateNewUser

func (mc *MongoClient) CreateNewUser(payload io.ReadCloser) (bool, error)

CreateNewUser checks if user of provided id exists and if not then creates new one returns UserID, ok if sure that user do not exist, and error Password is encrypted using bcrypt

func (*MongoClient) Execute

func (mc *MongoClient) Execute(payload json.RawMessage) ([]byte, error)

Execute executes query on given graphql payload and returns Marshaled bytes slice

func (*MongoClient) FindServerByName

func (mc *MongoClient) FindServerByName(name string) (*Server, error)

FindServerByName returns server document from database

func (*MongoClient) GetHubIDIfHasUser

func (mc *MongoClient) GetHubIDIfHasUser(serverID primitive.ObjectID, hubName string, userID primitive.ObjectID) (bool, primitive.ObjectID, error)

GetHubIDIfHasUser check if hub on a given server exists, and if hub contains user, if so returns success and hubId, otherwise failure and NilObjectID

func (*MongoClient) GetServerHubIds

func (mc *MongoClient) GetServerHubIds(serverID primitive.ObjectID) (*[]primitive.ObjectID, error)

GetServerHubIds returns all hubs that belongs to server

func (*MongoClient) Login

func (mc *MongoClient) Login(payload io.ReadCloser) (*User, error)

Login handles user login based on database stored user data and password Password is encrypted and cannot be compared without bcrypt

func (*MongoClient) WriteMessage

func (mc *MongoClient) WriteMessage(userID primitive.ObjectID, hubID primitive.ObjectID, text string) error

WriteMessage writes message to database of collection messages

type QueryData

type QueryData struct {
	Query string `json:"query"`
}

QueryData represents format of query in the Mesaage payload received from the client

type Server

type Server struct {
	ID     primitive.ObjectID   `bson:"_id" json:"_id"`
	URL    string               `bson:"url" json:"url"`
	Name   string               `bson:"name" json:"name"`
	Hubs   []primitive.ObjectID `bson:"hubs" json:"hubs"`
	Active bool                 `bson:"active" json:"active"`
}

Server represents mongo document which stores server information containing all hubs that can be run on this server

type User

type User struct {
	ID            string
	NickName      string `json:"nickName"`
	Email         string `json:"email"`
	Authenticated bool
}

User handles users session information

type UserCredentials

type UserCredentials struct {
	ID       primitive.ObjectID `bson:"_id" json:"id,omitempty"`
	NickName string             `bson:"nickName" json:"nickName"`
	Email    string             `json:"email" example:"support@domain.com"`
	Password string             `json:"password" example:"secret"`
	Active   bool               `json:"active" example:"true"`
}

UserCredentials stores user information

Jump to

Keyboard shortcuts

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