model

package
v0.0.0-...-613ab89 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("element not found in database")
	ErrConflict      = errors.New("element conflict in database")
	ErrMissingFields = errors.New("missing json fields")
	ErrNoNewEntries  = errors.New("no new entries")
)

Functions

This section is empty.

Types

type File

type File struct {
	ID          int        `json:"id"`
	Name        string     `json:"name"`
	SubmitterIP netip.Addr `json:"submitter_ip"`
	SubmitterID int        `json:"submitter_id"`
	IsUploaded  bool       `json:"is_uploaded"`
	ContentType string     `json:"content_type"`
	UploadDate  time.Time  `json:"upload_date"`
}

func (*File) IsCorrectlyInitialized

func (f *File) IsCorrectlyInitialized() error

type FileModel

type FileModel struct {
	DB PgxIface
	FileModelInterface
}

func (FileModel) Add

func (p FileModel) Add(ctx context.Context, item *File) error

func (FileModel) CheckIfExists

func (p FileModel) CheckIfExists(ctx context.Context, name string) (bool, error)

func (FileModel) Delete

func (p FileModel) Delete(ctx context.Context, name, userID string) (int, error)

func (FileModel) Get

func (p FileModel) Get(ctx context.Context, name string) (File, error)

func (FileModel) GetAll

func (p FileModel) GetAll(ctx context.Context, userID, pageID, limit int) ([]File, error)

GetAll returns all files for userID but without content. Now with pagination!

func (FileModel) GetEveryFile

func (p FileModel) GetEveryFile(ctx context.Context, pageID, limit int) ([]File, error)

func (FileModel) GetWithAuth

func (p FileModel) GetWithAuth(ctx context.Context, name, userID string) (File, error)

func (FileModel) PostUploadFileUpdate

func (p FileModel) PostUploadFileUpdate(ctx context.Context, userID int, name, contentType string) error

func (FileModel) UpdateContentType

func (p FileModel) UpdateContentType(ctx context.Context, name, contentType string) error

type FileModelInterface

type FileModelInterface interface {
	Add(ctx context.Context, p File) error
	SetContentFlag(ctx context.Context, name string) error
	Get(ctx context.Context, name string) (File, error)
	GetAll(ctx context.Context) ([]File, error)
	Delete(ctx context.Context, name string) error
}

type Models

type Models struct {
	Users UserModel
	Files FileModel
}

func NewModels

func NewModels(db PgxIface) Models

type PgxIface

type PgxIface interface {
	Begin(context.Context) (pgx.Tx, error)
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	Ping(context.Context) error
	Close()
}

type User

type User struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Email    string `json:"email"`
	Password string `json:"password"`
	IsAdmin  bool   `json:"is_admin"`
}

func (User) HasLoginCredentials

func (u User) HasLoginCredentials() error

func (User) IsCorrectlyInitialized

func (u User) IsCorrectlyInitialized() error

type UserModel

type UserModel struct {
	DB PgxIface
	UserModelInterface
}

func (UserModel) Add

func (m UserModel) Add(ctx context.Context, user User) error

func (UserModel) Authenticate

func (m UserModel) Authenticate(ctx context.Context, u User) (User, error)

Authenticate returns true if credentials correct.

func (UserModel) Delete

func (m UserModel) Delete(ctx context.Context, userID int) (int, error)

func (UserModel) Get

func (m UserModel) Get(ctx context.Context, userID int) (User, error)

Get returns user based on user ID.

func (UserModel) GetAll

func (m UserModel) GetAll(ctx context.Context) ([]User, error)

func (UserModel) Search

func (m UserModel) Search(ctx context.Context, username string) (User, error)

Search returns user based on username.

func (UserModel) Update

func (m UserModel) Update(ctx context.Context, userID int, u User) error

TODO partial update ?

func (UserModel) UpdateSelf

func (m UserModel) UpdateSelf(ctx context.Context, userID int, u User) error

UpdateSelf is the update query but you can't change your username

type UserModelInterface

type UserModelInterface interface {
	Add(ctx context.Context, u User) error
	Get(ctx context.Context, name string) (User, error)
	GetAll(ctx context.Context) ([]User, error)
	Delete(ctx context.Context, name string) error
	Update(ctx context.Context, name string, u User) error
	Authenticate(ctx context.Context, u User) (User, error)
}

Jump to

Keyboard shortcuts

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