models

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLatestProductNumber

func GetLatestProductNumber(db *gorm.DB,
	documentTypeName, productName string) (int, error)

GetLatestProductNumber gets the latest document number for a product.

func ModelsToAutoMigrate

func ModelsToAutoMigrate() []interface{}

Types

type Document

type Document struct {
	gorm.Model

	// GoogleFileID is the Google Drive file ID of the document.
	GoogleFileID string `gorm:"index;not null;unique"`

	// Approvers is the list of users whose approval is requested for the
	// document.
	Approvers []*User `gorm:"many2many:document_reviews;"`

	// Contributors are users who have contributed to the document.
	Contributors []*User `gorm:"many2many:document_contributors;"`

	// CustomFields contains custom fields.
	CustomFields []*DocumentCustomField

	// DocumentCreatedAt is the time of document creation.
	DocumentCreatedAt time.Time

	// DocumentModifiedAt is the time the document was last modified.
	DocumentModifiedAt time.Time

	// DocumentNumber is a document number unique to each product/area. It
	// pairs with the product abbreviation to form a document identifier
	// (e.g., "TF-123").
	DocumentNumber int `gorm:"index:latest_product_number"`

	// DocumentType is the document type.
	DocumentType   DocumentType
	DocumentTypeID uint

	// DocumentFileRevision are the file revisions for the document.
	FileRevisions []DocumentFileRevision

	// Imported is true if the document was not created through the application.
	Imported bool

	// Locked is true if the document cannot be updated (may be in a bad state).
	Locked bool

	// Owner is the owner of the document.
	Owner   *User `gorm:"default:null;not null"`
	OwnerID *uint `gorm:"default:null"`

	// Product is the product or area that the document relates to.
	Product   Product
	ProductID uint `gorm:"index:latest_product_number"`

	// RelatedResources are the related resources for the document.
	RelatedResources []*DocumentRelatedResource

	// Status is the status of the document.
	Status DocumentStatus

	// ShareableAsDraft is true if the document can be shared in the WIP (draft)
	// status.
	ShareableAsDraft bool

	// Summary is a summary of the document.
	Summary *string

	// Title is the title of the document. It only contains the title, and not the
	// product abbreviation, document number, or document type.
	Title string
}

Document is a model for a document.

func (*Document) BeforeSave

func (d *Document) BeforeSave(tx *gorm.DB) error

BeforeSave is a hook used to find associations before saving.

func (*Document) Create

func (d *Document) Create(db *gorm.DB) error

Create creates a document in database db.

func (*Document) Delete added in v0.4.0

func (d *Document) Delete(db *gorm.DB) error

Delete deletes a document in database db.

func (*Document) Get

func (d *Document) Get(db *gorm.DB) error

Get gets a document from database db by Google file ID, and assigns it to the receiver.

func (*Document) GetProjects added in v0.4.0

func (d *Document) GetProjects(db *gorm.DB) ([]Project, error)

GetProjects gets all projects associated with document d.

func (*Document) GetRelatedResources added in v0.3.0

func (d *Document) GetRelatedResources(db *gorm.DB) (
	elrrs []DocumentRelatedResourceExternalLink,
	hdrrs []DocumentRelatedResourceHermesDocument,
	err error,
)

GetRelatedResources returns typed related resources for document d.

func (*Document) ReplaceRelatedResources added in v0.3.0

func (d *Document) ReplaceRelatedResources(
	db *gorm.DB,
	elrrs []DocumentRelatedResourceExternalLink,
	hdrrs []DocumentRelatedResourceHermesDocument,
) error

ReplaceRelatedResources replaces related resources for document d.

func (*Document) Upsert

func (d *Document) Upsert(db *gorm.DB) error

Upsert updates or inserts the receiver document into database db.

type DocumentCustomField

type DocumentCustomField struct {
	DocumentID                uint `gorm:"primaryKey"`
	DocumentTypeCustomFieldID uint `gorm:"primaryKey"`
	DocumentTypeCustomField   DocumentTypeCustomField
	// Value                     datatypes.JSON
	Value string
}

func UpsertStringDocumentCustomField added in v0.4.0

func UpsertStringDocumentCustomField(
	documentCustomFields []*DocumentCustomField,
	documentTypeName string,
	documentTypeCustomFieldName string,
	customFieldValue string,
) []*DocumentCustomField

