model

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Copyright (c) 2024 Eli Janssen Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	DefaultReminderThresholdHours = 24
)
View Source
const UserPWResetExpiry = 30 * time.Minute
View Source
const UserVerifyExpiry = 30 * time.Minute

Variables

View Source
var NewApiKeyRefID = reftag.NewRandom[ApiKeyRefID]
View Source
var NewCredentialRefID = reftag.New[CredentialRefID]
View Source
var NewEarmarkRefID = reftag.New[EarmarkRefID]
View Source
var NewEventItemRefID = reftag.New[EventItemRefID]
View Source
var NewEventRefID = reftag.New[EventRefID]
View Source
var NewNotificationRefID = reftag.New[NotificationRefID]
View Source
var NewUserPWResetRefID = reftag.New[UserPWResetRefID]
View Source
var NewUserRefID = reftag.New[UserRefID]
View Source
var NewUserVerifyRefID = reftag.New[UserVerifyRefID]

Functions

func ArchiveOldEvents

func ArchiveOldEvents(ctx context.Context, db PgxHandle) error

func CheckPass

func CheckPass(ctx context.Context,
	pwHash []byte, rawPass []byte,
) (bool, error)

func DeleteEarmark

func DeleteEarmark(ctx context.Context, db PgxHandle,
	earmarkID int,
) error

func DeleteEvent

func DeleteEvent(ctx context.Context, db PgxHandle,
	eventID int,
) error

func DeleteEventItem

func DeleteEventItem(ctx context.Context, db PgxHandle,
	eventItemID int,
) error

func DeleteFavorite

func DeleteFavorite(ctx context.Context, db PgxHandle, favID int) error

func DeleteNotification

func DeleteNotification(ctx context.Context, db PgxHandle, ID int) error

func DeleteNotificationsByUser

func DeleteNotificationsByUser(ctx context.Context, db PgxHandle, userID int) error

func DeleteUser

func DeleteUser(ctx context.Context, db PgxHandle, userID int) error

func DeleteUserCredential

func DeleteUserCredential(ctx context.Context, db PgxHandle,
	ID int,
) error

func DeleteUserEventNotification

func DeleteUserEventNotification(ctx context.Context, db PgxHandle,
	userID int, eventID int,
) error

func DeleteUserPWReset

func DeleteUserPWReset(ctx context.Context, db PgxHandle,
	refID UserPWResetRefID,
) error

func DeleteUserVerify

func DeleteUserVerify(ctx context.Context, db PgxHandle,
	refID UserVerifyRefID,
) error

func Exec

func Exec[T any](ctx context.Context, db PgxHandle, query string, args ...interface{}) error

func ExecTx

func ExecTx[T any](ctx context.Context, db PgxHandle, query string, args ...interface{}) error

func Get

func Get[T any](ctx context.Context, db PgxHandle, query string, args ...interface{}) (T, error)

func GetNotificationCountByUser

func GetNotificationCountByUser(ctx context.Context, db PgxHandle,
	userID int,
) (int, error)

func GetUserCredentialCountByUser

func GetUserCredentialCountByUser(ctx context.Context, db PgxHandle,
	userID int,
) (int, error)

func HashPass

func HashPass(ctx context.Context, rawPass []byte) ([]byte, error)

func Query

func Query[T any](ctx context.Context, db PgxHandle, query string, args ...interface{}) ([]*T, error)

func QueryOne

func QueryOne[T any](ctx context.Context, db PgxHandle, query string, args ...interface{}) (*T, error)

func QueryOneTx

func QueryOneTx[T any](ctx context.Context, db PgxHandle, query string, args ...interface{}) (*T, error)

func QueryTx

func QueryTx[T any](ctx context.Context, db PgxHandle, query string, args ...interface{}) ([]*T, error)

func SetupDBPool

func SetupDBPool(dbDSN string, tracing bool) (*pgxpool.Pool, error)

func UpdateEarmark

func UpdateEarmark(ctx context.Context, db PgxHandle,
	earmarkID int, note string,
) error

func UpdateEvent

func UpdateEvent(ctx context.Context, db PgxHandle, eventID int,
	vals *EventUpdateModelValues,
) error

func UpdateEventItem

func UpdateEventItem(ctx context.Context, db PgxHandle,
	eventItemID int, description string,
) error

func UpdateUser

