user

package
v0.0.0-...-8f9543d Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bit

type Bit bool

func (*Bit) Scan

func (b *Bit) Scan(src interface{}) error

type MariadbRepo

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

MariadbRepo holds a connection

func NewRepository

func NewRepository(context *gorm.DB) *MariadbRepo

NewRepository instansiates a repository obect

func (*MariadbRepo) Create

func (r *MariadbRepo) Create(user *User) (string, error)

Create creates a user

func (*MariadbRepo) Update

func (r *MariadbRepo) Update(user *User) error

Update updates a user

func (*MariadbRepo) UserByEmail

func (r *MariadbRepo) UserByEmail(email string) (*User, error)

UserByEmail get an user by its email

func (*MariadbRepo) UserById

func (r *MariadbRepo) UserById(id string) (*User, error)

UserById fetches a user by the userId

func (*MariadbRepo) UserByUsername

func (r *MariadbRepo) UserByUsername(username string) (*User, error)

UserByUsername gets a user by its username

func (*MariadbRepo) UserExists

func (r *MariadbRepo) UserExists(email string, username string) (string, error)

UserExists returns an userId if the user exists

type PrivacyLevel

type PrivacyLevel int

PrivacyLevel is a type that describes a users level of privacy

const (
	// ProtectedLevel describes a level where a user can be seen by anyone who has a flightlog login
	ProtectedLevel PrivacyLevel = 0
	// PrivateLevel describes a level where a user needs to grant access to those who wants access
	PrivateLevel PrivacyLevel = 1
	// PublicLevel describes a user that anyone can watch with or without login
	PublicLevel PrivacyLevel = 2
)

type Reader

type Reader interface {
	UserByEmail(email string) (*User, error)
	UserById(id string) (*User, error)
}

Reader describes read related actions for a user

type Repository

type Repository interface {
	Reader
	Writer
	// UserExists checks if there is any row with a matching email or username
	UserExists(email string, username string) (string, error)
	UserByUsername(username string) (*User, error)
}

type Service

type Service interface {
	Reader
	Writer
	Login(username string, email string, password string) (*User, error)
}

Service define user service layer

type User

type User struct {
	ID            string                `gorm:"primaryKey;column:id;size:64"`
	Givenname     string                `gorm:"column:givenname;size:64"`
	Familyname    string                `gorm:"column:familyname;size:64"`
	Email         string                `gorm:"column:email;size:320"`
	Active        Bit                   `gorm:"column:active"`
	Username      string                `gorm:"column:username;size:32"`
	Privacy       PrivacyLevel          `gorm:"column:privacylevel"`
	UpdatedAt     *time.Time            `gorm:"column:updatedat;type:time"`
	CreatedAt     *time.Time            `gorm:"column:createdat;type:time"`
	DeletedAt     *time.Time            `gorm:"column:deletedat;type:time"`
	FlyingDevices []device.FlyingDevice `gorm:"foreignKey:userId"`
}

User models a db user

func (User) TableName

func (User) TableName() string

type UserService

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

func NewUserService

func NewUserService(repo Repository) *UserService

func (*UserService) Create

func (u *UserService) Create(user *User) (string, error)

func (*UserService) Login

func (u *UserService) Login(username string, email string, password string) (*User, error)

func (*UserService) Update

func (u *UserService) Update(user *User) error

func (*UserService) UserByEmail

func (u *UserService) UserByEmail(email string) (*User, error)

func (*UserService) UserById

func (u *UserService) UserById(id string) (*User, error)

type Writer

type Writer interface {
	Create(user *User) (string, error)
	Update(user *User) error
}

Writer describes write related actions for a user

Jump to

Keyboard shortcuts

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