Documentation ¶
Overview ¶
The stor package manages the storage of our entities.
Index ¶
Constants ¶
const ( STATUS_READY = "ready" STATUS_ACTIVE = "active" STATUS_REVOKED = "revoked" STATUS_RETURNED = "returned" STATUS_CANCELLED = "cancelled" STATUS_EXPIRED = "expired" EVENT_REGISTER = "register" EVENT_RENEW = "renew" EVENT_RETURN = "return" EVENT_REVOKE = "revoke" EVENT_CANCEL = "cancel" )
List of status values as strings
Variables ¶
This section is empty.
Functions ¶
func GormDialector ¶
Types ¶
type Event ¶
type Event struct { ID uint `json:"-" gorm:"primaryKey"` Timestamp time.Time `json:"timestamp"` Type string `json:"type"` DeviceName string `json:"name"` DeviceID string `json:"id" gorm:"index"` LicenseID string `json:"-" gorm:"index"` // implicit foreign key to the related license License LicenseInfo `json:"-" gorm:"references:UUID"` // the event belongs to the license }
Event data model we don't include the full gorm model here, has no update nor soft deletion occurs on events
type EventRepository ¶
type EventRepository interface { List(licenseID string) (*[]Event, error) GetRegisterByDevice(licenseID string, deviceID string) (*Event, error) Count(licenseID string) (int64, error) Get(id uint) (*Event, error) Create(e *Event) error Update(e *Event) error Delete(e *Event) error }
EventRepository interface, defining event operations
type LicenseInfo ¶
type LicenseInfo struct { gorm.Model Updated *time.Time `json:"updated,omitempty"` // see comment above UUID string `json:"uuid" validate:"required,uuid" gorm:"uniqueIndex"` Provider string `json:"provider" validate:"required,url"` UserID string `json:"user_id,omitempty" validate:"required" gorm:"index"` Start *time.Time `json:"start,omitempty"` End *time.Time `json:"end,omitempty"` MaxEnd *time.Time `json:"max_end,omitempty"` Copy int32 `json:"copy,omitempty"` Print int32 `json:"print,omitempty"` Status string `json:"status" validate:"oneof=ready active expired cancelled revoked" gorm:"index"` StatusUpdated *time.Time `json:"status_updated,omitempty"` DeviceCount int `json:"device_count"` PublicationID string `json:"publication_id" validate:"required,uuid"` // implicit foreign key to the related publication Publication Publication `gorm:"references:UUID" validate:"-"` // the license belongs to the publication }
LicenseInfo data model Note: the date of issue of the license is handled by the gorm model. but the license is not logically updated when a device registers, therefore we keep the Updated property, which must be maintained manually.
func (*LicenseInfo) Validate ¶
func (l *LicenseInfo) Validate() error
Validate checks required fields and values
type LicenseRepository ¶
type LicenseRepository interface { ListAll() (*[]LicenseInfo, error) List(pageNum, pageSize int) (*[]LicenseInfo, error) FindByUser(userID string) (*[]LicenseInfo, error) FindByPublication(publicationID string) (*[]LicenseInfo, error) FindByStatus(status string) (*[]LicenseInfo, error) FindByDeviceCount(min int, max int) (*[]LicenseInfo, error) Count() (int64, error) Get(uuid string) (*LicenseInfo, error) Create(p *LicenseInfo) error Update(p *LicenseInfo) error Delete(p *LicenseInfo) error }
LicenseRepository interface, defining license operations
type Publication ¶
type Publication struct { gorm.Model UUID string `json:"uuid" validate:"required,uuid4_rfc4122" gorm:"uniqueIndex"` Title string `json:"title,omitempty"` EncryptionKey []byte `json:"encryption_key"` Location string `json:"location" validate:"required,url"` ContentType string `json:"content_type"` Size uint32 `json:"size"` Checksum string `json:"checksum" validate:"required,base64"` }
Publication data model
func (*Publication) Validate ¶
func (p *Publication) Validate() error
Validate checks required fields and values
type PublicationRepository ¶
type PublicationRepository interface { ListAll() (*[]Publication, error) List(pageNum, pageSize int) (*[]Publication, error) FindByType(contentType string) (*[]Publication, error) Count() (int64, error) Get(uuid string) (*Publication, error) Create(p *Publication) error Update(p *Publication) error Delete(p *Publication) error }
PublicationRepository interface, defining publication operations
type Store ¶
type Store interface { Publication() PublicationRepository License() LicenseRepository Event() EventRepository }
Store interface, giving access to specialized interfaces