models

package
v0.0.0-...-9b6346a Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyGroupRequestScope

func VerifyGroupRequestScope(ctx context.Context, groupId string) (string, error)

VerifyGroupRequestScope inputs a Group http request and returns decrypted TokenData or an error

Types

type Blacklist

type Blacklist struct {
	Id           string    `json:"id,omitempty"`
	AuthToken    string    `json:"auth_token,omitempty"`
	LastModified time.Time `json:"last_modified,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
}

Blacklist is a root struct that is used to store the json encoded data for/from a mongodb blacklist doc.

type File

type File struct {
	Id           string    `json:"id,omitempty"`
	OwnerId      string    `json:"owner_id,omitempty"`
	OwnerType    string    `json:"owner_type,omitempty"`
	GridFSId     string    `json:"gridfs_id,omitempty"`
	BucketName   string    `json:"bucket_name,omitempty"`
	BucketType   string    `json:"bucket_type,omitempty"`
	Name         string    `json:"name,omitempty"`
	FileType     string    `json:"file_type,omitempty"`
	Size         int       `json:"size,omitempty"`
	LastModified time.Time `json:"last_modified,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
	DeletedAt    time.Time `json:"deleted_at,omitempty"`
}

File is a root struct that is used to store the json encoded data for/from a mongodb file doc.

func UsersToFiles

func UsersToFiles(users []*User) []*File

UsersToFiles converts an input slice of user to a slice of file

func (*File) BuildBucketName

func (g *File) BuildBucketName() error

BuildBucketName returns a current name for the bucket of a GridFS File

func (*File) BuildFilter

func (g *File) BuildFilter() (*File, error)

BuildFilter is a function that setups the base user struct during a File modification request

func (*File) BuildUpdate

func (g *File) BuildUpdate(cur *File)

BuildUpdate is a function that setups the base file struct during a file modification request

func (*File) CheckID

func (g *File) CheckID(chkId string) bool

CheckID determines whether a specified ID is set or not

func (*File) Validate

func (g *File) Validate(valCase string) (err error)

Validate a File for different scenarios such as creating new File, or updating a File

type FilesRes

type FilesRes struct {
	TotalCount int64   `json:"total_count"`
	TotalPages int64   `json:"total_pages"`
	Page       int64   `json:"page"`
	Size       int64   `json:"size"`
	HasMore    bool    `json:"has_more"`
	Files      []*File `json:"files"`
}

FilesRes Multiple Files in a paginated response

type Group