func UpdateUser(ctx context.Context, db PgxHandle, userID int,
	vals *UserUpdateModelValues,
) error

func UpdateUserSettings

func UpdateUserSettings(ctx context.Context, db PgxHandle,
	userID int, pm *UserSettings,
) error

func ValidateReminderThresholdHours

func ValidateReminderThresholdHours[T constraints.Unsigned](v T) (uint8, error)

Types

type ApiKey

type ApiKey struct {
	Created time.Time
	Token   string
	UserID  int `db:"user_id"`
}

func CreateApiKey

func CreateApiKey(ctx context.Context, db PgxHandle,
	userID int, token string,
) (*ApiKey, error)

func GetApiKeyByUser

func GetApiKeyByUser(ctx context.Context, db PgxHandle,
	userID int,
) (*ApiKey, error)

func NewApiKey

func NewApiKey(ctx context.Context, db PgxHandle,
	userID int,
) (*ApiKey, error)

type ApiKeyRefID

type ApiKeyRefID struct {
	reftag.IDt9
}

type BifurcatedRowCounts

type BifurcatedRowCounts struct {
	Current  int
	Archived int
}

func GetEarmarkCountByUser

func GetEarmarkCountByUser(ctx context.Context, db PgxHandle,
	userID int,
) (*BifurcatedRowCounts, error)

func GetEventCountsByUser

func GetEventCountsByUser(ctx context.Context, db PgxHandle,
	userID int,
) (*BifurcatedRowCounts, error)

func GetFavoriteCountByUser

func GetFavoriteCountByUser(ctx context.Context, db PgxHandle,
	userID int,
) (*BifurcatedRowCounts, error)

type CredentialRefID

type CredentialRefID struct {
	reftag.IDt7
}

type Earmark

type Earmark struct {
	Created      time.Time
	LastModified time.Time `db:"last_modified"`
	Note         string
	EventItemID  int `db:"event_item_id"`
	UserID       int `db:"user_id"`
	ID           int
	RefID        EarmarkRefID `db:"ref_id"`
}

func CreateEarmark

func CreateEarmark(ctx context.Context, db PgxHandle,
	refID EarmarkRefID, eventItemID int, userID int, note string,
) (*Earmark, error)

func GetEarmarkByEventItem

func GetEarmarkByEventItem(ctx context.Context, db PgxHandle,
	eventItemID int,
) (*Earmark, error)

func GetEarmarkByID

func GetEarmarkByID(ctx context.Context, db PgxHandle,
	earmarkID int,
) (*Earmark, error)

func GetEarmarkByRefID

func GetEarmarkByRefID(ctx context.Context, db PgxHandle,
	refID EarmarkRefID,
) (*Earmark, error)

func GetEarmarksByEvent

func GetEarmarksByEvent(ctx context.Context, db PgxHandle,
	eventID int,
) ([]*Earmark, error)

func GetEarmarksByEventItemIDs

func GetEarmarksByEventItemIDs(ctx context.Context, db PgxHandle,
	eventItemIDs []int,
) ([]*Earmark, error)

func GetEarmarksByUserFiltered

func GetEarmarksByUserFiltered(
	ctx context.Context, db PgxHandle,
	userID int, archived bool,
) ([]*Earmark, error)

func GetEarmarksByUserPaginated

func GetEarmarksByUserPaginated(ctx context.Context, db PgxHandle,
	userID int, limit, offset int,
) ([]*Earmark, error)

func GetEarmarksByUserPaginatedFiltered

func GetEarmarksByUserPaginatedFiltered(
	ctx context.Context, db PgxHandle,
	userID int, limit, offset int, archived bool,
) ([]*Earmark, error)

func NewEarmark

func NewEarmark(ctx context.Context, db PgxHandle,
	eventItemID, userID int, note string,
) (*Earmark, error)

type EarmarkRefID

type EarmarkRefID struct {
	reftag.IDt4
}

type Event

type Event struct {
	Created       time.Time
	LastModified  time.Time `db:"last_modified"`
	StartTime     time.Time `db:"start_time"`
	StartTimeTz   *TimeZone `db:"start_time_tz"`
	Name          string
	Description   string
	ItemSortOrder []int `db:"item_sort_order"`
	Archived      bool
	UserID        int `db:"user_id"`
	ID            int
	RefID         EventRefID `db:"ref_id"`
}

