primboard

package
v0.0.0-...-0a5c495 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2020 License: AGPL-3.0 Imports: 28 Imported by: 0

README

Go API Server for swagger

PrImBoard (Private Image Board) can be best described as an image board for all the picures and videos you have taken. You can invite users to the board and share specific images with them or your family members!

Overview

This server was generated by the [swagger-codegen] (https://github.com/swagger-api/swagger-codegen) project.
By using the OpenAPI-Spec from a remote server, you can easily generate a server stub.

To see how to make this your own, look here:

README

  • API version: 1.0.0
  • Build date: 2019-11-29T12:40:25.493Z[GMT]
Running the server

To run the server, follow these simple steps:

go run main.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EventProject = bson.M{
	"id":                1,
	"title":             1,
	"description":       1,
	"comments":          1,
	"creator":           1,
	"groups":            1,
	"timestampCreation": 1,
	"timestampStart":    1,
	"timestampEnd":      1,
	"url":               1,
	"urlThumb":          1,
}

EventProject is a bson representation of the event object

View Source
var IPFSNodeProject = bson.M{
	"title":       1,
	"username":    1,
	"password":    1,
	"address":     1,
	"ipfsApiPort": 1,
	"ipfsApiUrl":  1,
	"ipfsGateway": 1,
}

IPFSNodeProject is a bson representation of the ipfs-node setting object

View Source
var MediaProject = bson.M{
	"_id":             1,
	"sha1":            1,
	"title":           1,
	"description":     1,
	"comments":        1,
	"creator":         1,
	"events":          1,
	"timestamp":       1,
	"timestampUpload": 1,
	"url":             1,
	"urlThumb":        1,
	"type":            1,
	"format":          1,
	"contentType":     1,
	"tags":            1,
	"users":           UserProject,
	"groups":          UserGroupProject,
	"nodes":           NodeProject,
}

MediaProject is a bson representation of the $project aggregation for mongodb

View Source
var NodeProject = bson.M{
	"id":      1,
	"title":   1,
	"creator": 1,
	"type":    1,
	"groups":  1,
	"url":     1,
}

NodeProject is a bson representation of the ipfs-node setting object

View Source
var Sessions = []*Session{}

Sessions is a map of token/session strings for authenticated users

View Source
var SettingsProject = bson.M{
	"ipfsNodes": IPFSNodeProject,
}

SettingsProject is a bson representation of the settings object

View Source
var UserGroupProject = bson.M{
	"_id":     1,
	"title":   1,
	"creator": 1,
	"users":   1,
}

UserGroupProject is a bson representation of a user group

View Source
var UserProject = bson.M{
	"username":  1,
	"firstName": 1,
	"lastName":  1,
	"urlImage":  1,
}

UserProject is a bson representation of the user object

View Source
var UserSettingsProject = bson.M{
	"settings": SettingsProject,
}

Functions

func BulkAddMediaEvent

func BulkAddMediaEvent(db *mongo.Database, mediaIDs []primitive.ObjectID, eventIDs []primitive.ObjectID, permission bson.M) (*mongo.BulkWriteResult, error)

BulkAddMediaEvent bulk operates an add events to many media ids

func BulkAddMediaGroup

func BulkAddMediaGroup(db *mongo.Database, mediaIDs []primitive.ObjectID, groupIDs []primitive.ObjectID, permission bson.M) (*mongo.BulkWriteResult, error)

BulkAddMediaGroup bulk operates an adds groups to many media ids

func BulkAddTagEvent

func BulkAddTagEvent(db *mongo.Database, tags []string, ids []primitive.ObjectID, permission bson.M) (*mongo.BulkWriteResult, error)

BulkAddTagEvent bulk operates a tag slice to many media ids

func BulkAddTagMedia

func BulkAddTagMedia(db *mongo.Database, tags []string, ids []primitive.ObjectID, permission bson.M) (*mongo.BulkWriteResult, error)

BulkAddTagMedia bulk operates an add Tags to many media ids

func CloseSession

func CloseSession(w *http.ResponseWriter, r *http.Request)

CloseSession deletes the token/session pair from cache and lets the cookie expire

func DecodeTagStringRequest

func DecodeTagStringRequest(w http.ResponseWriter, r *http.Request, t string) (string, int)

DecodeTagStringRequest decodes the api request into the passed object responds with decode error if occurs status 0 => ok || status 1 => error

func DecodeTagStringsRequest

func DecodeTagStringsRequest(w http.ResponseWriter, r *http.Request, t []string) ([]string, int)

DecodeTagStringsRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

func HashPassword

func HashPassword(password string) (hashedPassword string)

HashPassword hashes the passed passwort using bcrypt

func Logger

func Logger(inner http.Handler, name string) http.Handler

Logger logs the request

func MatchesBcrypt

func MatchesBcrypt(password string, hash string) error

MatchesBcrypt verifies, that a given string is equal to a encrypted string

func ParseIDs

func ParseIDs(ids []string) ([]primitive.ObjectID, error)

ParseIDs parses a slice of hex ids into primitive.ObjectIDs

func ReadSessionCookie

func ReadSessionCookie(w *http.ResponseWriter, r *http.Request) string

ReadSessionCookie reads the stoken cookie from the request and returns the value

func RemoveString

func RemoveString(s []string, r string) []string

RemoveString removes a given string from a given slice

func SetSessionCookie

func SetSessionCookie(w *http.ResponseWriter, r *http.Request, session *Session)

SetSessionCookie renews the session attributes and adds the token to the cookie

func UniqueStrings

func UniqueStrings(slice []string) []string

UniqueStrings removes all duplicates from a string slice and returns the result

func VerifyTag

func VerifyTag(db *mongo.Database, tag string) (string, error)

VerifyTag creates the tag if not in the db already and returns the name in the db

func VerifyTags

func VerifyTags(db *mongo.Database, tags []string) ([]string, error)

VerifyTags iterates over an array of tags and creates the tags if not in db already. Uniquifies the slice and returns the clean slice.

Types

type App

type App struct {
	Router *mux.Router
	DB     *mongo.Database
	Config *m.APIGatewayConfig
	Nodes  []Node // stores all authenticated nodes
}

App struct to maintain database connection and router

func (*App) AddCommentByMediaID

func (a *App) AddCommentByMediaID(w http.ResponseWriter, r *http.Request)

AddCommentByMediaID appends a comment to the specified media

func (*App) AddDescriptionByMediaID

func (a *App) AddDescriptionByMediaID(w http.ResponseWriter, r *http.Request)

AddDescriptionByMediaID adds the description to the media

func (*App) AddEvent

func (a *App) AddEvent(w http.ResponseWriter, r *http.Request)

AddEvent handles the webrequest for Event creation

func (*App) AddIPFSNodeByUsername

func (a *App) AddIPFSNodeByUsername(w http.ResponseWriter, r *http.Request)

AddIPFSNodeByUser adds an ipfs-node setting to the users settings

func (*App) AddMedia

func (a *App) AddMedia(w http.ResponseWriter, r *http.Request)

AddMedia handles the webrequest for Media creation

func (*App) AddNode

func (a *App) AddNode(w http.ResponseWriter, r *http.Request)

AddNode handles the webrequest for Node creation

func (*App) AddTag

func (a *App) AddTag(w http.ResponseWriter, r *http.Request)

AddTag handles the webrequest for Tag creation

func (*App) AddTagByMediaID

func (a *App) AddTagByMediaID(w http.ResponseWriter, r *http.Request)

AddTagByMediaID appends a tag to the specified media creates a new tag if not in the tag document

func (*App) AddTagsByMediaID

func (a *App) AddTagsByMediaID(w http.ResponseWriter, r *http.Request)

AddTagsByMediaID appends multiple tags to the specified media creates a new tag if not in the tag document

func (*App) AddTimestampByMediaID

func (a *App) AddTimestampByMediaID(w http.ResponseWriter, r *http.Request)

AddTimestampByMediaID adds the creation date to the media

func (*App) AddTitleByMediaID

func (a *App) AddTitleByMediaID(w http.ResponseWriter, r *http.Request)

AddTitleByMediaID adds the title to the media

func (*App) AddUserGroup

func (a *App) AddUserGroup(w http.ResponseWriter, r *http.Request)

AddUserGroup handles the webrequest for usergroup creation

func (*App) AddUserGroupsByMediaID

func (a *App) AddUserGroupsByMediaID(w http.ResponseWriter, r *http.Request)

AddUserGroupsByMediaID appends multiple tags to the specified media creates a new tag if not in the tag document

func (*App) AddUserToUserGroupByID

func (a *App) AddUserToUserGroupByID(w http.ResponseWriter, r *http.Request)

AddUserToUserGroupByID adds a User to the specified usergroup

func (*App) AddUsersToUserGroupByID

func (a *App) AddUsersToUserGroupByID(w http.ResponseWriter, r *http.Request)

AddUsersToUserGroupByID adds a User to the specified usergroup

func (*App) Authenticate

func (a *App) Authenticate(h http.Handler, logout bool) http.Handler

Authenticate is a middleware to pre-authenticate routes via the session token if logout is true, no new session token is beeing generated

func (*App) AuthenticateNode

func (a *App) AuthenticateNode(w http.ResponseWriter, r *http.Request)

AuthenticateNode selects the specified node from db and verifies the psk

func (*App) Connect

func (a *App) Connect()

Connect initializes a mongodb connection

func (*App) CreateUser

func (a *App) CreateUser(w http.ResponseWriter, r *http.Request)

CreateUser handles the webrequest for user creation

func (*App) DeleteEventByID

func (a *App) DeleteEventByID(w http.ResponseWriter, r *http.Request)

DeleteEventByID handles the webrequest for Event deletion

func (*App) DeleteMediaByID

func (a *App) DeleteMediaByID(w http.ResponseWriter, r *http.Request)

DeleteMediaByID handles the webrequest for Media deletion

func (*App) DeleteNodeByID

func (a *App) DeleteNodeByID(w http.ResponseWriter, r *http.Request)

DeleteNodeByID handles the webrequest for Node deletion

func (*App) DeleteTagByID

func (a *App) DeleteTagByID(w http.ResponseWriter, r *http.Request)

DeleteTagByID handles the webrequest for Tag deletion

func (*App) DeleteUser

func (a *App) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser handles the webrequest for user deletion

func (*App) DeleteUserGroupByID

func (a *App) DeleteUserGroupByID(w http.ResponseWriter, r *http.Request)

DeleteUserGroupByID handles the webrequest for usergroup deletion

func (*App) GenerateInvite

func (a *App) GenerateInvite(w http.ResponseWriter, r *http.Request)

GenerateInvite handles the webrequest for creating a new invite

func (*App) GetEventByID

func (a *App) GetEventByID(w http.ResponseWriter, r *http.Request)

GetEventByID handles the webrequest for receiving Event model by id

func (*App) GetEvents

func (a *App) GetEvents(w http.ResponseWriter, r *http.Request)

GetEvents handles the webrequest for receiving all events

func (*App) GetEventsByName

func (a *App) GetEventsByName(w http.ResponseWriter, r *http.Request)

GetEventsByName returns available Events by their name, starting with

func (*App) GetIPFSNodesByUsername

func (a *App) GetIPFSNodesByUsername(w http.ResponseWriter, r *http.Request)

GetIPFSNodesByUsername returns all IPFSNodes for the current user

func (*App) GetMedia

func (a *App) GetMedia(w http.ResponseWriter, r *http.Request)

GetMedia handles the webrequest for receiving all media

func (*App) GetMediaByHash

func (a *App) GetMediaByHash(w http.ResponseWriter, r *http.Request)

GetMediaByHash Handles the webrequest for receiving Media model by ipfs hash and mongo id

func (*App) GetMediaByID

func (a *App) GetMediaByID(w http.ResponseWriter, r *http.Request)

GetMediaByID handles the webrequest for receiving Media model by id

func (*App) GetMediaByIDs

func (a *App) GetMediaByIDs(w http.ResponseWriter, r *http.Request)

GetMediaByIDs handles the webrequest for receiving Media models by ids

func (*App) GetNodeByID

func (a *App) GetNodeByID(w http.ResponseWriter, r *http.Request)

GetNodeByID handles the webrequest for receiving Node model by id

func (*App) GetNodes

func (a *App) GetNodes(w http.ResponseWriter, r *http.Request)

GetNodes handles the webrequest for receiving all nodes

func (*App) GetSettingsByUsername

func (a *App) GetSettingsByUsername(w http.ResponseWriter, r *http.Request)

func (*App) GetTagByID

func (a *App) GetTagByID(w http.ResponseWriter, r *http.Request)

GetTagByID handles the webrequest for receiving Tag model by id

func (*App) GetTags

func (a *App) GetTags(w http.ResponseWriter, r *http.Request)

GetTags returns all Tags available

func (*App) GetTagsByName

func (a *App) GetTagsByName(w http.ResponseWriter, r *http.Request)

GetTagsByName returns available Tags by their name, starting with

func (*App) GetUserByUsername

func (a *App) GetUserByUsername(w http.ResponseWriter, r *http.Request)

GetUserByUsername handles the webrequest for receiving user model by username

func (*App) GetUserGroupByID

func (a *App) GetUserGroupByID(w http.ResponseWriter, r *http.Request)

GetUserGroupByID handles the webrequest for receiving usergroup model by id

func (*App) GetUserGroups

func (a *App) GetUserGroups(w http.ResponseWriter, r *http.Request)

GetUserGroups returns all groups, the current user is assigned to

func (*App) GetUserGroupsByName

func (a *App) GetUserGroupsByName(w http.ResponseWriter, r *http.Request)

GetUserGroupsByName returns available Tags by their name, starting with

func (*App) Index

func (a *App) Index(w http.ResponseWriter, r *http.Request)

Index controller

func (*App) Initialize

func (a *App) Initialize(config models.APIGatewayConfig)

Initialize initializes application related content - mongodb connection initialization - router initialization

func (*App) InitializeRoutes

func (a *App) InitializeRoutes()

InitializeRoutes initializes all the available webroutes

func (*App) LoginUser

func (a *App) LoginUser(w http.ResponseWriter, r *http.Request)

LoginUser Handles the webrequest for logging the user in

func (*App) LogoutUser

func (a *App) LogoutUser(w http.ResponseWriter, r *http.Request)

LogoutUser handles the webrequest for logging the user out

func (*App) MapEventsToMedia

func (a *App) MapEventsToMedia(w http.ResponseWriter, r *http.Request)

MapEventsToMedia maps an media slice to each event entry

func (*App) MapGroupsToMedia

func (a *App) MapGroupsToMedia(w http.ResponseWriter, r *http.Request)

MapGroupsToMedia maps an media slice to each event entry

func (*App) MapTagsToEvents

func (a *App) MapTagsToEvents(w http.ResponseWriter, r *http.Request)

MapTagsToEvents maps a slice of Tags to a slice of events

func (*App) MapTagsToMedia

func (a *App) MapTagsToMedia(w http.ResponseWriter, r *http.Request)

MapTagsToMedia adds a list of tags to a list of media

func (*App) NewSession

func (a *App) NewSession(user User) *Session

NewSession initializes a new Session (if not exists) for the passed user otherwise it updates the token

func (*App) RemoveUserFromUserGroupByID

func (a *App) RemoveUserFromUserGroupByID(w http.ResponseWriter, r *http.Request)

RemoveUserFromUserGroupByID adds a User to the specified usergroup

func (*App) RemoveUsersFromUserGroupByID

func (a *App) RemoveUsersFromUserGroupByID(w http.ResponseWriter, r *http.Request)

RemoveUsersFromUserGroupByID adds a User to the specified usergroup

func (*App) Run

func (a *App) Run(addr string)

Run starts the application on the passed address with the inherited router WARN: router must be initialized first

func (*App) UpdateEventByID

func (a *App) UpdateEventByID(w http.ResponseWriter, r *http.Request)

UpdateEventByID handles the webrequest for updating the Event with the passed request body

func (*App) UpdateMediaByHash

func (a *App) UpdateMediaByHash(w http.ResponseWriter, r *http.Request)

UpdateMediaByHash handles the webrequest for updating the Media with the passed request body

func (*App) UpdateMediaByID

func (a *App) UpdateMediaByID(w http.ResponseWriter, r *http.Request)

UpdateMediaByID handles the webrequest for updating the Media with the passed request body

func (*App) UpdateNodeByID

func (a *App) UpdateNodeByID(w http.ResponseWriter, r *http.Request)

UpdateNodeByID handles the webrequest for updating the Node with the passed request body

func (*App) UpdateTagByID

func (a *App) UpdateTagByID(w http.ResponseWriter, r *http.Request)

UpdateTagByID handles the webrequest for updating the Tag with the passed request body

func (*App) UpdateUser

func (a *App) UpdateUser(w http.ResponseWriter, r *http.Request)

UpdateUser handles the webrequest for updating the user with the passed request body

func (*App) UpdateUserGroupByID

func (a *App) UpdateUserGroupByID(w http.ResponseWriter, r *http.Request)

UpdateUserGroupByID handles the webrequest for updating the usergroup with the passed request body

func (*App) UploadMedia

func (a *App) UploadMedia(w http.ResponseWriter, r *http.Request)

UploadMedia handles the webrequest for uploading a file to the api

type Comment

type Comment struct {
	Timestamp int64  `json:"timestamp,omitempty"`
	Username  string `json:"username,omitempty"`
	Comment   string `json:"comment,omitempty"`
}

Comment type that is beeing referenced by multiple other types

func DecodeCommentRequest

func DecodeCommentRequest(w http.ResponseWriter, r *http.Request, c Comment) (Comment, int)

DecodeCommentRequest decodes the api request into the passed object responds with decode error if occurs status 0 => ok || status 1 => error

func DecodeCommentsRequest

func DecodeCommentsRequest(w http.ResponseWriter, r *http.Request, c []Comment) ([]Comment, int)

DecodeCommentsRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

func (*Comment) AddMetadata

func (c *Comment) AddMetadata(username string)

AddMetadata sets the passed username and the current timestamp for this comment

func (*Comment) IsValid

func (c *Comment) IsValid() error

IsValid verifies, that all values of that comment are valid and allowed

type DBConnection

type DBConnection struct {
	Col    *mongo.Collection
	Ctx    context.Context
	Cancel context.CancelFunc
}

DBConnection holds information about the collection and the context

func GetColCtx

func GetColCtx(model string, db *mongo.Database, duration time.Duration) DBConnection

GetColCtx returns the collection for the specified model and initializes a timeout context with passed duration

type Event

type Event struct {
	ID                primitive.ObjectID   `json:"id,omitempty" bson:"_id,omitempty"`
	Title             string               `json:"title,omitempty" bson:"title,omitempty"`
	Description       string               `json:"description,omitempty" bson:"description,omitempty"`
	Comments          []*Comment           `json:"comments,omitempty" bson:"comments,omitempty"`
	Creator           string               `json:"creator,omitempty" bson:"creator,omitempty"`
	Groups            []primitive.ObjectID `json:"groups,omitempty" bson:"groups,omitempty"`
	TimestampCreation int64                `json:"timestampCreation,omitempty" bson:"timestampCreation,omitempty"`
	TimestampStart    int64                `json:"timestampStart,omitempty" bson:"timestampStart,omitempty"`
	TimestampEnd      int64                `json:"timestampEnd,omitempty" bson:"timestampEnd,omitempty"`
	URL               string               `json:"url,omitempty" bson:"url,omitempty"`
	URLThumb          string               `json:"urlThumb,omitempty" bson:"urlThumb,omitempty"`
}

Event holds comments, media and the information about the the event

func GetAllEvents

func GetAllEvents(db *mongo.Database) ([]Event, error)

GetAllEvents selects all Events from the mongodb

func GetEventsByIDs

func GetEventsByIDs(db *mongo.Database, ids []primitive.ObjectID, permission bson.M) ([]Event, error)

GetEventsByIDs selects multiple Media Documents for the passed ids. verifies the reading permissions

func GetEventsByKeyword

func GetEventsByKeyword(db *mongo.Database, permission bson.M, keyword string, limit int64) ([]Event, error)

GetEventsByKeyword returns the topmost events that are starting with the keyword

func (*Event) AddEvent

func (e *Event) AddEvent(db *mongo.Database) (*mongo.InsertOneResult, error)

AddEvent creates the model in the mongodb

func (*Event) DeleteEvent

func (e *Event) DeleteEvent(db *mongo.Database) (*mongo.DeleteResult, error)

DeleteEvent deletes the model from the mongodb

func (*Event) GetEvent

func (e *Event) GetEvent(db *mongo.Database, permission bson.M) error

GetEvent returns the specified entry from the mongodb

func (*Event) GetEventCreate

func (e *Event) GetEventCreate(db *mongo.Database, permission bson.M, creator string) error

GetEventCreate selects the passed event from database -> creates if not exist

func (*Event) UpdateEvent

func (e *Event) UpdateEvent(db *mongo.Database, ue Event, permission bson.M) (*mongo.UpdateResult, error)

UpdateEvent updates the record with the passed one

func (*Event) VerifyEvent

func (e *Event) VerifyEvent(db *mongo.Database) error

VerifyEvent verifies all mandatory fields of the specified event does not verify ID

type IPFSNode

type IPFSNode struct {
	Title       string `json:"title" bson:"title"`
	Username    string `json:"username" bson:"username"`
	Password    string `json:"password,omitempty" bson:"password,omitempty"`
	Address     string `json:"address,omitempty" bson:"address,omitempty"`
	IPFSAPIPort int    `json:"ipfsApiPort,omitempty" bson:"ipfsApiPort,omitempty"`
	IPFSAPIURL  string `json:"ipfsApiUrl,omitempty" bson:"ipfsApiUrl,omitempty"`
	IPFSGateway string `json:"ipfsGateway,omitempty" bson:"ipfsGateway,omitempty"`
}

IPFSNode stores all relevant information about an additional node for uploads

func DecodeIPFSNodeRequest

func DecodeIPFSNodeRequest(w http.ResponseWriter, r *http.Request, ipfs IPFSNode) (IPFSNode, int)

DecodeIPFSNodeRequest decodes the api request into the passed object responds with decode error if occurs status 0 => ok || status 1 => error

func (*IPFSNode) Valid

func (s *IPFSNode) Valid() error

Valid checks whether the ipfs-node settings is valid or not

type Invite

type Invite struct {
	ID    primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	Token string             `json:"token,omitempty" bson:"token,omitempty"`
	Until int64              `json:"until,omitempty" bson:"until,omitempty"`
	Used  bool               `json:"used,omitempty" bson:"used,omitempty"`
}

Invite represents the database entry for the tokens

func (*Invite) FindID

func (i *Invite) FindID(db *mongo.Database) error

FindID selects an Invite with the given ID

func (*Invite) FindToken

func (i *Invite) FindToken(db *mongo.Database) error

FindToken selects an Invite with the given token

func (*Invite) Init

func (i *Invite) Init(db *mongo.Database, validity int) (*mongo.InsertOneResult, error)

Init inits a token and saves it into database. Default validity is 3 days

func (*Invite) Invalidate

func (i *Invite) Invalidate(db *mongo.Database) error

Invalidate verifies that the token is in the database and is valid. If the token is valid, it sets it's used state to used.

func (*Invite) Revalidate

func (i *Invite) Revalidate(db *mongo.Database, validity int) error

Revalidate sets the given token usage to false and adjusts the until date if needed

type Media

type Media struct {
	ID              primitive.ObjectID   `json:"id,omitempty" bson:"_id,omitempty"`
	Sha1            string               `json:"sha1,omitempty" bson:"sha1,omitempty"`
	ThumbnailSha1   string               `json:"thumbnailSha1,omitempty" bson:"thumbnailSha1,omitempty"`
	Title           string               `json:"title,omitempty" bson:"title,omitempty"`
	Description     string               `json:"description,omitempty" bson:"description,omitempty"`
	Comments        []*Comment           `json:"comments,omitempty" bson:"comments,omitempty"`
	Creator         string               `json:"creator,omitempty" bson:"creator,omitempty"`
	Events          []primitive.ObjectID `json:"events,omitempty" bson:"events,omitempty"`
	GroupIDs        []primitive.ObjectID `json:"groupIDs,omitempty" bson:"groupIDs,omitempty"`
	Timestamp       int64                `json:"timestamp,omitempty" bson:"timestamp,omitempty"`
	TimestampUpload int64                `json:"timestampUpload,omitempty" bson:"timestampUpload,omitempty"`
	URL             string               `json:"url,omitempty" bson:"url,omitempty"`
	URLThumb        string               `json:"urlThumb,omitempty" bson:"urlThumb,omitempty"`
	Type            string               `json:"type,omitempty" bson:"type,omitempty"`
	Format          string               `json:"format,omitempty" bson:"format,omitempty"`
	ContentType     string               `json:"contentType,omitempty" bson:"contentType,omitempty"`
	Tags            []string             `json:"tags,omitempty" bson:"tags,omitempty"`
	NodeIDs         []primitive.ObjectID `json:"nodeIDs,omitempty" bson:"nodeIDs,omitempty"`
	Users           []User               `json:"users,omitempty"`
	Groups          []UserGroup          `json:"groups,omitempty"`
	Nodes           []Node               `json:"nodes,omitempty"`
}

Media holds all information about the item

func DecodeMediaRequest

func DecodeMediaRequest(w http.ResponseWriter, r *http.Request, m Media) (Media, int)

DecodeMediaRequest decodes the api request into the passed object responds with decode error if occurs status 0 => ok || status 1 => error

func DecodeMediasRequest

func DecodeMediasRequest(w http.ResponseWriter, r *http.Request) ([]Media, int)

DecodeMediasRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

func GetAllMedia

func GetAllMedia(db *mongo.Database) ([]Media, error)

GetAllMedia selects all Media from the mongodb

func GetMediaByIDs

func GetMediaByIDs(db *mongo.Database, ids []primitive.ObjectID, permission bson.M) ([]Media, error)

GetMediaByIDs selects multiple Media Documents for the passed ids. verifies the reading permissions

func GetMediaPage

func GetMediaPage(db *mongo.Database, query MediaQuery, permission bson.M) ([]Media, error)

GetMediaPage returns the requested page after a specific id

func (*Media) AddMedia

func (m *Media) AddMedia(db *mongo.Database) (*mongo.InsertOneResult, error)

AddMedia creates the model in the mongodb

func (*Media) AddTag

func (m *Media) AddTag(db *mongo.Database, t string) error

AddTag adds a tag to the mapped tag set (ignores duplicates) Overrides the current model instance

func (*Media) AddTags

func (m *Media) AddTags(db *mongo.Database, tags []string) error

AddTags adds a tag array to the mapped tag set (ignores duplicates) Overrides the current model instance

func (*Media) AddUserGroups

func (m *Media) AddUserGroups(db *mongo.Database, ugIDs []primitive.ObjectID) error

AddUserGroups adds an array of primitive.ObjectID (of a usergroup) to the mapped usergroup set (ignores duplicates) Overrides the current model instance

func (*Media) DeleteMedia

func (m *Media) DeleteMedia(db *mongo.Database) (*mongo.DeleteResult, error)

DeleteMedia deletes the model from the mongodb

func (*Media) GetMedia

func (m *Media) GetMedia(db *mongo.Database, permission bson.M) error

GetMedia returns the specified entry from the mongodb

func (*Media) Save

func (m *Media) Save(db *mongo.Database) error

Save writes changes, made to the instance itself, to the database and overrides the instance with the return value from the database

func (*Media) UpdateMedia

func (m *Media) UpdateMedia(db *mongo.Database, um Media) error

UpdateMedia updates the record with the passed one Does NOT call the checkComments Method

type MediaEventMap

type MediaEventMap struct {
	Events   []Event  `json:"events,omitempty"`
	MediaIDs []string `json:"mediaIDs,omitempty"`
}

MediaEventMap is used to map an array of events to an array of media

func DecodeMediaEventMapRequest

func DecodeMediaEventMapRequest(w http.ResponseWriter, r *http.Request) (MediaEventMap, int)

DecodeMediaEventMapRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

type MediaGroupMap

type MediaGroupMap struct {
	Groups   []UserGroup `json:"groups,omitempty"`
	MediaIDs []string    `json:"mediaIDs,omitempty"`
}

MediaGroupMap is used to map an array of groups to an array of media

func DecodeMediaGroupMapRequest

func DecodeMediaGroupMapRequest(w http.ResponseWriter, r *http.Request) (MediaGroupMap, int)

DecodeMediaGroupMapRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

type MediaQuery

type MediaQuery struct {
	After  primitive.ObjectID
	Before primitive.ObjectID
	Event  primitive.ObjectID
	Filter string
	From   primitive.ObjectID
	Until  primitive.ObjectID
	Size   int
	ASC    int16
}

MediaQuery holds query options for the media api

func (*MediaQuery) IsValid

func (mq *MediaQuery) IsValid() error

IsValid validates that the passed query combination is allowed for filtering

type Node

type Node struct {
	ID      primitive.ObjectID   `json:"id,omitempty" bson:"_id,omitempty"`
	Title   string               `json:"title,omitempty" bson:"title,omitempty"`
	Creator string               `json:"creator,omitempty" bson:"creator,omitempty"`
	Type    string               `json:"type,omitempty" bson:"type,omitempty"`
	Secret  string               `json:"secret,omitempty" bson:"secret,omitempty"`
	Groups  []primitive.ObjectID `json:"groups,omitempty" bson:"groups,omitempty"`
	URL     string               `json:"url,omitempty" bson:"url,omitempty"`
}

Node holts the users and the information about the group

func GetAllNodes

func GetAllNodes(db *mongo.Database, permission bson.M) ([]Node, error)

GetAllNodes selects all Nodes from the mongodb

func (*Node) AddNode

func (e *Node) AddNode(db *mongo.Database) (*mongo.InsertOneResult, error)

AddNode creates the model in the mongodb

func (*Node) DeleteNode

func (e *Node) DeleteNode(db *mongo.Database) (*mongo.DeleteResult, error)

DeleteNode deletes the model from the mongodb

func (*Node) GetNode

func (e *Node) GetNode(db *mongo.Database, permission bson.M) error

GetNode returns the specified entry from the mongodb

func (*Node) UpdateNode

func (e *Node) UpdateNode(db *mongo.Database, ue Node, permission bson.M) (*mongo.UpdateResult, error)

UpdateNode updates the record with the passed one

func (*Node) VerifyNode

func (e *Node) VerifyNode(db *mongo.Database) error

VerifyNode verifies all mandatory fields of the specified node does not verify ID

type Session

type Session struct {
	User       User
	Token      string
	Expire     time.Time
	Usergroups []primitive.ObjectID
}

Session stores the user data, the token, the expiration of the session and the usergroups of the current user

func GetSession

func GetSession(token string) *Session

GetSession returns the session object for the passed token

func GetSessionByUser

func GetSessionByUser(user User) *Session

GetSessionByUser Returns the session for the passed user if exist

func GetSessionByUsername

func GetSessionByUsername(user string) *Session

GetSessionByUsername returns the session for the passed username if exist

func Remove

func Remove(ss []*Session, index int) []*Session

Remove deletes the item from the slice at the passed index

func RemoveToken

func RemoveToken(ss []*Session, token string) []*Session

RemoveToken finds the entry with the passed token and deletes it

func (*Session) IsValid

func (s *Session) IsValid() bool

IsValid returns whether the current session is valid or not

func (*Session) RenewToken

func (s *Session) RenewToken() string

RenewToken creates a new token and resets the expiry interval

type Settings

type Settings struct {
	IPFSNodes []*IPFSNode `json:"ipfsNodes,omitempty" bson:"ipfsNodes,omitempty"`
}

Settings stores all user related configurations

type Tag

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

Tag has a name and an ID for the reference

func DecodeTagRequest

func DecodeTagRequest(w http.ResponseWriter, r *http.Request, t Tag) (Tag, int)

DecodeTagRequest decodes the api request into the passed object responds with decode error if occurs status 0 => ok || status 1 => error

func DecodeTagsRequest

func DecodeTagsRequest(w http.ResponseWriter, r *http.Request, t []Tag) ([]Tag, int)

DecodeTagsRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

func GetTagsByKeyword

func GetTagsByKeyword(db *mongo.Database, keyword string, limit int64) ([]Tag, error)

GetTagsByKeyword returns the topmost tags that are starting with the keyword

func (*Tag) AddTag

func (t *Tag) AddTag(db *mongo.Database) (*mongo.InsertOneResult, error)

AddTag creates the model in the mongodb

func (*Tag) DeleteTag

func (t *Tag) DeleteTag(db *mongo.Database) (*mongo.DeleteResult, error)

DeleteTag deletes the model from the mongodb

func (*Tag) GetIDCreate

func (t *Tag) GetIDCreate(db *mongo.Database) error

GetIDCreate searches the database for the passed tag and adds the id to the current tag. It creates a new tag document if the passed tag was not find in the database

func (*Tag) GetTag

func (t *Tag) GetTag(db *mongo.Database) error

GetTag returns the specified entry from the mongodb

func (*Tag) GetTagByName

func (t *Tag) GetTagByName(db *mongo.Database) error

GetTagByName returns the specified entry from the mongodb

func (*Tag) UpdateTag

func (t *Tag) UpdateTag(db *mongo.Database, ut Tag) (*mongo.UpdateResult, error)

UpdateTag updates the record with the passed one

type TagEventMap

type TagEventMap struct {
	Events []Event  `json:"events,omitempty"`
	Tags   []string `json:"tags,omitempty"`
}

TagEventMap ist used to map an array of tags to an array of media

func DecodeTagEventMapRequest

func DecodeTagEventMapRequest(w http.ResponseWriter, r *http.Request) (TagEventMap, int)

DecodeTagEventMapRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

type TagMediaMap

type TagMediaMap struct {
	IDs  []string `json:"ids,omitempty"`
	Tags []string `json:"tags,omitempty"`
}

TagMediaMap ist used to map an array of tags to an array of media

func DecodeTagMediaMapRequest

func DecodeTagMediaMapRequest(w http.ResponseWriter, r *http.Request) (TagMediaMap, int)

DecodeTagMediaMapRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

type User

type User struct {
	Username  string    `json:"username" bson:"username"`
	FirstName string    `json:"firstName,omitempty" bson:"firstName,omitempty"`
	LastName  string    `json:"lastName,omitempty" bson:"lastName,omitempty"`
	Password  string    `json:"password,omitempty" bson:"password,omitempty"`
	URLImage  string    `json:"urlImage,omitempty" bson:"urlImage,omitempty"`
	Token     string    `json:"token,omitempty"`
	Settings  *Settings `json:"settings,omitempty" bson:"settings,omitempty"`
}

User contains all information about the user

func DecodeUserRequest

func DecodeUserRequest(w http.ResponseWriter, r *http.Request, u User) (User, int)

DecodeUserRequest decodes the api request into the passed object responds with decode error if occurs status 0 => ok || status 1 => error

func DecodeUsersRequest

func DecodeUsersRequest(w http.ResponseWriter, r *http.Request, u []User) ([]User, int)

DecodeUsersRequest decodes the api request into the passed user slice responds with decode error if occurs status 0 => ok || status 1 => error

func GetUsers

func GetUsers(db *mongo.Database, u []User) ([]User, error)

GetUsers returns a sclice of the specified users from the database

func (*User) AddIPFSNode

func (u *User) AddIPFSNode(ipfs IPFSNode) error

AddIPFSNode checks if the passed node struct is valid and adds it to the user

func (*User) CreateUser

func (u *User) CreateUser(db *mongo.Database) (*mongo.InsertOneResult, error)

CreateUser creates the user model in the mongodb

func (*User) DeleteUser

func (u *User) DeleteUser(db *mongo.Database) (*mongo.DeleteResult, error)

DeleteUser deletes the model from the mongodb

func (*User) Exists

func (u *User) Exists(db *mongo.Database) bool

Exists checks if the user can be selected from the database Assumes false if any error occurs

func (*User) GetUser

func (u *User) GetUser(db *mongo.Database) error

GetUser returns the specified entry from the mongodb

func (*User) Save

func (u *User) Save(db *mongo.Database) error

Save writes changes, made to the instance itself, to the database and overrides the instance with the return value from the database

func (*User) UpdateUser

func (u *User) UpdateUser(db *mongo.Database, uu User) (*mongo.UpdateResult, error)

UpdateUser updates the record with the passed one

type UserGroup

type UserGroup struct {
	ID      primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	Title   string             `json:"title,omitempty" bson:"title,omitempty"`
	Creator string             `json:"creator,omitempty" bson:"creator,omitempty"`
	Users   []string           `json:"users,omitempty" bson:"users,omitempty"`
}

UserGroup holts the users and the information about the group

func DecodeUserGroupRequest

func DecodeUserGroupRequest(w http.ResponseWriter, r *http.Request, ug UserGroup) (UserGroup, int)

DecodeUserGroupRequest decodes the api request into the passed object responds with decode error if occurs status 0 => ok || status 1 => error

func DecodeUserGroupsRequest

func DecodeUserGroupsRequest(w http.ResponseWriter, r *http.Request, ugs []UserGroup) ([]UserGroup, int)

DecodeUserGroupsRequest decodes the api request into the passed slice responds with decode error if occurs status 0 => ok || status 1 => error

func GetUserGroups

func GetUserGroups(db *mongo.Database, user string) ([]UserGroup, error)

GetUserGroups returns all groups the user is part of

func GetUserGroupsByIDs

func GetUserGroupsByIDs(db *mongo.Database, ids []primitive.ObjectID) ([]UserGroup, error)

GetUserGroupsByIDs returns a slice of usergroups, that are matching the given id slice

func GetUserGroupsByKeyword

func GetUserGroupsByKeyword(db *mongo.Database, keyword string, limit int64) ([]UserGroup, error)

GetUserGroupsByKeyword returns the topmost groups that are starting with the keyword

func (*UserGroup) AddUserGroup

func (ug *UserGroup) AddUserGroup(db *mongo.Database, skipVerify bool) (*mongo.InsertOneResult, error)

AddUserGroup creates the model in the mongodb

func (*UserGroup) DeleteUserGroup

func (ug *UserGroup) DeleteUserGroup(db *mongo.Database) (*mongo.DeleteResult, error)

DeleteUserGroup deletes the model from the mongodb

func (*UserGroup) GetUserGroup

func (ug *UserGroup) GetUserGroup(db *mongo.Database, permission bson.M) error

GetUserGroup returns the specified entry from the mongodb

func (*UserGroup) GetUserGroupAPI

func (ug *UserGroup) GetUserGroupAPI(w http.ResponseWriter, db *mongo.Database) int

GetUserGroupAPI handles possible errors during the select and writes Responses

func (*UserGroup) Save

func (ug *UserGroup) Save(db *mongo.Database, skipVerify bool) error

Save writes changes, made to the instance itself, to the database and overrides the instance with the return value from the database

func (*UserGroup) UpdateUserGroup

func (ug *UserGroup) UpdateUserGroup(db *mongo.Database, uug UserGroup, skipVerify bool) (*mongo.UpdateResult, error)

UpdateUserGroup updates the record with the passed one

func (*UserGroup) Verify

func (ug *UserGroup) Verify(db *mongo.Database) error

Verify tries to verify the usergroup object

Jump to

Keyboard shortcuts

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