Documentation ¶
Overview ¶
The stor package manages the database storage of pubstore entities.
Index ¶
- func GormDialector(cnx string) gorm.Dialector
- type Author
- type Category
- type Language
- type Publication
- type Publisher
- type Store
- func (s *Store) CountPublications() (int64, error)
- func (s *Store) CountUsers() (int64, error)
- func (s *Store) CreatePublication(publication *Publication) error
- func (s *Store) CreateTransaction(transaction *Transaction) error
- func (s *Store) CreateUser(user *User) error
- func (s *Store) DeletePublication(publication *Publication) error
- func (s *Store) DeleteTransaction(transaction *Transaction) error
- func (s *Store) DeleteUser(user *User) error
- func (s *Store) FindPublicationsByAuthor(author string, page int, pageSize int) ([]Publication, error)
- func (s *Store) FindPublicationsByCategory(category string, page int, pageSize int) ([]Publication, error)
- func (s *Store) FindPublicationsByLanguage(code string, page int, pageSize int) ([]Publication, error)
- func (s *Store) FindPublicationsByPublisher(publisher string, page int, pageSize int) ([]Publication, error)
- func (s *Store) FindPublicationsByTitle(title string, page int, pageSize int) ([]Publication, error)
- func (s *Store) FindPublicationsByType(contentType string, page int, pageSize int) ([]Publication, error)
- func (s *Store) FindTransactionsByUser(userID uint) (*[]Transaction, error)
- func (s *Store) GetAuthors() ([]Author, error)
- func (s *Store) GetCategories() ([]Category, error)
- func (s *Store) GetLanguages() ([]Language, error)
- func (s *Store) GetPublication(uuid string) (*Publication, error)
- func (s *Store) GetPublishers() ([]Publisher, error)
- func (s *Store) GetTransactionByLicence(licenseID string) (*Transaction, error)
- func (s *Store) GetTransactionByUserAndPublication(userID, publicationID uint) (*Transaction, error)
- func (s *Store) GetUser(uuid string) (*User, error)
- func (s *Store) GetUserByEmail(email string) (*User, error)
- func (s *Store) GetUserBySession(sessionId string) (*User, error)
- func (s *Store) ListPublications(page int, pageSize int) ([]Publication, error)
- func (s *Store) ListUsers(page, pageSize int) ([]User, error)
- func (s *Store) UpdatePublication(publication *Publication) error
- func (s *Store) UpdateTransaction(transaction *Transaction) error
- func (s *Store) UpdateUser(user *User) error
- type Transaction
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GormDialector ¶
Types ¶
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 Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store defines a generic store with a gorm db
func (*Store) CountPublications ¶
Count returns the publication count
func (*Store) CountUsers ¶
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 ¶
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) 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 ¶
GetAuthors lists available authors
func (*Store) GetCategories ¶
GetCategories lists available categories
func (*Store) GetLanguages ¶
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 ¶
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) GetUserByEmail ¶
GetUserByEmail returns a user, found by email
func (*Store) GetUserBySession ¶
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) 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
type Transaction ¶
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 ¶
BeforeCreate creates user uuid if missing
func (*User) BeforeSave ¶
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 ¶
BeforeUpdate checks the uuid