UpsertStringDocumentCustomField upserts a string document custom field with the provided document type name (documentTypeName), document type custom field name (documentTypeCustomFieldName), and value (customFieldValue) into a document's custom fields (documentCustomFields), and returns the resulting custom field (pointer) slice. If the value is an empty string, the custom field will be removed from the result.

func UpsertStringSliceDocumentCustomField added in v0.4.0

func UpsertStringSliceDocumentCustomField(
	documentCustomFields []*DocumentCustomField,
	documentTypeName string,
	documentTypeCustomFieldName string,
	customFieldValue []string,
) ([]*DocumentCustomField, error)

UpsertStringSliceDocumentCustomField upserts a string slice document custom field with the provided document type name (documentTypeName), document type custom field name (documentTypeCustomFieldName), and value (customFieldValue) into a document's custom fields (documentCustomFields), and returns the resulting custom field (pointer) slice. If the value is an empty string slice, the custom field will be removed from the result.

func (*DocumentCustomField) BeforeSave

func (d *DocumentCustomField) BeforeSave(tx *gorm.DB) error

BeforeSave is a hook to find or create associations before saving.

func (*DocumentCustomField) Create added in v0.4.0

func (d *DocumentCustomField) Create(db *gorm.DB) error

func (*DocumentCustomField) Upsert

func (d *DocumentCustomField) Upsert(db *gorm.DB) error

type DocumentFileRevision added in v0.4.0

type DocumentFileRevision struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`

	Document   Document
	DocumentID uint `gorm:"primaryKey"`

	// GoogleDriveFileRevisionID is the ID of the Google Drive file revision.
	GoogleDriveFileRevisionID string `gorm:"primaryKey"`

	// Name is the name of the document file revision.
	Name string `gorm:"primaryKey"`
}

DocumentFileRevision is a model for a document's Google Drive file revisions.

func (*DocumentFileRevision) Create added in v0.4.0

func (fr *DocumentFileRevision) Create(db *gorm.DB) error

Create creates a file revision for a document. Required fields in the receiver:

  • Document ID or Google File ID
  • Google Drive file revision ID
  • Name of file revision

func (*DocumentFileRevision) Get added in v0.4.0

func (fr *DocumentFileRevision) Get(db *gorm.DB) error

type DocumentFileRevisions added in v0.4.0

type DocumentFileRevisions []DocumentFileRevision

DocumentFileRevisions is a slice of document file revisions.

func (*DocumentFileRevisions) Find added in v0.4.0

func (frs *DocumentFileRevisions) Find(db *gorm.DB, doc Document) error

Find finds all file revisions for a provided document, and assigns them to the receiver.

type DocumentRelatedResource added in v0.3.0

type DocumentRelatedResource struct {
	gorm.Model

	// Document is the document that the related resource is attached to.
	Document   Document
	DocumentID uint `gorm:"uniqueIndex:document_id_sort_order_unique"`

	// RelatedResourceID is the foreign key of the related resource, set by a Gorm
	// polymorphic relationship.
	RelatedResourceID uint `gorm:"default:null;not null"`

	// RelatedResourceType is the table for the related resource, set by a Gorm
	// polymorphic relationship.
	RelatedResourceType string `gorm:"default:null;not null"`

	// SortOrder is the relative order of the related resource in comparison to
	// all of the document's other related resources.
	SortOrder int `gorm:"default:null;not null;uniqueIndex:document_id_sort_order_unique"`
}

DocumentRelatedResource is a model for a document related resource.

type DocumentRelatedResourceExternalLink struct {
	gorm.Model

	RelatedResource DocumentRelatedResource `gorm:"polymorphic:RelatedResource"`

	Name string `gorm:"default:null;not null"`

	URL string `gorm:"default:null;not null"`
}

func (*DocumentRelatedResourceExternalLink) Create added in v0.3.0

func (*DocumentRelatedResourceExternalLink) Get added in v0.3.0

type DocumentRelatedResourceExternalLinks []DocumentRelatedResourceExternalLink

type DocumentRelatedResourceHermesDocument added in v0.3.0

type DocumentRelatedResourceHermesDocument struct {
	gorm.Model

	RelatedResource DocumentRelatedResource `gorm:"polymorphic:RelatedResource"`

	// Document is the target related document.
	Document   Document
	DocumentID uint
}

func (*DocumentRelatedResourceHermesDocument) Create added in v0.3.0

type DocumentReview

type DocumentReview struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`

	DocumentID uint `gorm:"primaryKey"`
	Document   Document
	UserID     uint `gorm:"primaryKey"`
	User       User
	Status     DocumentReviewStatus
}

