stor

package
v0.0.0-...-6d50a0b Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

The stor package manages the database storage of pubstore entities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GormDialector

func GormDialector(cnx string) gorm.Dialector

Types

type Author

type Author struct {
	gorm.Model
	Name string `json:"name" gorm:"uniqueIndex"`
}

func (*Author) BeforeSave

func (l *Author) BeforeSave(tx *gorm.DB) (err error)

type Category

type Category struct {
	gorm.Model
	Name string `json:"name" gorm:"uniqueIndex"`
}

func (*Category) BeforeSave

func (l *Category) BeforeSave(tx *gorm.DB) (err error)

type Language

type Language struct {
	gorm.Model
	Code string `json:"code" gorm:"size:2;uniqueIndex"`
}

func (*Language) BeforeSave

func (l *Language) BeforeSave(tx *gorm.DB) (err error)

type Publication

type Publication struct {
	gorm.Model
	UUID          string      `json:"uuid" validate:"omitempty,uuid4_rfc4122" gorm:"uniqueIndex"`
	Title         string      `json:"title" gorm:"index"`
	ContentType   string      `json:"content_type" gorm:"index"`
	DatePublished string      `json:"date_published"`
	Description   string      `json:"description"`
	CoverUrl      string      `json:"cover_url"`
	Language      []Language  `json:"language" gorm:"many2many:publication_language;"`
	Publisher     []Publisher `json:"publisher" gorm:"many2many:publication_publisher;"`
	Author        []Author    `json:"author" gorm:"many2many:publication_author;"`
	Category      []Category  `json:"category" gorm:"many2many:publication_category;"`
}

A Publication DatePublished is a string: we do not process its value as a dateTime (or a simpler date, which is more complex to validate)

func (*Publication) Validate

func (p *Publication) Validate() error

Validate checks required fields and values

type Publisher

type Publisher struct {
	gorm.Model
	Name string `json:"name" gorm:"uniqueIndex"`
}

func (*Publisher) BeforeSave

func (l *Publisher) BeforeSave(tx *gorm.DB) (err error)

type Store

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

Store defines a generic store with a gorm db

func Init

func Init(dsn string) (Store, error)

Init initializes the database

func (*Store) CountPublications

func (s *Store) CountPublications() (int64, error)

Count returns the publication count

func (*Store) CountUsers

func (s *Store) CountUsers() (int64, error)

CountUsers returns the user count

func (*Store) CreatePublication

func (s *Store) CreatePublication(publication *Publication) error

CreatePublication creates a new publication

func (*Store) CreateTransaction

func (s *Store) CreateTransaction(transaction *Transaction) error

CreateTransaction creates a new transaction

func (*Store) CreateUser

func (s *Store) CreateUser(user *User) error

CreateUser creates a new user

func (*Store) DeletePublication

func (s *Store) DeletePublication(publication *Publication) error

DeletePublication deletes a publication

func (*Store) DeleteTransaction

func (s *Store) DeleteTransaction(transaction *Transaction) error

DeleteTransaction deletes a transaction

func (*Store) DeleteUser

func (s *Store) DeleteUser(user *User) error

DeleteUser deletes a user

func (*Store) FindPublicationsByAuthor

func (s *Store) FindPublicationsByAuthor(author string, page int, pageSize int) ([]Publication, error)

FindPublicationsByAuthor retrieves publications by author

func (*Store) FindPublicationsByCategory

func (s *Store) FindPublicationsByCategory(category string, page int, pageSize int) ([]Publication, error)

FindPublicationsByCategory retrieves publications by category

func (*Store) FindPublicationsByLanguage

func (s *Store) FindPublicationsByLanguage(code string, page int, pageSize int) ([]Publication, error)

FindPublicationsByLanguage retrieves publications by language

func (*Store) FindPublicationsByPublisher

func (s *Store) FindPublicationsByPublisher(publisher string, page int, pageSize int) ([]Publication, error)

FindPublicationsByPublisher retrieves publications by publisher