func CreateEvent

func CreateEvent(ctx context.Context, db PgxHandle,
	refID EventRefID,
	userID int, name, description string,
	startTime time.Time,
	startTimeTz *TimeZone,
) (*Event, error)

func GetEventByEventItemID

func GetEventByEventItemID(ctx context.Context, db PgxHandle,
	eventItemID int,
) (*Event, error)

func GetEventByID

func GetEventByID(ctx context.Context, db PgxHandle,
	eventID int,
) (*Event, error)

func GetEventByRefID

func GetEventByRefID(ctx context.Context, db PgxHandle,
	refID EventRefID,
) (*Event, error)

func GetEventsByIDs

func GetEventsByIDs(ctx context.Context, db PgxHandle,
	eventIDs []int,
) ([]*Event, error)

func GetEventsByUserFiltered

func GetEventsByUserFiltered(
	ctx context.Context, db PgxHandle,
	userID int, archived bool,
) ([]*Event, error)

func GetEventsByUserPaginated

func GetEventsByUserPaginated(
	ctx context.Context, db PgxHandle,
	userID int, limit, offset int,
) ([]*Event, error)

func GetEventsByUserPaginatedFiltered

func GetEventsByUserPaginatedFiltered(
	ctx context.Context, db PgxHandle,
	userID int, limit, offset int, archived bool,
) ([]*Event, error)

func GetEventsComingSoonByUserPaginated

func GetEventsComingSoonByUserPaginated(
	ctx context.Context, db PgxHandle,
	userID int, limit, offset int,
) ([]*Event, error)

func GetFavoriteEventsByUserFiltered

func GetFavoriteEventsByUserFiltered(
	ctx context.Context, db PgxHandle,
	userID int, archived bool,
) ([]*Event, error)

func GetFavoriteEventsByUserPaginatedFiltered

func GetFavoriteEventsByUserPaginatedFiltered(
	ctx context.Context, db PgxHandle,
	userID int, limit, offset int, archived bool,
) ([]*Event, error)

func NewEvent

func NewEvent(ctx context.Context, db PgxHandle,
	userID int, name, description string,
	startTime time.Time,
	startTimeTz *TimeZone,
) (*Event, error)

func (*Event) When

func (ev *Event) When() time.Time

type EventItem

type EventItem struct {
	Created      time.Time
	LastModified time.Time `db:"last_modified"`
	Description  string
	EventID      int `db:"event_id"`
	ID           int
	RefID        EventItemRefID `db:"ref_id"`
}

func CreateEventItem

func CreateEventItem(ctx context.Context, db PgxHandle,
	refID EventItemRefID, eventID int, description string,
) (*EventItem, error)

func GetEventItemByID

func GetEventItemByID(ctx context.Context, db PgxHandle,
	eventItemID int,
) (*EventItem, error)

func GetEventItemByRefID

func GetEventItemByRefID(ctx context.Context, db PgxHandle,
	refID EventItemRefID,
) (*EventItem, error)

func GetEventItemsByEvent

func GetEventItemsByEvent(ctx context.Context, db PgxHandle,
	eventID int,
) ([]*EventItem, error)

func GetEventItemsByIDs

func GetEventItemsByIDs(ctx context.Context, db PgxHandle,
	eventItemIDs []int,
) ([]*EventItem, error)

func NewEventItem

func NewEventItem(ctx context.Context, db PgxHandle,
	eventID int, description string,
) (*EventItem, error)

type EventItemCount

type EventItemCount struct {
	EventID int `db:"event_id"`
	Count   int
}

func GetEventItemsCountByEventIDs

func GetEventItemsCountByEventIDs(ctx context.Context, db PgxHandle,
	eventIDs []int,
) ([]*EventItemCount, error)

type EventItemRefID

type EventItemRefID struct {
	reftag.IDt3
}

type EventRefID

type EventRefID struct {
	reftag.IDt2
}

type EventUpdateModelValues

type EventUpdateModelValues struct {
	StartTime     mo.Option[time.Time]
	Tz            mo.Option[*TimeZone]
	Name          mo.Option[string]
	Description   mo.Option[string]
	ItemSortOrder mo.Option[[]int]
}

type Favorite

type Favorite struct {
	Created time.Time
	EventID int `db:"event_id"`
	UserID  int `db:"user_id"`
	ID      int
}