func (*DocumentReview) BeforeSave

func (d *DocumentReview) BeforeSave(tx *gorm.DB) error

BeforeSave is a hook to find or create associations before saving.

func (*DocumentReview) Get

func (d *DocumentReview) Get(db *gorm.DB) error

Get gets the document review from database db, and assigns it to the receiver.

func (*DocumentReview) Update

func (d *DocumentReview) Update(db *gorm.DB) error

Update updates the document review in database db.

type DocumentReviewStatus

type DocumentReviewStatus int
const (
	UnspecifiedDocumentReviewStatus DocumentReviewStatus = iota
	ApprovedDocumentReviewStatus
	ChangesRequestedDocumentReviewStatus
)

type DocumentReviews

type DocumentReviews []DocumentReview

DocumentReviews is a slice of document reviews.

func (*DocumentReviews) Find

func (d *DocumentReviews) Find(db *gorm.DB, dr DocumentReview) error

Find finds all document reviews with the provided query, and assigns them to the receiver.

type DocumentStatus

type DocumentStatus int

DocumentStatus is the status of the document (e.g., "WIP", "In-Review", "Approved", "Obsolete").

const (
	UnspecifiedDocumentStatus DocumentStatus = iota
	WIPDocumentStatus
	InReviewDocumentStatus
	ApprovedDocumentStatus
	ObsoleteDocumentStatus
)

type DocumentType

type DocumentType struct {
	gorm.Model

	// Name is the name of the document type, generally an abbreviation.
	// Example: "RFC"
	Name string `gorm:"index;not null;unique"`

	// LongName is the longer name for the document type.
	// Example: "Request for Comments"
	LongName string `gorm:"default:null;not null"`

	// Description is the description of the document type.
	// Example: "Create a Request for Comments document to present a proposal to
	// colleagues for their review and feedback."
	Description string

	// FlightIcon is the name of the Helios flight icon.
	// From: https://helios.hashicorp.design/icons/library
	FlightIcon string

	// MoreInfoLinkText is the text for a "more info" link.
	// Example: "When should I create an RFC?"
	MoreInfoLinkText string

	// MoreInfoLinkURL is the URL for a "more info" link.
	MoreInfoLinkURL string

	// CustomFields contain custom fields that are specific to a particular
	// document type.
	CustomFields []DocumentTypeCustomField

	// Checks are document type checks, which require acknowledging a check box in
	// order to publish a document.
	Checks datatypes.JSON
}

DocumentType is a model for a type of document (e.g., "RFC", "PRD").

func (*DocumentType) FirstOrCreate

func (d *DocumentType) FirstOrCreate(db *gorm.DB) error

FirstOrCreate finds the first document type by name or creates a new record if it does not exist.

func (*DocumentType) Get

func (d *DocumentType) Get(db *gorm.DB) error

Get gets a document type from database db by document type name, and assigns it to the receiver.

func (*DocumentType) Upsert

func (d *DocumentType) Upsert(db *gorm.DB) error

Upsert updates or inserts the receiver into database db.

type DocumentTypeCustomField

type DocumentTypeCustomField struct {
	gorm.Model

	Name           string
	DocumentTypeID uint
	DocumentType   DocumentType
	ReadOnly       bool
	Type           DocumentTypeCustomFieldType
}

func (*DocumentTypeCustomField) Get

func (d *DocumentTypeCustomField) Get(db *gorm.DB) error

Get gets a document type custom field from database db by name and document type name, and assigns it to the receiver.

func (*DocumentTypeCustomField) Upsert

func (d *DocumentTypeCustomField) Upsert(db *gorm.DB) error

Upsert updates or inserts the receiver into database db.

type DocumentTypeCustomFieldType

type DocumentTypeCustomFieldType int
const (
	UnspecifiedDocumentTypeCustomFieldType DocumentTypeCustomFieldType = iota
	StringDocumentTypeCustomFieldType
	PersonDocumentTypeCustomFieldType
	PeopleDocumentTypeCustomFieldType
)

type DocumentTypes

type DocumentTypes []DocumentType

DocumentTypes is a slice of document types.

func (*DocumentTypes) GetAll

func (d *DocumentTypes) GetAll(db *gorm.DB) error

GetAll gets all document types from database db, and assigns them to the receiver.

type Documents

type Documents []Document

Documents is a slice of documents.

func (*Documents) Find

