db

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	New        ProjectState = "New"
	Upcoming   ProjectState = "Upcoming"
	Pending    ProjectState = "Pending"
	NotStarted ProjectState = "Not Started"
	Draft      ProjectState = "Draft"
	Active     ProjectState = "Active"
	Priority   ProjectState = "Priority"
	Canceld    ProjectState = "Canceled"
	Onhold     ProjectState = "On-Hold"
	Archived   ProjectState = "Archived"

	Concept     RevisionState = "Concept"
	Underreview RevisionState = "Under Review"
	Released    RevisionState = "Released"
	Inwork      RevisionState = "In-Work"
	Depreciated RevisionState = "Depreciated"

	Lot       TracebilityState = "Lot"
	LotSerial TracebilityState = "Lot and Serial"
	Serial    TracebilityState = "Serial"
	NotTaced  TracebilityState = "Not-Traced"

	D_gmm3        DensityUnit = "Gram / mm^3"
	D_gcm3        DensityUnit = "Gram / cm^3"
	D_kgm3        DensityUnit = "Kilo Gram / m^3"
	D_tonnem3     DensityUnit = "Tonne / m^3"
	D_metrictonm3 DensityUnit = "Metric Ton / m^3" // equal to tonne
	D_poundft3    DensityUnit = "Pound / Ft^3"
	D_poundinch3  DensityUnit = "Pound / inch^3"

	V_mm3   VolumeUnit = "Cubic mm [mm^3]"
	V_cm3   VolumeUnit = "Cubic cm [cm^3]"
	V_m3    VolumeUnit = "Cubic m [m^3]"
	V_litre VolumeUnit = "Litre"
	V_ft3   VolumeUnit = "Cubic ft [Ft^3]"
	V_inch3 VolumeUnit = "Cubic inch [Inch^3]"

	W_g         WeightUnit = "Gram [g]"
	W_kg        WeightUnit = "Kilo Gram [kg]"
	W_tonne     WeightUnit = "Tonne [t]"
	W_metricton WeightUnit = "Metric Ton" // equal to tonne
	W_pound     WeightUnit = "Pound [p]"
	W_slug      WeightUnit = "Slug"

	A_mm2   AreaUnit = "Square mm [mm^2]"
	A_cm2   AreaUnit = "Square cm [cm^2]"
	A_m2    AreaUnit = "Square m [m^2]"
	A_ft2   AreaUnit = "Square ft [Ft^2]"
	A_inch2 AreaUnit = "Square inch [Inch^2]"
)

Variables

View Source
var ErrUserNotFound = errors.New("user not found")
View Source
var Sessions = map[string]Session{}

Functions

func CreateNumber

func CreateNumber(number string, ndigits *int) (string, error)

Create new Project number number is only added when it has a value. CreateNumber generates a new project number based on the last current number. number: Last current number as a string, including leading zeros. ndigits: Number of digits for the new number length. If -1, the length is just the length of the number.

func GetAvailableRoles added in v0.1.3

func GetAvailableRoles() []string

GetAvailableRoles returns a list of roles

func InitDB

func InitDB() (*gorm.DB, error)

InitDB loads configuration and initializes the database

Types

type AccountStatus added in v0.1.3

type AccountStatus string
const (
	StatusActive    AccountStatus = "active"
	StatusDisabled  AccountStatus = "disabled"
	StatusLocked    AccountStatus = "locked"
	StatusPending   AccountStatus = "pending"
	StatusSuspended AccountStatus = "suspended"
	StatusExpired   AccountStatus = "expired"
	StatusDeleted   AccountStatus = "deleted"
	StatusInvited   AccountStatus = "invited"
)

type AreaUnit

type AreaUnit string

type Base