type Group struct {
	Id           string    `json:"id,omitempty"`
	Name         string    `json:"name,omitempty"`
	RootAdmin    bool      `json:"root_admin,omitempty"`
	LastModified time.Time `json:"last_modified,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
	DeletedAt    time.Time `json:"deleted_at,omitempty"`
}

Group is a root struct that is used to store the json encoded data for/from a mongodb group doc.

func LoadGroupCreateProto

func LoadGroupCreateProto(u *groupsService.CreateReq) *Group

LoadGroupCreateProto inputs a groupsService.CreateReq and returns a Group

func LoadGroupFindProto

func LoadGroupFindProto(u *groupsService.FindReq) *Group

LoadGroupFindProto inputs a groupsService.FindReq and returns a Group

func LoadGroupProto

func LoadGroupProto(u *groupsService.Group) *Group

LoadGroupProto inputs a groupsService and returns a Group

func LoadGroupUpdateProto

func LoadGroupUpdateProto(u *groupsService.UpdateReq) *Group

LoadGroupUpdateProto inputs a groupsService.UpdateReq and returns a Group

func (*Group) CheckID

func (g *Group) CheckID(chkId string) bool

CheckID determines whether a specified ID is set or not

func (*Group) ToProto

func (g *Group) ToProto() *groupsService.Group

ToProto Convert Group to proto

func (*Group) Validate

func (g *Group) Validate(valCase string) (err error)

Validate a Group for different scenarios such as loading TokenData, creating new Group, or updating a Group

type GroupTasks

type GroupTasks struct {
	Group *Group
	Tasks []*Task
}

GroupTasks is used for storing a Group record with it's associated Tasks

type GroupUsers

type GroupUsers struct {
	Group *Group
	Users []*User
}

GroupUsers is used for storing a Group record with it's associated Users

type GroupsRes

type GroupsRes struct {
	TotalCount int64    `json:"total_count"`
	TotalPages int64    `json:"total_pages"`
	Page       int64    `json:"page"`
	Size       int64    `json:"size"`
	HasMore    bool     `json:"has_more"`
	Groups     []*Group `json:"groups"`
}

GroupsRes Multiple Groups in a paginated response

func (*GroupsRes) ToProto

func (p *GroupsRes) ToProto() []*groupsService.Group

ToProto convert GroupsRes to proto

type InFile

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

InFile is used for streaming bytes into

func NewInFile

func NewInFile(name string) *InFile

NewInFile constructs an InFile

func (*InFile) Write

func (f *InFile) Write(chunk []byte) error

Write bytes unto an InFile

type PasswordUpdate

type PasswordUpdate struct {
	CurrentPassword string
	NewPassword     string
}

PasswordUpdate stores the structured data from a session token for use

func LoadPasswordUpdateProto

func LoadPasswordUpdateProto(u *authService.UpdatePasswordReq) *PasswordUpdate

LoadPasswordUpdateProto inputs an authService.LoginReq and returns a PasswordUpdate

func (*PasswordUpdate) Validate

func (r *PasswordUpdate) Validate() error

Validate a PasswordUpdate action

type Task

type Task struct {
	Id           string     `json:"id,omitempty"`
	Name         string     `json:"name,omitempty"`
	Status       TaskStatus `json:"status,omitempty"`
	Due          time.Time  `json:"due,omitempty"`
	Description  string     `json:"description,omitempty"`
	UserId       string     `json:"user_id,omitempty"`
	GroupId      string     `json:"group_id,omitempty"`
	LastModified time.Time  `json:"last_modified,omitempty"`
	CreatedAt    time.Time  `json:"created_at,omitempty"`
	DeletedAt    time.Time  `json:"deleted_at,omitempty"`
}

Task is a root struct that is used to store the json encoded data for/from a mongodb group doc.

func LoadTaskCreateProto

func LoadTaskCreateProto(u *tasksService.CreateReq) *Task

LoadTaskCreateProto inputs a tasksService.CreateReq and returns a Task

func LoadTaskFindProto

func LoadTaskFindProto(u *tasksService.FindReq) *Task

LoadTaskFindProto inputs a tasksService.FindReq and returns a Task

func LoadTaskProto

func LoadTaskProto(u *tasksService.Task) *Task

LoadTaskProto inputs a usersService and returns a Task

func LoadTaskUpdateProto

func LoadTaskUpdateProto(u *tasksService.UpdateReq) *Task

LoadTaskUpdateProto inputs a tasksService.UpdateReq and returns a Task

func (*Task) BuildUpdate

func (g *Task) BuildUpdate(cur *Task)

BuildUpdate is a function that setups the base task struct during a user modification request

func (*Task) CheckID

func (g *Task) CheckID(chkId string) bool

CheckID determines whether a specified ID is set or not

func (*Task) LoadScope

func (g *Task) LoadScope(scopeUser *User)

LoadScope scopes the Task struct

func (*Task) ToProto

func (g *Task) ToProto() *tasksService.Task

ToProto Convert Task to proto

func (*Task) Validate

func (g *Task) Validate(valCase string) (err error)

Validate a Group for different scenarios such as loading TokenData, creating new Group, or updating a Group

type TaskStatus

type TaskStatus int
const (
	UNSPECIFIED TaskStatus = iota
	NOT_STARTED
	IN_PROGRESS
	COMPLETED
)

type TasksRes

type TasksRes struct {
	TotalCount int64   `json:"total_count"`
	TotalPages int64   `json:"total_pages"`
	Page       int64   `json:"page"`
	Size       int64   `json:"size"`
	HasMore    bool    `json:"has_more"`
	Tasks      []*Task `json:"tasks"`
}

TasksRes Multiple Tasks in a paginated response

func (*TasksRes) ToProto

func (p *TasksRes) ToProto() []*tasksService.Task

ToProto convert TasksRes to proto

type TokenData

type TokenData struct {
	UserId    string
	Role      string
	RootAdmin bool
	GroupId   string
}

TokenData stores the structured data from a session token for use

func DecodeJWT

func DecodeJWT(curToken string) (*TokenData, error)

DecodeJWT is used to decode a JWT token

func InitUserToken

func InitUserToken(u *User) (*TokenData, error)

InitUserToken inputs a pointer to a user and returns TokenData

func LoadTokenFromContext

func LoadTokenFromContext(ctx context.Context) (*TokenData, error)

LoadTokenFromContext inputs a http request and returns decrypted TokenData or an error

func (*TokenData) AdminRouteRoleCheck

func (t *TokenData) AdminRouteRoleCheck() string

AdminRouteRoleCheck checks admin routes JWT tokens to ensure that a group admin does not break scope

func (*TokenData) CreateToken

func (t *TokenData) CreateToken(exp int64) (string, error)

CreateToken is used to create a new session JWT token

func (*TokenData) GetGroupsScope

func (t *TokenData) GetGroupsScope() *Group

GetGroupsScope returns a scoped Group ID filter based on token User role

func (*TokenData) GetUsersScope

func (t *TokenData) GetUsersScope(scopeType string) *User

GetUsersScope returns a scoped User ID filter based on token User role

func (*TokenData) ToUser

func (t *TokenData) ToUser() *User

ToUser creates a new User struct using the TokenData and returns a pointer to it

type User

type User struct {
	Id           string    `json:"id,omitempty"`
	Username     string    `json:"username,omitempty"`
	Password     string    `json:"password,omitempty"`
	FirstName    string    `json:"firstname,omitempty"`
	LastName     string    `json:"lastname,omitempty"`
	Email        string    `json:"email,omitempty"`
	Role         string    `json:"role,omitempty"`
	RootAdmin    bool      `json:"root_admin,omitempty"`
	GroupId      string    `json:"group_id,omitempty"`
	ImageId      string    `json:"image_id,omitempty"`
	LastModified time.Time `json:"last_modified,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
	DeletedAt    time.Time `json:"deleted_at,omitempty"`
}