func (d *Documents) Find(
	db *gorm.DB, query interface{}, queryArgs ...interface{}) error

Find finds all documents from database db with the provided query, and assigns them to the receiver.

type IndexerFolder

type IndexerFolder struct {
	gorm.Model

	// GoogleDriveID is the Google Drive ID of the folder.
	GoogleDriveID string `gorm:"default:null;not null;uniqueIndex"`

	// LastIndexedAt is the time that the folder was last indexed.
	LastIndexedAt time.Time
}

IndexerFolder is a model for a indexer folder.

func (*IndexerFolder) Get

func (f *IndexerFolder) Get(db *gorm.DB) error

Get gets the indexer folder and assigns it to the receiver.

func (*IndexerFolder) Upsert

func (l *IndexerFolder) Upsert(db *gorm.DB) error

Upsert updates or inserts the receiver indexer folder into database db.

type IndexerMetadata

type IndexerMetadata struct {
	gorm.Model

	// LastFullIndexAt is the time that the indexer last completed a full index.
	LastFullIndexAt time.Time
}

Indexer is a model for indexer metadata.

func (*IndexerMetadata) Get

func (m *IndexerMetadata) Get(db *gorm.DB) error

Get gets the indexer metadata and assigns it to the receiver.

func (*IndexerMetadata) Upsert

func (m *IndexerMetadata) Upsert(db *gorm.DB) error

Upsert updates or inserts the indexer metadata.

type Product

type Product struct {
	gorm.Model

	// Name is the name of the product.
	Name string `gorm:"default:null;index;not null;type:citext;unique"`

	// Abbreviation is a short group of capitalized letters to represent the
	// product.
	Abbreviation string `gorm:"default:null;not null;type:citext;unique"`

	// UserSubscribers are the users that subscribed to this product.
	UserSubscribers []User `gorm:"many2many:user_product_subscriptions;"`
}

Product is a model for product data.

func (*Product) FirstOrCreate

func (p *Product) FirstOrCreate(db *gorm.DB) error

FirstOrCreate finds the first product by name or creates a record if it does not exist in database db.

func (*Product) Get

func (p *Product) Get(db *gorm.DB) error

Get gets a product from database db by name, and assigns it back to the receiver.

func (*Product) Upsert

func (p *Product) Upsert(db *gorm.DB) error

Upsert updates or inserts a product into database db.

type ProductLatestDocumentNumber

