schemas

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DbGetChildSlice

func DbGetChildSlice[Parent interface{}, Schema interface{}](
	ctx context.Context,
	db *gorm.DB,
	parent *Parent,
	columnName string,
	first *int32,
	limit *int32,
	order string,
) ([]Schema, error)

func DbGetFromId

func DbGetFromId[T interface{}, N int32 | int64 | uint](ctx context.Context, db *gorm.DB, id N) (T, error)

func DbGetManyFromIds

func DbGetManyFromIds[T interface{}, N int32 | int64 | uint](ctx context.Context, db *gorm.DB, ids []N) ([]T, error)

func DbIdsOfAssoc

func DbIdsOfAssoc[N int32 | int64 | uint](ctx context.Context, db *gorm.DB, model interface{}, column string) ([]N, error)

func ModelAuthHealthEntry

func ModelAuthHealthEntry(ctx context.Context, db *gorm.DB, principal *User, schema *HealthEntry) error

func OpenDb

func OpenDb(db_url string) (*gorm.DB, error)

Types

type Category

type Category struct {
	gorm.Model
	UserID        uint
	Title         string
	MultiChoices  []CategoryMultiChoice       `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	SingleChoices []CategorySingleChoiceGroup `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

func (*Category) FromModel

func (category *Category) FromModel(_ context.Context, _ *gorm.DB, model models.Category) error

func (Category) GetOwnerID

func (category Category) GetOwnerID(context.Context, *gorm.DB) uint

func (*Category) SetParentId

func (category *Category) SetParentId(id uint)

func (*Category) ToModel

func (category *Category) ToModel(context.Context, *gorm.DB) (models.Category, error)

type CategoryMultiChoice

type CategoryMultiChoice struct {
	gorm.Model
	CategoryID  uint
	Title       string
	Description string
	Entries     []*HealthEntry `gorm:"many2many:entry_multi_choices;"`
}

func (*CategoryMultiChoice) FromModel

func (choice *CategoryMultiChoice) FromModel(_ context.Context, _ *gorm.DB, model models.CategoryMultiChoice) error

func (CategoryMultiChoice) GetOwnerID

func (choice CategoryMultiChoice) GetOwnerID(ctx context.Context, db *gorm.DB) uint

func (*CategoryMultiChoice) GetParent

func (choice *CategoryMultiChoice) GetParent(ctx context.Context, db *gorm.DB) (Category, error)

func (*CategoryMultiChoice) SetParentId

func (choice *CategoryMultiChoice) SetParentId(id uint)

func (*CategoryMultiChoice) ToModel

type CategorySingleChoiceGroup

type CategorySingleChoiceGroup struct {
	gorm.Model
	CategoryID  uint
	Title       string
	Description string
	Choices     []CategorySingleChoiceItem `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

func (*CategorySingleChoiceGroup) FromModel

func (CategorySingleChoiceGroup) GetOwnerID

func (choice CategorySingleChoiceGroup) GetOwnerID(ctx context.Context, db *gorm.DB) uint

func (*CategorySingleChoiceGroup) GetParent

func (choice *CategorySingleChoiceGroup) GetParent(ctx context.Context, db *gorm.DB) (Category, error)

func (*CategorySingleChoiceGroup) SetParentId

func (choice *CategorySingleChoiceGroup) SetParentId(id uint)

func (*CategorySingleChoiceGroup) ToModel

type CategorySingleChoiceItem

type CategorySingleChoiceItem struct {
	gorm.Model
	CategorySingleChoiceGroupID uint
	Title                       string
	Description                 string
	Entries                     []*HealthEntry `gorm:"many2many:entry_single_choices;"`
}

func (*CategorySingleChoiceItem) FromModel

func (CategorySingleChoiceItem) GetOwnerID

func (choice CategorySingleChoiceItem) GetOwnerID(ctx context.Context, db *gorm.DB) uint

func (*CategorySingleChoiceItem) GetParent

func (*CategorySingleChoiceItem) SetParentId

func (choice *CategorySingleChoiceItem) SetParentId(id uint)

func (*CategorySingleChoiceItem) ToModel

type HealthEntry

type HealthEntry struct {
	gorm.Model

	UserID uint `json:"user_id"`

	Remarks string `json:"remarks"`

	HaveBloodPressure bool    `json:"have_blood_pressure"`
	Systole           float32 `json:"systole"`
	Diastole          float32 `json:"diastole"`
	Pulse             float32 `json:"pulse"`

	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`

	MultiChoices  []CategoryMultiChoice      `gorm:"many2many:entry_multi_choices;" json:"multi_choices"`
	SingleChoices []CategorySingleChoiceItem `gorm:"many2many:entry_single_choices;" json:"single_choices"`
}

func (*HealthEntry) FromModel

func (entry *HealthEntry) FromModel(ctx context.Context, db *gorm.DB, model models.Entry) error

func (HealthEntry) GetOwnerID

func (entry HealthEntry) GetOwnerID(context.Context, *gorm.DB) uint

func (*HealthEntry) SetParentId

func (entry *HealthEntry) SetParentId(id uint)

func (*HealthEntry) ToModel

func (entry *HealthEntry) ToModel(ctx context.Context, db *gorm.DB) (models.Entry, error)

type User

type User struct {
	gorm.Model
	OidcIssuer    string
	OidcSub       string
	Name          string
	FirstName     string
	HealthEntries []HealthEntry
	Categories    []Category `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

func LookupUser

func LookupUser(ctx context.Context, db *gorm.DB, id uint) (User, error)

func (*User) CreateAllowed

func (user *User) CreateAllowed(objOwnerId uint) bool

func (*User) DeleteAllowed

func (user *User) DeleteAllowed(objOwnerId uint) bool

func (*User) ReadAllowed

func (user *User) ReadAllowed(objOwnerId uint) bool

func (*User) UpdateAllowed

func (user *User) UpdateAllowed(objOwnerId uint) bool

Jump to

Keyboard shortcuts

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