core

package
v0.0.0-...-500edce Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxInt  = 1<<(UintSize-1) - 1
	MinInt  = -MaxInt - 1
	MaxUint = 1<<UintSize - 1
)
View Source
const UintSize = 32 << (^uint(0) >> 32 & 1) // 32 or 64

Variables

View Source
var (
	ErrFeatureDeactivated             = ApiError{1023, "This feature is currently not availiable"}
	ErrAccountNotConfirmed            = ApiError{1022, "Account hasn't been confirmed yet"}
	ErrAuthFailed                     = ApiError{1020, "User cannot be authenticated"}
	ErrRequestLimitExceeded           = ApiError{1019, "The client exceeded the request limit."}
	ErrInvalidFileType                = ApiError{1018, "File type not allowed"}
	ErrUnknownError                   = ApiError{1000, "An unexpected error occured."}
	ErrDataBase                       = ApiError{1008, "Some unexepected error occured within the datatbase."}
	ErrAccessDenied                   = ApiError{1006, "Access denied"}
	ErrRequireJSON                    = ApiError{1014, "JSON format required"}
	ErrAlreadyExists                  = ApiError{1021, "Ressource alread exists"}
	ErrUnsupportedMethod              = ApiError{1017, "Unsupported method"}
	ErrNothingChanged                 = ApiError{1007, "This action had no effect"}
	ErrLockedOut                      = ApiError{1005, "User Locked out"}
	ErrNoResultFromDB                 = ApiError{1004, "No rows returned"}
	ErrInvalidMessageType             = ApiError{1024, "This message type is not implemented."}
	ErrUserDoesNotExist               = ApiError{1001, "No such user"}
	ErrExpired                        = ApiError{1015, "Ressource expired"}
	ErrInvalidToken                   = ApiError{1016, "Invalid token"}
	ErrRessourceDoesNotExist          = ApiError{1013, "The requested ressource does not exist."}
	ErrConversationDoesNotExist       = ApiError{1009, "No such conversation"}
	ErrMessageTypeNotImplemented      = ApiError{1003, "This message type was not implemented"}
	ErrPasswordDoesNotMeetRequiremens = ApiError{1002, "The proposed password does not meet the requirements"}
)

Functions

func NewDataBaseError

func NewDataBaseError(err error) error

NewDataBaseError creates and returns a DataBaseError based on some error. Returns nil if the input is nil.

func UnwrapDatabaseError

func UnwrapDatabaseError(err error) error

UnwrapDatabaseError returns either the wrapped core.ErrDataBase if the passed in error is of type DataBaseError. Else it returns the passed in error as is.

Types

type ApiError

type ApiError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ApiError

func NewInvalidValueError

func NewInvalidValueError(field string) ApiError

NewInvalidValueError creates an ApiError with code 1012. It is made to indicate invalid values in requests.

func NewJSONFormatError

func NewJSONFormatError(message string) ApiError

NewJSONFormatError creates an ApiError with code 1010. It is made to indicate invalid json payloads in requests.

func NewPathFormatError

func NewPathFormatError(message string) ApiError

NewPathFormatError creates an ApiError with code 1011. It is made to indicate invalid values in urls.

func (ApiError) Error

func (e ApiError) Error() string

type CodeMessage

type CodeMessage struct {
	Message
	Code     string `json:"code"`
	Language string `json:"language"`
	Title    string `json:"title"`
	LockedBy int    `json:"lockedBy" pg:"lockedby"`
}

CodeMessage is derived from Message.

func (CodeMessage) GetDate

func (m CodeMessage) GetDate() time.Time

GetDate makes CodeMessage implement the Cronological interface.

func (CodeMessage) GetSequenceNumber

func (m CodeMessage) GetSequenceNumber() int

GetSequenceNumber makes CodeMessage implement the Sequencable interface.

type Conversation

type Conversation struct {
	Title           string `json:"title"`
	ID              int    `json:"id"`
	Repourl         string `json:"repoUrl"`
	NUnreadMessages int    `json:"nUnreadMessages" pg:"unreadmessagescount"`
}

Conversation

type ConversationRepo