type ProductLatestDocumentNumber struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`

	DocumentType   DocumentType
	DocumentTypeID uint `gorm:"primaryKey"`
	Product        Product
	ProductID      uint `gorm:"primaryKey"`

	// LatestDocumentNumber is a the latest document number per product and
	// document type.
	LatestDocumentNumber int `gorm:"default:null;not null"`
}

ProductLatestDocumentNumber is a model for latest product document numbers.

func (*ProductLatestDocumentNumber) BeforeSave

func (p *ProductLatestDocumentNumber) BeforeSave(tx *gorm.DB) error

BeforeSave is a hook to find or create associations before saving.

func (*ProductLatestDocumentNumber) Get

Get gets the latest product number and assigns it to the receiver.

func (*ProductLatestDocumentNumber) Upsert

func (p *ProductLatestDocumentNumber) Upsert(db *gorm.DB) error

Upsert updates or inserts the receiver document into database db.

type Project added in v0.4.0

type Project struct {
	gorm.Model

	// Creator is the user that created the project.
	Creator   User
	CreatorID uint `gorm:"default:null;not null"`

	// Description is a description of the project.
	Description *string

	// JiraIssueID is the ID of the Jira issue associated with the project.
	JiraIssueID *string

	// ProjectCreatedAt is the time of project creation.
	ProjectCreatedAt time.Time `gorm:"default:null;not null"`

	// ProjectModifiedAt is the time the project was last modified.
	ProjectModifiedAt time.Time `gorm:"default:null;not null"`

	// RelatedResources are the related resources for the project.
	RelatedResources []*ProjectRelatedResource

	// Status is the status of the document.
	Status ProjectStatus `gorm:"default:null;not null"`

	// Title is the title of the project.
	Title string `gorm:"default:null;not null"`
}

Project is a model for a project.

func (*Project) Create added in v0.4.0

func (p *Project) Create(db *gorm.DB) error

Create creates a new project. The resulting project is saved back to the receiver.

func (*Project) Get added in v0.4.0

func (p *Project) Get(db *gorm.DB, id uint) error

Get gets a project by ID.

func (*Project) GetRelatedResources added in v0.4.0

func (p *Project) GetRelatedResources(db *gorm.DB) (
	elrrs []ProjectRelatedResourceExternalLink,
	hdrrs []ProjectRelatedResourceHermesDocument,
	err error,
)

GetRelatedResources returns typed related resources for project p.

func (*Project) ReplaceRelatedResources added in v0.4.0

func (p *Project) ReplaceRelatedResources(
	db *gorm.DB,
	elrrs []ProjectRelatedResourceExternalLink,
	hdrrs []ProjectRelatedResourceHermesDocument,
) error

ReplaceRelatedResources replaces related resources for project p.

func (*Project) Update added in v0.4.0

func (p *Project) Update(db *gorm.DB) error

Update updates a project. The resulting project is saved back to the receiver.

type ProjectRelatedResource added in v0.4.0

type ProjectRelatedResource struct {
	gorm.Model

	// Project is the project that the related resource is attached to.
	Project   Project
	ProjectID uint `gorm:"uniqueIndex:project_id_sort_order_unique"`

	// RelatedResourceID is the foreign key of the related resource, set by a Gorm
	// polymorphic relationship.
	RelatedResourceID uint `gorm:"default:null;not null"`

	// RelatedResourceType is the table for the related resource, set by a Gorm
	// polymorphic relationship.
	RelatedResourceType string `gorm:"default:null;not null"`

	// SortOrder is the relative order of the related resource in comparison to
	// all of the project's other related resources.
	SortOrder int `gorm:"default:null;not null;uniqueIndex:project_id_sort_order_unique"`
}

ProjectRelatedResource is a model for a project related resource.

type ProjectRelatedResourceExternalLink struct {
	gorm.Model

	RelatedResource ProjectRelatedResource `gorm:"polymorphic:RelatedResource"`

	Name string `gorm:"default:null;not null"`

	URL string `gorm:"default:null;not null"`
}

func (*ProjectRelatedResourceExternalLink) Create added in v0.4.0

func (*ProjectRelatedResourceExternalLink) Get added in v0.4.0

type ProjectRelatedResourceExternalLinks []ProjectRelatedResourceExternalLink

type ProjectRelatedResourceHermesDocument added in v0.4.0

type ProjectRelatedResourceHermesDocument struct {
	gorm.Model

	RelatedResource ProjectRelatedResource `gorm:"polymorphic:RelatedResource"`

	// Document is the target related Hermes document.
	Document   Document
	DocumentID uint
}

func (*ProjectRelatedResourceHermesDocument) Create added in v0.4.0

type ProjectStatus added in v0.4.0

type ProjectStatus int

ProjectStatus is the status of the project.

const (
	UnspecifiedProjectStatus ProjectStatus = iota
	ActiveProjectStatus
	CompletedProjectStatus
	ArchivedProjectStatus
)

func ParseProjectStatusString added in v0.4.0

func ParseProjectStatusString(s string) (ProjectStatus, bool)

func (ProjectStatus) String added in v0.4.0

func (s ProjectStatus) String() string

type RecentlyViewedDoc

type RecentlyViewedDoc struct {
	UserID     int `gorm:"primaryKey"`
	DocumentID int `gorm:"primaryKey"`
	ViewedAt   time.Time
}

type User

type User struct {
	gorm.Model

	// EmailAddress is the email address of the user.
	EmailAddress string `gorm:"default:null;index;not null;type:citext;unique"`

	// ProductSubscriptions are the products that have been subscribed to by the
	// user.
	ProductSubscriptions []Product `gorm:"many2many:user_product_subscriptions;"`

	// RecentlyViewedDocs are the documents recently viewed by the user.
	RecentlyViewedDocs []Document `gorm:"many2many:recently_viewed_docs;"`
}

User is a model for an application user.

func (*User) BeforeSave

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

BeforeSave is a hook to find or create associations before saving.

func (*User) FirstOrCreate

func (u *User) FirstOrCreate(db *gorm.DB) error

FirstOrCreate finds the first user by email address or creates a user record if it does not exist in database db. The result is saved back to the receiver.

func (*User) Get

func (u *User) Get(db *gorm.DB) error

Get gets a user from database db by email address, and assigns it to the receiver.

func (*User) Upsert

func (u *User) Upsert(db *gorm.DB) error

Upsert updates or inserts the receiver user into database db.

Jump to

Keyboard shortcuts

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