type Base struct {
	ID        uint `gorm:"primaryKey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Base struct to embed in other models

type Claims added in v0.1.3

type Claims struct {
	Role string `json:"role"`
	jwt.StandardClaims
}

type DensityUnit

type DensityUnit string

type Document

type Document struct {
}

Document related

type FileSystem

type FileSystem struct{}

File System related Class

func (*FileSystem) CreateFileIdx

func (fs *FileSystem) CreateFileIdx()

Create file copy

func (*FileSystem) CreateFolder

func (fs *FileSystem) CreateFolder()

Create new folder

func (*FileSystem) Init

func (fs *FileSystem) Init()

type Item

type Item struct {
	gorm.Model
	ID       uint   `gorm:"primaryKey"`
	ItemName string `gorm:"size:100"`
	// number          int
	Project         string
	Path            string
	Name            string
	Description     string
	FullDescription string
}

Item represents the items table.

func (*Item) AddItemImage

func (i *Item) AddItemImage()

Update existing item

func (*Item) RemoveItem

func (i *Item) RemoveItem()

Remove existing item

func (*Item) UpdateItem

func (i *Item) UpdateItem()

Update existing item

type Model

type Model struct {
}

Model related

func (Model) CreateModel

func (m Model) CreateModel()

Create new model

func (Model) GetVersion

func (m Model) GetVersion()

Get model that is not latest version

func (Model) RemoveModel

func (m Model) RemoveModel()

Remove existing model

func (Model) UpdateModel

func (m Model) UpdateModel()

Update existing model

type OwnerStates

type OwnerStates struct {
}

Item / Model / Document Ownership states

func (OwnerStates) CheckIn

func (o OwnerStates) CheckIn()

Check in Items, Models, Documents

func (OwnerStates) CheckInCheckOut

func (o OwnerStates) CheckInCheckOut()

Check in Items, Models, Documents

func (OwnerStates) CheckOut

func (o OwnerStates) CheckOut()

Check in Items, Models, Documents

type PdmDocument

type PdmDocument struct {
	Base
	DocumentNumber          int    // Or string?
	DocumentName            string `gorm:"type:varchar(32)"`
	DocumentDescription     string `gorm:"type:varchar(32)"`
	DocumentFullDescription string
	DocumentFilename        string `gorm:"type:varchar(253);not null"`
	DocumentExt             string `gorm:"type:varchar(253);not null"`

	UserID uint    `gorm:"foreignKey:UserID"`
	User   PdmUser `gorm:"foreignKey:UserID"`
	ItemID uint    `gorm:"foreignKey:ItemID"`
	Item   PdmItem `gorm:"foreignKey:ItemID"`
}

PdmDocument represents the documents table

type PdmHistory

type PdmHistory struct {
	Base
	HistoryDateCreated    *time.Time
	HistoryCreatedBy      string
	HistoryDateLastEdit   *time.Time
	HistoryLastEditBy     string
	HistoryCheckedOutBy   string
	HistoryRevisionState  string // Enum can be defined later
	HistoryRevisionNumber int
	HistoryStoredNumber   int
}

PdmHistory represents the history table

type PdmItem

type PdmItem struct {
	Base
	ItemNumber            string `gorm:"type:varchar(16)"`
	ItemName              string `gorm:"type:varchar(32)"`
	ItemDescription       string `gorm:"type:varchar(32)"`
	ItemFullDescription   string
	ItemNumberLinkedFiles int
	ItemPath              string `gorm:"not null"`
	ItemPreview           []byte // For LargeBinary

	UserID uint
	User   PdmUser

	ProjectID uint          `gorm:"foreignKey:ProjectID"`
	Models    []PdmModel    `gorm:"foreignKey:ItemID"`
	Documents []PdmDocument `gorm:"foreignKey:ItemID"`
}

PdmItem represents the items table

type PdmManufacturer

type PdmManufacturer struct {
	Base
	ManufacturerName string      `gorm:"type:varchar(32)"`
	PurchasingID     uint        `gorm:"foreignKey:PurchasingID"`
	Purchasing       PdmPurchase `gorm:"foreignKey:PurchasingID"`
}

PdmManufacturer represents the manufacturers table

type PdmMaterial

type PdmMaterial struct {
	Base
	MaterialName            string `gorm:"type:varchar(32)"`
	MaterialFinish          string `gorm:"type:varchar(32)"`
	MaterialDensity         float64
	MaterialDensityUnit     string // Enum can be defined later
	MaterialVolume          float64
	MaterialVolumeUnit      string // Enum can be defined later
	MaterialWeight          float64
	MaterialWeightUnit      string // Enum can be defined later
	MaterialSurfaceArea     float64
	MaterialSurfaceAreaUnit string // Enum can be defined later
}

PdmMaterial represents the materials table

type PdmModel

type PdmModel struct {
	Base
	ModelNumber          int
	ModelName            string `gorm:"type:varchar(32)"`
	ModelDescription     string `gorm:"type:varchar(32)"`
	ModelFullDescription string
	ModelFilename        string `gorm:"type:varchar(253);not null"`
	ModelExt             string `gorm:"type:varchar(253);not null"`
	ModelPreview         []byte

	UserID uint
	User   PdmUser

	ItemID uint
	Item   PdmItem

	MaterialID uint
	Material   PdmMaterial `gorm:"foreignKey:MaterialID;references:ID"`
}

PdmModel represents the models table

type PdmProject

type PdmProject struct {
	Base
	ProjectNumber     string `gorm:"type:varchar(16);not null"`
	ProjectName       string `gorm:"type:varchar(32)"`
	ProjectStatus     string // Enum type can be defined later
	ProjectDateStart  *time.Time
	ProjectDateFinish *time.Time
	ProjectPath       string

	Users []*PdmUser `gorm:"many2many:user_project_link"`
}

PdmProject represents the projects table

type PdmProjectItemLink struct {
	ProjectID uint `gorm:"primaryKey;autoIncrement:false"`
	ItemID    uint `gorm:"primaryKey;autoIncrement:false"`
}

PdmProjectItemLink is the association table for projects and items

type PdmPurchase

type PdmPurchase struct {
	Base
	PurchasingSource       bool
	PurchasingTraceability string // Enum can be defined later

	ItemID         uint              `gorm:"foreignKey:ItemID"`
	Item           PdmItem           `gorm:"foreignKey:ItemID"`
	ManufacturerID uint              `gorm:"foreignKey:ManufacturerID"`
	Manufacturers  []PdmManufacturer `gorm:"foreignKey:ManufacturerID"`
	VendorID       uint              `gorm:"foreignKey:VendorID"`
	Vendors        []PdmVendor       `gorm:"foreignKey:VendorID"`
}

PdmPurchase represents the purchasing table

type PdmUser

type PdmUser struct {
	Base

	LoginName          string         `gorm:"column:login_name;type:varchar(30);not null;uniqueIndex"`
	FullName           string         `gorm:"type:varchar(61)"`
	PasswordHash       string         `gorm:"type:varchar(60);not null"`
	MustChangePassword bool           `gorm:"default:true"`
	FirstName          string         `gorm:"type:varchar(30)"`
	LastName           string         `gorm:"type:varchar(30)"`
	DateOfBirth        time.Time      `gorm:"type:date"`
	Sex                string         `gorm:"type:varchar(10)"` // "male", "female", or "x"
	EmailAddress       string         `gorm:"type:varchar(255);not null;uniqueIndex"`
	PhoneNumber        string         `gorm:"type:varchar(20)"`
	Department         string         `gorm:"type:varchar(30)"`
	PhotoPath          string         `gorm:"type:varchar(255)"`
	AccountStatus      string         `gorm:"type:varchar(20);default:'active'"`
	Roles              pq.StringArray `gorm:"type:text[]"`
}

func (*PdmUser) HasAllRoles added in v0.1.3

func (u *PdmUser) HasAllRoles(roles []string) bool

func (*PdmUser) HasAnyPermission added in v0.1.3

func (u *PdmUser) HasAnyPermission(perms []RBAC) bool

HasAnyPermission checks if the user has at least one of the given permissions.

func (*PdmUser) HasAnyRole added in v0.1.3

func (u *PdmUser) HasAnyRole(roles []string) bool

Check whether user has all the roles

func (*PdmUser) HasPermission added in v0.1.3

func (u *PdmUser) HasPermission(permission RBAC) bool

HasPermission checks if the user has the given RBAC permission.

func (*PdmUser) HasRole added in v0.1.3

func (u *PdmUser) HasRole(role string) bool

Check whether user has a role

type PdmUserProjectLink struct {
	UserID    uint `gorm:"primaryKey;autoIncrement:false"`
	ProjectID uint `gorm:"primaryKey;autoIncrement:false"`
}

PdmUserProjectLink is the association table for users and projects

type PdmUserRoleLink struct {
	UserID uint `gorm:"primaryKey;autoIncrement:false"`
	RoleID uint `gorm:"primaryKey;autoIncrement:false"`
}

PdmUserRoleLink is the association table for users and roles

type PdmVendor

type PdmVendor struct {
	Base
	VendorName    string      `gorm:"type:varchar(32)"`
	VPurchasingID uint        `gorm:"foreignKey:VPurchasingID"`
	VPurchasing   PdmPurchase `gorm:"foreignKey:VPurchasingID"`
}

PdmVendor represents the vendors table

type Project

type Project struct {
	gorm.Model
	ID          uint   `gorm:"primaryKey"`
	ProjectName string `gorm:"size:100"`
	// contains filtered or unexported fields
}

Project represents the projects table.

func NewProject

func NewProject(number string, name string, status *string, path string) (*Project, error)

Create new project

func (*Project) AddUserToProject

func (p *Project) AddUserToProject()

Add user to project

func (Project) GetId

func (p Project) GetId(number string) int

Get id with Project number

func (*Project) RemovePproject

func (p *Project) RemovePproject()

Remove existing project

func (*Project) RemoveUserFromProject

func (p *Project) RemoveUserFromProject()

Remove user from project

func (*Project) UpdateProject

func (p *Project) UpdateProject()

Update existing project

type ProjectState

type ProjectState string

type RBAC added in v0.1.3

type RBAC string
const (
	CheckIn               RBAC = "Check-In"
	CheckOut              RBAC = "Check-Out"
	CreateDocument        RBAC = "Create Document"
	CreateItem            RBAC = "Create Item"
	CreateModel           RBAC = "Create Model"
	DeleteDocument        RBAC = "Delete Document"
	DeleteItem            RBAC = "Delete Item"
	DeleteModel           RBAC = "Delete Model"
	CreateProject         RBAC = "Create Project"
	AddUserToProject      RBAC = "Add User to Project"
	RemoveUserFromProject RBAC = "Remove User from Project"
	CreateUser            RBAC = "Create User"
	DeleteUser            RBAC = "Delete User"
	CreateDatabase        RBAC = "Create Database"
	ReadDocuments         RBAC = "Read Documents"
	ReadItems             RBAC = "Read Items"
	ReadModels            RBAC = "Read Models"
)

func RolePermissions

func RolePermissions(role []Role) (ret []RBAC)

role -> permissions mapping

type ReleaseStates

type ReleaseStates struct {
}

Item / Model /Document release states struct

func (ReleaseStates) ChangeReleaseState

func (r ReleaseStates) ChangeReleaseState()

new Item, Model, Document

func (ReleaseStates) Depreciated

func (r ReleaseStates) Depreciated()

Check in Items, Models, Documents

func (ReleaseStates) New

func (r ReleaseStates) New()

New Item, Model, Document

func (ReleaseStates) NotForNew

func (r ReleaseStates) NotForNew()

Check in Items, Models, Documents

func (ReleaseStates) Prototype

func (r ReleaseStates) Prototype()

Prototype Item, Model, Document

func (ReleaseStates) Release

func (r ReleaseStates) Release()

Check in Items, Models, Documents

type RevisionState

type RevisionState string

type Role

type Role string
const (
	Admin          Role = "admin"
	Designer       Role = "designer"
	SeniorDesigner Role = "senior"
	Viewer         Role = "viewer"
	Editor         Role = "editor"
	Approver       Role = "approver"
	ProjectLead    Role = "projectlead"
	Qa             Role = "qa"
	Guest          Role = "guest"
)

func DefaultRoles added in v0.1.3

func DefaultRoles() []Role

type RoleList added in v0.1.3

type RoleList []Role

func (*RoleList) Scan added in v0.1.3

func (r *RoleList) Scan(value interface{}) error

func (RoleList) Value added in v0.1.3

func (r RoleList) Value() (driver.Value, error)
type Search struct {
}

Search https://docs.sqlalchemy.org/en/14/orm/session_basics.html

func NewSearch added in v0.1.3

func NewSearch() *Search

func (Search) SearchDescription

func (s Search) SearchDescription(description string)

Search on description

func (Search) SearchHelp

func (s Search) SearchHelp() string

help function

func (Search) SearchNumber

func (s Search) SearchNumber(number int)

Search on number

func (Search) SearchSomething_else

func (s Search) SearchSomething_else(something string)

Search on something else

type SearchItem

type SearchItem struct {
}

Search for projects

func NewSearchItem added in v0.1.3

func NewSearchItem() *SearchItem

func (SearchItem) ItemDescription added in v0.1.3

func (s SearchItem) ItemDescription(description string)

Search on project description

func (SearchItem) ItemNumber added in v0.1.3

func (s SearchItem) ItemNumber(user_number string)

Search on project number

type SearchProject

type SearchProject struct {
}

Search for projects

func NewSearchProject added in v0.1.3

func NewSearchProject() *SearchProject

func (SearchProject) ProjectDescription added in v0.1.3

func (s SearchProject) ProjectDescription(description string)

Search on project description

func (SearchProject) ProjectNumber added in v0.1.3

func (s SearchProject) ProjectNumber(user_number string)

Search on project number

type SearchUser

type SearchUser struct {
}

Search for projects

func NewSearchUser added in v0.1.3

func NewSearchUser() *SearchUser

func (SearchUser) UserFirstFame added in v0.1.3

func (s SearchUser) UserFirstFame(user_first_name string)

Search on user first name

func (SearchUser) UserLastName added in v0.1.3

func (s SearchUser) UserLastName(user_last_name string)

Search on user last name

func (SearchUser) UserName added in v0.1.3

func (s SearchUser) UserName(user_name string)

Search on user name

func (SearchUser) UserNumber added in v0.1.3

func (s SearchUser) UserNumber(user_number string)

Search on user number

func (SearchUser) UserRole added in v0.1.3

func (s SearchUser) UserRole(user_role string)

Search on user role

type Session added in v0.1.3

type Session struct {
	Username   string
	Expiration time.Time
}

type TracebilityState

type TracebilityState string

type UserRepo added in v0.1.3

type UserRepo struct {
	DB *gorm.DB
}

Ease of handling

func NewUserRepo added in v0.1.3

func NewUserRepo(db *gorm.DB) *UserRepo

Constructor

func (*UserRepo) AddUserToLdap added in v0.1.3

func (r *UserRepo) AddUserToLdap(loginname string)

func (*UserRepo) ClearMustChangePassword added in v0.1.3

func (r *UserRepo) ClearMustChangePassword(loginname string) error

Resets the MustChangePassword flag to false

func (*UserRepo) CreateUser added in v0.1.3

func (r *UserRepo) CreateUser(user *PdmUser) error

func (*UserRepo) GetAllUsers added in v0.1.3

func (r *UserRepo) GetAllUsers() ([]PdmUser, error)

func (*UserRepo) LoadUser added in v0.1.3

func (r *UserRepo) LoadUser(loginname string) (*PdmUser, error)

LoadUser search a user based on user name.

func (*UserRepo) LoadUserByID added in v0.1.3

func (r *UserRepo) LoadUserByID(id uint) (*PdmUser, error)

LoadUser search by ID on user name.

func (*UserRepo) LoadUserByLoginName added in v0.1.3

func (r *UserRepo) LoadUserByLoginName(loginName string) (*PdmUser, error)

func (*UserRepo) NormalizeAllUsers added in v0.1.3

func (r *UserRepo) NormalizeAllUsers() error

NormalizeAllUsers walks over all users and normalizes their roles

func (*UserRepo) NormalizeAllUsersVerbose added in v0.1.3

func (r *UserRepo) NormalizeAllUsersVerbose() (changedCount, totalCount int, err error)

NormalizeAllUsersVerbose runs over all users and reports counts

func (*UserRepo) NormalizeUserRoles added in v0.1.3

func (r *UserRepo) NormalizeUserRoles(loginname string) error

NormalizeUserRoles updates the roles on a user to match the canonical lowercase Role constants

func (*UserRepo) NormalizeUserRolesVerbose added in v0.1.3

func (r *UserRepo) NormalizeUserRolesVerbose(loginname string) (bool, error)

NormalizeUserRolesVerbose updates and reports if any roles were changed

func (*UserRepo) RemoveUserFromLdap added in v0.1.3

func (r *UserRepo) RemoveUserFromLdap(user_id int, loginname string)

Delete existing user

func (*UserRepo) UpdatePassword added in v0.1.3

func (r *UserRepo) UpdatePassword(loginname, hash string) error

Renames password and also sets the MustChangePassword flag to false

func (*UserRepo) UpdatePhotoPath added in v0.1.3

func (r *UserRepo) UpdatePhotoPath(userID uint, photoPath string) error

UpdatePhotoPath updates the PhotoPath of a user by their ID.

func (*UserRepo) UpdateUser added in v0.1.3

func (r *UserRepo) UpdateUser(user *PdmUser) error

UpdateUser saves the updated user record into the database. It overwrites the existing user entry based on its primary key.

type VolumeUnit

type VolumeUnit string

type WeightUnit

type WeightUnit string

Jump to

Keyboard shortcuts

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