func (*Store) FindPublicationsByTitle

func (s *Store) FindPublicationsByTitle(title string, page int, pageSize int) ([]Publication, error)

FindPublicationsByTitle retrieves publications by Title

func (*Store) FindPublicationsByType

func (s *Store) FindPublicationsByType(contentType string, page int, pageSize int) ([]Publication, error)

FindPublicationsByType retrieves publications by content type

func (*Store) FindTransactionsByUser

func (s *Store) FindTransactionsByUser(userID uint) (*[]Transaction, error)

FindTransactionsByUser retrieves the array to transactions made by a specific user

func (*Store) GetAuthors

func (s *Store) GetAuthors() ([]Author, error)

GetAuthors lists available authors

func (*Store) GetCategories

func (s *Store) GetCategories() ([]Category, error)

GetCategories lists available categories

func (*Store) GetLanguages

func (s *Store) GetLanguages() ([]Language, error)

GetLanguages lists available languages

func (*Store) GetPublication

func (s *Store) GetPublication(uuid string) (*Publication, error)

GetPublication returns a publication, found by uuid

func (*Store) GetPublishers

func (s *Store) GetPublishers() ([]Publisher, error)

GetPublishers lists available publishers

func (*Store) GetTransactionByLicence

func (s *Store) GetTransactionByLicence(licenseID string) (*Transaction, error)

GetTransactionByLicense retrieves a transaction using its licenseID

func (*Store) GetTransactionByUserAndPublication

func (s *Store) GetTransactionByUserAndPublication(userID, publicationID uint) (*Transaction, error)

GetTransactionByUserAndPublication retrieves a transaction using its userID and publicationID

func (*Store) GetUser

func (s *Store) GetUser(uuid string) (*User, error)

GetUser returns a user, found by uuid

func (*Store) GetUserByEmail

func (s *Store) GetUserByEmail(email string) (*User, error)

GetUserByEmail returns a user, found by email

func (*Store) GetUserBySession

func (s *Store) GetUserBySession(sessionId string) (*User, error)

GetUserBySession returns a user, found by session id

func (*Store) ListPublications

func (s *Store) ListPublications(page int, pageSize int) ([]Publication, error)

ListPublications retrieves all publications

func (*Store) ListUsers

func (s *Store) ListUsers(page, pageSize int) ([]User, error)

ListUsers lists users, with pagination

func (*Store) UpdatePublication

func (s *Store) UpdatePublication(publication *Publication) error

UpdatePublication updates a publication

func (*Store) UpdateTransaction

func (s *Store) UpdateTransaction(transaction *Transaction) error

UpdateTransaction updates a transaction

func (*Store) UpdateUser

func (s *Store) UpdateUser(user *User) error

UpdateUser updates a user

type Transaction

type Transaction struct {
	gorm.Model
	UserID        uint // implicit foreign key to the related user
	User          User
	PublicationID uint // implicit foreign key to the related publication
	Publication   Publication
	LicenceId     string
}

type User

type User struct {
	gorm.Model
	UUID        string `json:"uuid" validate:"omitempty,uuid4_rfc4122" gorm:"uniqueIndex"`
	Name        string `json:"name"`
	Email       string `json:"email" gorm:"index"`
	Password    string `json:"password" gorm:"-"`
	HPassword   string `json:"hpassword"`
	TextHint    string `json:"text_hint"`
	Passphrase  string `json:"passphrase" gorm:"-"`
	HPassphrase string `json:"hpassphrase"`
	SessionId   string `json:"-" gorm:"index"`
}

User defines the user entity

func (*User) BeforeCreate

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

BeforeCreate creates user uuid if missing

func (*User) BeforeSave

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

BeforeSave creates a hash of the user password and lcp passphrase. This applies only if the password and/or passphrase are set. Note: the clear password and passphrase are not saved.

func (*User) BeforeUpdate

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

BeforeUpdate checks the uuid

func (*User) Validate

func (u *User) Validate() error

Validate checks required fields and values

Jump to

Keyboard shortcuts

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