func CreateFavorite

func CreateFavorite(ctx context.Context, db PgxHandle,
	userID int, eventID int,
) (*Favorite, error)

func GetFavoriteByID

func GetFavoriteByID(ctx context.Context, db PgxHandle, favID int) (*Favorite, error)

func GetFavoriteByUserEvent

func GetFavoriteByUserEvent(ctx context.Context, db PgxHandle,
	userID int, eventID int,
) (*Favorite, error)

type Notification

type Notification struct {
	Created      time.Time
	LastModified time.Time `db:"last_modified"`
	Message      string
	UserID       int `db:"user_id"`
	ID           int
	RefID        NotificationRefID `db:"ref_id"`
	Read         bool
}

func CreateNotification

func CreateNotification(ctx context.Context, db PgxHandle,
	refID NotificationRefID, userID int, message string,
) (*Notification, error)

func GetNotificationByID

func GetNotificationByID(ctx context.Context, db PgxHandle, ID int) (*Notification, error)

func GetNotificationByRefID

func GetNotificationByRefID(ctx context.Context, db PgxHandle,
	refID NotificationRefID,
) (*Notification, error)

func GetNotificationsByUser

func GetNotificationsByUser(ctx context.Context, db PgxHandle,
	userID int,
) ([]*Notification, error)

func GetNotificationsByUserPaginated

func GetNotificationsByUserPaginated(ctx context.Context, db PgxHandle,
	userID int, limit, offset int,
) ([]*Notification, error)

func NewNotification

func NewNotification(ctx context.Context, db PgxHandle,
	userID int, message string,
) (*Notification, error)

func UpdateNotification

func UpdateNotification(ctx context.Context, db PgxHandle,
	ID int, read bool,
) (*Notification, error)

type NotificationRefID

type NotificationRefID struct {
	reftag.IDt8
}

type PgxHandle

type PgxHandle interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
}

type TimeZone

type TimeZone struct {
	*time.Location
}

func (TimeZone) Equal

func (tz TimeZone) Equal(other TimeZone) bool

func (*TimeZone) Scan

func (tz *TimeZone) Scan(src interface{}) error

Scan implements the sql.Scanner interface. A 16-byte slice will be handled by UnmarshalBinary, while a longer byte slice or a string will be handled by UnmarshalText.

func (TimeZone) Value

func (tz TimeZone) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type User

type User struct {
	Created      time.Time
	LastModified time.Time `db:"last_modified"`
	Email        string
	Name         string
	PWHash       []byte
	ID           int
	RefID        UserRefID `db:"ref_id"`
	Settings     UserSettings
	Verified     bool
	PWAuth       bool
	ApiAccess    bool `db:"api_access"`
	WebAuthn     bool
}

func CreateUser

func CreateUser(ctx context.Context, db PgxHandle,
	refID UserRefID, email, name string, pwHash []byte,
) (*User, error)

func GetUserByApiKey

func GetUserByApiKey(ctx context.Context, db PgxHandle,
	token string,
) (*User, error)

func GetUserByEmail

func GetUserByEmail(ctx context.Context, db PgxHandle,
	email string,
) (*User, error)

func GetUserByID

func GetUserByID(ctx context.Context, db PgxHandle,
	userID int,
) (*User, error)

func GetUserByRefID

func GetUserByRefID(ctx context.Context, db PgxHandle,
	refID UserRefID,
) (*User, error)

func GetUsersByIDs

func GetUsersByIDs(ctx context.Context, db PgxHandle,
	userIDs []int,
) ([]*User, error)

func NewUser

func NewUser(ctx context.Context, db PgxHandle,
	email, name string, rawPass []byte,
) (*User, error)

func (User) LogValue

func (u User) LogValue() slog.Value

type UserCredential

type UserCredential struct {
	Created    time.Time
	KeyName    string `db:"key_name"`
	Credential []byte
	UserID     int `db:"user_id"`
	ID         int
	RefID      CredentialRefID `db:"ref_id"`
}

func CreateUserCredential

func CreateUserCredential(ctx context.Context, db PgxHandle,
	refID CredentialRefID, userID int, keyName string, credential []byte,
) (*UserCredential, error)

func GetUserCredentialByRefID

