schemas

package
v0.0.0-...-c763bc7 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyError

type BodyError struct {
	Message     string       `json:"message,omitempty"`
	FieldErrors []FieldError `json:"field_errors,omitempty"`
}

type FieldError

type FieldError struct {
	Name  string
	Error string
}

type Group

type Group struct {
	ID          int64     `json:"id,omitempty" gorm:"primaryKey"`
	Title       string    `json:"title,omitempty" gorm:"not null"`
	Description string    `json:"description,omitempty"`
	Status      int16     `json:"status" gorm:"default:0"`
	Password    string    `json:"password,omitempty"`
	MaxSize     int16     `json:"max_size,omitempty" gorm:"default:5"`
	CreatedAt   time.Time `json:"created_at,omitempty" gorm:"autoCreateTime"`
	OwnerID     int64     `json:"owner_id" gorm:"not null"`
	Members     []User    `json:"members" gorm:"many2many:joined_groups"`

	DB *gorm.DB `json:"-" gorm:"-"`
}

func (*Group) Create

func (g *Group) Create() error

Create adds a new group entry to the database.

func (*Group) InitDB

func (g *Group) InitDB() error

InitDB initializes the database object

func (*Group) IsFull

func (g *Group) IsFull() bool

IsFull checks if the group is full.

func (*Group) IsMember

func (g *Group) IsMember(uid int64) bool

IsMember checks if the user is a member of the group.

func (*Group) IsOpen

func (g *Group) IsOpen() bool

IsOpen checks if the group is open.

func (*Group) IsOwner

func (g *Group) IsOwner(uid int64) bool

IsOwner checks if the user is the owner of the group.

func (*Group) IsPrivate

func (g *Group) IsPrivate() bool

IsPrivate checks if the group is private.

func (*Group) List

func (g *Group) List() ([]Group, error)

List gets all of the group entries from the database.

func (*Group) Migrate

func (g *Group) Migrate() error

Creates the group table based on the struct model

func (*Group) RemoveMember

func (g *Group) RemoveMember(u User) error

RemoveMember removes a user from the group.

func (*Group) Retrieve

func (g *Group) Retrieve() error

Retrieve retrieves the group details from the database given its database ID.

func (*Group) RetrieveWithPassword

func (g *Group) RetrieveWithPassword() error

RetrieveWithPassword returns the group details from the database given its ID.

The returned Group includes the password value.

func (*Group) Update

func (g *Group) Update() error

Update updates a group entry.

func (*Group) ValidateForCreate

func (g *Group) ValidateForCreate() error

ValidateForCreate checks if the group is a valid new entry.

func (*Group) ValidatePassword

func (g *Group) ValidatePassword(pw string) error

ValidatePassword validates the group password

type TokenResponse

type TokenResponse struct {
	Token string `json:"token"`
	User  User   `json:"user"`
}

type User

type User struct {
	ID           int64     `json:"id" gorm:"primaryKey"`
	Username     string    `json:"username" gorm:"unique"`
	Password     string    `json:"password,omitempty"`
	CreatedAt    time.Time `json:"created_at" gorm:"autoCreateTime"`
	MyGroups     []Group   `json:"-" gorm:"foreignKey:OwnerID"`
	JoinedGroups []Group   `json:"-" gorm:"many2many:joined_groups"`

	DB *gorm.DB `json:"-" gorm:"-"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

BeforeCreate hashes the password of the user before adding it to the DB.

func (*User) Create

func (u *User) Create() error

Create adds a new user entry to the database.

func (*User) InitDB

func (u *User) InitDB() error

InitDB initializes the database object

func (*User) Migrate

func (u *User) Migrate() error

Migrate creates the user table based on the struct model

func (*User) Retrieve

func (u *User) Retrieve() error

Retrieve retrieves the user details given its database ID.

func (*User) RetrieveByUsername

func (u *User) RetrieveByUsername() error

RetrieveUserByUsername retrieves a user details given its username.

func (*User) ValidateForSignUp

func (u *User) ValidateForSignUp() error

ValidateForSignUp checks if the user struct is valid for sign up.

type ValidationError

type ValidationError struct {
	Message string
	Errors  []FieldError
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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