User is a root struct that is used to store the json encoded data for/from a mongodb user doc.

func LoadLoginProto

func LoadLoginProto(u *authService.LoginReq) *User

LoadLoginProto inputs an authService.LoginReq and returns a User

func LoadRegisterProto

func LoadRegisterProto(u *authService.RegisterReq) *User

LoadRegisterProto inputs an authService.RegisterReq and returns a User

func LoadUserCreateProto

func LoadUserCreateProto(u *usersService.CreateReq) *User

LoadUserCreateProto inputs a usersService.CreateReq and returns a User

func LoadUserFindProto

func LoadUserFindProto(u *usersService.FindReq) *User

LoadUserFindProto inputs a usersService.FindReq and returns a User

func LoadUserProto

func LoadUserProto(u *usersService.User) *User

LoadUserProto inputs a usersService.User and returns a User

func LoadUserUpdateProto

func LoadUserUpdateProto(u *usersService.UpdateReq) *User

LoadUserUpdateProto inputs a usersService.UpdateReq and returns a User

func VerifyRequestScope

func VerifyRequestScope(ctx context.Context, scopeType string) (*User, error)

VerifyRequestScope inputs generic http requests and returns decrypted TokenData or an error

func VerifyUserRequestScope

func VerifyUserRequestScope(ctx context.Context, userId string, scopeType string) (*User, error)

VerifyUserRequestScope inputs User http request and returns decrypted TokenData or an error

func (*User) Authenticate

func (g *User) Authenticate(checkPassword string) error

Authenticate compares an input password with the hashed password stored in the User model

func (*User) BuildFilter

func (g *User) BuildFilter() (*User, error)

BuildFilter is a function that setups the base user struct during a user modification request

func (*User) BuildUpdate

func (g *User) BuildUpdate(curUser *User)

BuildUpdate is a function that setups the base user struct during a user modification request

func (*User) CheckID

func (g *User) CheckID(chkId string) bool

CheckID determines whether a specified ID is set or not

func (*User) HashPassword

func (g *User) HashPassword() error

HashPassword hashes a user password and associates it with the user struct

func (*User) LoadScope

func (g *User) LoadScope(scopeUser *User, valCase string)

LoadScope scopes the User struct

func (*User) ToAuthProto

func (g *User) ToAuthProto() *authService.User

ToAuthProto Convert User to auth proto

func (*User) ToProto

func (g *User) ToProto() *usersService.User

ToProto Convert User to proto

func (*User) Validate

func (g *User) Validate(valCase string) (err error)

Validate a User for different scenarios such as loading TokenData, creating new User, or updating a User

type UsersRes

type UsersRes struct {
	TotalCount int64   `json:"total_count"`
	TotalPages int64   `json:"total_pages"`
	Page       int64   `json:"page"`
	Size       int64   `json:"size"`
	HasMore    bool    `json:"has_more"`
	Users      []*User `json:"users"`
}

UsersRes Multiple Users in a paginated response

func (*UsersRes) ToProto

func (p *UsersRes) ToProto() []*usersService.User

ToProto convert UsersRes to proto

Jump to

Keyboard shortcuts

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