func GetUserCredentialByRefID(ctx context.Context, db PgxHandle,
	refID CredentialRefID,
) (*UserCredential, error)

func GetUserCredentialsByUser

func GetUserCredentialsByUser(ctx context.Context, db PgxHandle,
	userID int,
) ([]*UserCredential, error)

func NewUserCredential

func NewUserCredential(ctx context.Context, db PgxHandle,
	userID int, keyName string, credential []byte,
) (*UserCredential, error)

type UserEventNotification

type UserEventNotification struct {
	Created time.Time
	UserID  int `db:"user_id"`
	EventID int `db:"event_id"`
}

func CreateUserEventNotification

func CreateUserEventNotification(ctx context.Context, db PgxHandle,
	userID int, eventID int,
) (*UserEventNotification, error)

func GetUserEventNotification

func GetUserEventNotification(ctx context.Context, db PgxHandle,
	userID int, eventID int,
) (*UserEventNotification, error)

func NewUserEventNotification

func NewUserEventNotification(ctx context.Context, db PgxHandle,
	userID int, eventID int,
) (*UserEventNotification, error)

type UserEventNotificationNeeded

type UserEventNotificationNeeded struct {
	When         time.Time
	EventItemIDs []int `db:"items"`
	UserID       int   `db:"user_id"`
	EventID      int   `db:"event_id"`
	Owner        bool
}

func GetUserEventNotificationNeeded

func GetUserEventNotificationNeeded(
	ctx context.Context, db PgxHandle,
) ([]*UserEventNotificationNeeded, error)

type UserPWReset

type UserPWReset struct {
	Created time.Time
	UserID  int              `db:"user_id"`
	RefID   UserPWResetRefID `db:"ref_id"`
}

func CreateUserPWReset

func CreateUserPWReset(ctx context.Context, db PgxHandle,
	refID UserPWResetRefID, userID int,
) (*UserPWReset, error)

func GetUserPWResetByRefID

func GetUserPWResetByRefID(ctx context.Context, db PgxHandle,
	refID UserPWResetRefID,
) (*UserPWReset, error)

func NewUserPWReset

func NewUserPWReset(ctx context.Context, db PgxHandle,
	userID int,
) (*UserPWReset, error)

type UserPWResetRefID

type UserPWResetRefID struct {
	reftag.IDt5
}

type UserRefID

type UserRefID struct {
	reftag.IDt1
}

type UserSettings

type UserSettings struct {
	ReminderThresholdHours uint8 `json:"reminder_threshold"`
	// weird negative name here, so zero value defaults
	// to enabling reminders
	EnableReminders bool `json:"enable_reminders"`
}

func NewUserPropertyMap

func NewUserPropertyMap() *UserSettings

func (*UserSettings) Scan

func (p *UserSettings) Scan(src interface{}) error

func (UserSettings) Value

func (p UserSettings) Value() (driver.Value, error)

type UserSettingsMatcher

type UserSettingsMatcher struct {
	// contains filtered or unexported fields
}

func NewUserSettingsMatcher

func NewUserSettingsMatcher(expected UserSettings) UserSettingsMatcher

func (UserSettingsMatcher) Match

func (m UserSettingsMatcher) Match(v interface{}) bool

type UserUpdateModelValues

type UserUpdateModelValues struct {
	Name      mo.Option[string]
	Email     mo.Option[string]
	PWHash    mo.Option[[]byte]
	Verified  mo.Option[bool]
	PWAuth    mo.Option[bool]
	ApiAccess mo.Option[bool]
	WebAuthn  mo.Option[bool]
}

type UserVerify

type UserVerify struct {
	Created time.Time
	UserID  int             `db:"user_id"`
	RefID   UserVerifyRefID `db:"ref_id"`
}

func CreateUserVerify

func CreateUserVerify(ctx context.Context, db PgxHandle,
	refID UserVerifyRefID, userID int,
) (*UserVerify, error)

func GetUserVerifyByRefID

func GetUserVerifyByRefID(ctx context.Context, db PgxHandle,
	refID UserVerifyRefID,
) (*UserVerify, error)

func NewUserVerify

func NewUserVerify(ctx context.Context, db PgxHandle,
	userID int,
) (*UserVerify, error)

type UserVerifyRefID

type UserVerifyRefID struct {
	reftag.IDt6
}

Jump to

Keyboard shortcuts

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