type ConversationRepo interface {

	// Mutations
	DeleteConversation(id int) error
	CreateConversation(userID int, c Conversation, initialMembers []int) (Conversation, error)
	MarkAsInvited(userID, conversationID int) error
	MarkAsJoined(userID, conversationID int) (int, error)
	RemoveGroupAssociation(userID, conversationID int) error
	SetMetaDataOfConversation(conversation Conversation) error
	SetAsLeft(userID, conversationID int) error
	SetAdminState(userID, conversationID int, state bool) error

	// Queries
	FindInvitations(userid int) ([]Invitation, error)
	FindConversations() ([]Conversation, error)
	FindConversationForID(conversationID int) (Conversation, error)
	FindConversationsForUser(userid int) ([]Conversation, error)
	IsUserInConversation(userID, conversationID int) (bool, error)
	IsUserAdminOfConveration(userID, conversationID int) (bool, error)
	GetUsersInConversation(conversationID int) ([]UserInConversation, error)
	CountAdminsOfConversation(conversationID int) (int, error)
}

ConversationRepo contains all queries and mutations to work with conversations.

type Cronological

type Cronological interface {
	GetDate() time.Time
}

Cronological is used to enable chronological sorting

type DataBaseError

type DataBaseError struct {
	APIError ApiError
	Err      error
}

DataBaseError combines core.ErrDataBase with a generic error return from a database.

func (DataBaseError) Error

func (e DataBaseError) Error() string

func (DataBaseError) Unwrap

func (e DataBaseError) Unwrap() error

Unwrap retrieves the ErrDataBase instance inside any DataBaseError.

type Invitation

type Invitation struct {
	ConversationID    int    `json:"conversationId"`
	ConversationTitle string `json:"conversationTitle"`
	Recipient         int    `json:"recipient"`
}

Invitation

type MailingService

type MailingService interface {
	SendEmail(to, subject, body string) error
}

MailingService provides an simple interface to send emails.

type MediaMessage

type MediaMessage struct {
	Message
	Text  string        `json:"text"`
	Files []MediaObject `json:"files"`
}

MediaMessage is derived from Message.

func (MediaMessage) GetSequenceNumber

func (m MediaMessage) GetSequenceNumber() int

GetSequenceNumber makes MediaMessage implement the Sequencable interface.

type MediaObject

type MediaObject struct {
	ID       int             `json:"id"`
	MIMEType string          `json:"mimeType" pg:"filetype"`
	Name     string          `json:"name"`
	Meta     json.RawMessage `json:"meta"`
}

MediaObject represents a file.

type Message

type Message struct {
	ID             int         `json:"id"`
	Type           MessageType `json:"type"`
	Sentdate       time.Time   `json:"sentdate"`
	ProvisionaryID int         `json:"provisionaryId,omitempty"`
	Author         string      `json:"author"`
}

Message is the abstract base type of any message.

func (Message) GetDate

func (m Message) GetDate() time.Time

GetDate makes Message implement the Cronological interface.

func (Message) GetSequenceNumber

func (m Message) GetSequenceNumber() int

GetSequenceNumber makes Message implement the Sequencable interface.

type MessageRepo

type MessageRepo interface {

	// Mutations
	StoreTextMessage(conversation, user int, m TextMessage) (int, error)
	StoreCodeMessage(conversation, user int, m CodeMessage) (int, error)
	StoreMediaMessage(conversation, user int, m MediaMessage) (int, error)
	SetReadFlags(userid, conversationID int) error
	UpdateCode(messageID int, newCode, title, language string) error
	SetLockedSateForCodeMessage(messageID int, lockingUserID int) error
	CreateMediaObject(messageID int, name, fileType string) (int, error)
	SetMetaOfMediaMessage(id int, meta interface{}) error
	DeleteMessage(id int) error
	UpdateCompleteFlag(id int) error

	// Queries
	FindForConversation(conversationID, beforeInSequence, limit int) ([]interface{}, error)
	FindCodeMessagesForConversation(conversationID, beforeInSequence, limit int) ([]interface{}, error)
	FindTextMessagesForConversation(conversationID, beforeInSequence, limit int) ([]interface{}, error)
	FindMediaMessagesForConversation(conversationID, beforeInSequence, limit int) ([]interface{}, error)
	FindCodeMessageForID(messageID, conversationID int) (CodeMessage, error)
	FindTextMessageForID(messageID, conversationID int) (TextMessage, error)
	FindMediaMessageForID(messageID, conversationID int) (MediaMessage, error)
	FindMessageStubForConversation(conversationID, messageID int) (Message, error)
	FindAllProgrammingLanguages() ([]ProgrammingLanguage, error)
	FindMediaObjectForID(id, conversationID int) (MediaObject, error)
}

MessageRepo contains all queries and mutations to work with messages.

type MessageType

type MessageType int

MessageType describes an MessageType enum value.

const (
	// TextMessageType represents the type of a pure text message.
	TextMessageType MessageType = 0

	// CodeMessageType represents the type of a code message.
	CodeMessageType MessageType = 1

	// MediaMessageType represents a type of message that can hold various types of files.
	MediaMessageType MessageType = 2

	// UndefinedMesssageType represents a message of any kind.
	UndefinedMesssageType MessageType = -1
)

type ProgrammingLanguage

type ProgrammingLanguage struct {
	Name       string `json:"name"`
	IsRunnable bool   `pg:"IsRunnable" json:"isRunnable"`
}

ProgrammingLanguage is what is says. The field IsRunnable is for future use.

type Pusher

type Pusher interface {
	BroadcastToRoom(roomNumber int, payload interface{}, ctx context.Context)
	Unicast(ctx context.Context, userID int, payload interface{})
}

type RequestLimitExceededError

type RequestLimitExceededError struct {
	Err       ApiError
	RateLimit map[string]int
}

RequestLimitExceededError represents an error when a client is making to many requests to the server. The RateLimit map should contain the following fields. All the units are in seconds.

  • retryAfter
  • remaining
  • limit
  • resetAfter

func NewRequestLimitExceededError

func NewRequestLimitExceededError(retryAfter, remaining, limit, resetAfter int) RequestLimitExceededError

NewRequestLimitExceededError creates an new RequestLimitExceededError

func (RequestLimitExceededError) Error

type Sequencable

type Sequencable interface {
	GetSequenceNumber() int
}

type Size

type Size struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

type TextMessage

type TextMessage struct {
	Message
	Text string `json:"text"`
}

TextMessage is derived from Message.

func (TextMessage) GetDate

func (m TextMessage) GetDate() time.Time

GetDate makes TextMessage implement the Cronological interface.

func (TextMessage) GetSequenceNumber

func (m TextMessage) GetSequenceNumber() int

GetSequenceNumber makes TextMessage implement the Sequencable interface.

type User

type User struct {
	ID                  int       `pg:"id" json:"id"`
	Email               string    `pg:"email" json:"email,omitempty"`
	Name                string    `pg:"name" json:"name"`
	ConfirmationUUID    uuid.UUID `json:"-"`
	LockedOutSince      time.Time `json:"-"`
	FailedLoginAttempts int       `json:"-"`
	LastFailedLogin     time.Time `json:"-"`
	IsDeleted           bool      `pg:"isdeleted" json:"isDeleted"`
}

User contains the information of actual users that can sign in to the app.

type UserInConversation

type UserInConversation struct {
	User
	IsAdmin    bool `pg:"isadmin" json:"isAdmin"`
	ColorIndex int  `pg:"colorindex" json:"colorIndex"`
	HasJoined  bool `pg:"hasjoined" json:"hasJoined"`
	HasLeft    bool `pg:"hasleft" json:"hasLeft"`
}

UserInConversation represents the state of user as a member or ex-member of some conversation.

type UserRepo

type UserRepo interface {

	// Mutations
	LockUser(userID int) error
	UnlockUser(userID int) error
	SetConfirmationIDToNULL(token string) (string, error)
	SoftDeleteUser(userid int) error
	CreateUser(user User, password string) (User, error)
	IncrementFailedLoginAttempts(user string) error
	SetPassword(user int, newPassword string) error
	CreateRecoverID(emailAddress string) (uuid.UUID, error)
	UpdateOnlineState(userID int) error
	RecoverPassword(recoveryUUID uuid.UUID, password string) (string, error)

	// Queries
	CompareCredentials(userID int, password string) (int, error)
	GetUserForID(userID int) (User, error)
	GetUserForName(name string) (User, error)
	GetUsersForPrefix(prefix string, limit int) ([]User, error)
	SelectRecoveryTokenIssueDate(recoveryUUID uuid.UUID) (time.Time, error)

	// Internal
	DeleteUser(userid int) error
}

UserRepo contains all queries and mutations to work with users.

Directories

Path Synopsis
communication

Jump to

Keyboard shortcuts

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