Documentation ¶
Index ¶
- Constants
- type Base
- type Contact
- type Create
- type OTP
- type PGInstance
- func (db *PGInstance) AddProduct(ctx context.Context, product *Product) (*Product, error)
- func (db *PGInstance) AddSaleRecord(ctx context.Context, sale *Sale) (*Sale, error)
- func (db *PGInstance) GetDailySale(ctx context.Context) ([]*Sale, error)
- func (db *PGInstance) GetProductByID(ctx context.Context, id string) (*Product, error)
- func (db *PGInstance) GetUserPINByUserID(ctx context.Context, userID string, flavour enums.Flavour) (*UserPIN, error)
- func (db *PGInstance) GetUserProfileByPhoneNumber(ctx context.Context, phoneNumber string, flavour enums.Flavour) (*User, error)
- func (db *PGInstance) GetUserProfileByUserID(ctx context.Context, userID *string) (*User, error)
- func (db *PGInstance) InvalidatePIN(ctx context.Context, userID string, flavour enums.Flavour) error
- func (db *PGInstance) RegisterUser(ctx context.Context, user *User, contact *Contact) (*User, error)
- func (db *PGInstance) SaveOTP(ctx context.Context, otp *OTP) (*OTP, error)
- func (db *PGInstance) SavePIN(ctx context.Context, pinData *UserPIN) (*UserPIN, error)
- func (db *PGInstance) SearchProduct(ctx context.Context, searchTerm string) ([]*Product, error)
- func (db *PGInstance) SearchUser(ctx context.Context, searchTerm string) ([]*User, error)
- func (db *PGInstance) UpdateProduct(ctx context.Context, product *Product, updateData map[string]interface{}) error
- func (db *PGInstance) UpdateUser(ctx context.Context, user *User, updateData map[string]interface{}) error
- type Product
- type Query
- type Sale
- type Update
- type User
- type UserPIN
Constants ¶
const ( // GoogleProject ... GoogleProject = "GOOGLE_CLOUD_PROJECT_ID" // DatabaseRegion ... DatabaseRegion = "DATABASE_REGION" // DatabasesInstance ... DatabasesInstance = "DATABASE_INSTANCE" // DBHost .. DBHost = "POSTGRES_HOST" // DBPort ... DBPort = "POSTGRES_PORT" // DBUser ... DBUser = "POSTGRES_USER" // DBPASSWORD ... DBPASSWORD = "POSTGRES_PASSWORD" // DBName ... DBName = "POSTGRES_DB" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct { CreatedAt time.Time `gorm:"column:created_at"` CreatedBy *string `gorm:"column:created_by"` UpdatedAt time.Time `gorm:"column:updated_at"` UpdatedBy *string `gorm:"column:updated_by"` }
Base is the base table for all tables
type Contact ¶
type Contact struct { Base ID string `gorm:"column:id"` Active bool `gorm:"column:active"` ContactType string `gorm:"column:contact_type"` ContactValue string `gorm:"column:contact_value"` Flavour enums.Flavour `gorm:"column:flavour"` UserID *string `gorm:"column:user_id"` }
Contact is a contact model for a user
func (*Contact) BeforeCreate ¶
BeforeCreate is a hook run before creating user contact
type Create ¶
type Create interface { RegisterUser(ctx context.Context, user *User, contact *Contact) (*User, error) SaveOTP(ctx context.Context, otp *OTP) (*OTP, error) SavePIN(ctx context.Context, pinData *UserPIN) (*UserPIN, error) AddProduct(ctx context.Context, product *Product) (*Product, error) AddSaleRecord(ctx context.Context, sale *Sale) (*Sale, error) }
Create holds all the database record creation methods
type OTP ¶
type OTP struct { Base ID string `gorm:"column:id"` IsValid bool `gorm:"column:is_valid"` ValidUntil time.Time `gorm:"column:valid_until"` PhoneNumber string `gorm:"column:phone_number"` OTP string `gorm:"column:otp"` Flavour enums.Flavour `gorm:"column:flavour"` UserID string `gorm:"column:user_id"` }
OTP is model for one time password
func (*OTP) BeforeCreate ¶
BeforeCreate is a hook run before creating an OTP
type PGInstance ¶
PGInstance box for postgres client. We use this instead of a global variable
func NewPGInstance ¶
func NewPGInstance() (*PGInstance, error)
NewPGInstance creates a new instance of postgres client
func (*PGInstance) AddProduct ¶
Adds a product into the database
func (*PGInstance) AddSaleRecord ¶
AddSaleRecord adds sale record in the database
func (*PGInstance) GetDailySale ¶
func (db *PGInstance) GetDailySale(ctx context.Context) ([]*Sale, error)
GetDailySale retrieves daily sales
func (*PGInstance) GetProductByID ¶
GetProductByID retrieves a product using its ID
func (*PGInstance) GetUserPINByUserID ¶
func (db *PGInstance) GetUserPINByUserID(ctx context.Context, userID string, flavour enums.Flavour) (*UserPIN, error)
GetUserPINByUserID fetches a user's pin using the user ID and Flavour
func (*PGInstance) GetUserProfileByPhoneNumber ¶
func (db *PGInstance) GetUserProfileByPhoneNumber(ctx context.Context, phoneNumber string, flavour enums.Flavour) (*User, error)
GetUserProfileByPhoneNumber fetches a user profile using the phone number
func (*PGInstance) GetUserProfileByUserID ¶
GetUserProfileByUserID fetches a user profile using the user ID
func (*PGInstance) InvalidatePIN ¶
func (db *PGInstance) InvalidatePIN(ctx context.Context, userID string, flavour enums.Flavour) error
InvalidatePIN invalidates a pin that is linked to the user profile when a new one is created
func (*PGInstance) RegisterUser ¶
func (db *PGInstance) RegisterUser(ctx context.Context, user *User, contact *Contact) (*User, error)
RegisterUser creates a new user record. The user can be a resident or a staff member
func (*PGInstance) SearchProduct ¶
SearchProduct searches a product using the term provided by the user
func (*PGInstance) SearchUser ¶
SearchUser searches for a user using the search term
func (*PGInstance) UpdateProduct ¶
func (db *PGInstance) UpdateProduct(ctx context.Context, product *Product, updateData map[string]interface{}) error
UpdateProduct updates product details
func (*PGInstance) UpdateUser ¶
func (db *PGInstance) UpdateUser(ctx context.Context, user *User, updateData map[string]interface{}) error
UpdateUser updates a user record
type Product ¶
type Product struct { Base ID string `gorm:"column:id"` Active bool `gorm:"column:active"` Name string `gorm:"column:name"` Category string `gorm:"column:category"` Quantity float64 `gorm:"column:quantity"` Unit string `gorm:"column:unit"` Price float64 `gorm:"column:price"` VAT float64 `gorm:"column:vat"` Description string `gorm:"column:description"` Manufacturer string `gorm:"column:manufacturer"` InStock bool `gorm:"column:in_stock"` }
Product is used to display product info
func (*Product) BeforeCreate ¶
BeforeCreate is a hook run before creating an OTP
type Query ¶
type Query interface { GetUserProfileByUserID(ctx context.Context, userID *string) (*User, error) GetUserProfileByPhoneNumber(ctx context.Context, phoneNumber string, flavour enums.Flavour) (*User, error) GetUserPINByUserID(ctx context.Context, userID string, flavour enums.Flavour) (*UserPIN, error) SearchUser(ctx context.Context, searchTerm string) ([]*User, error) GetProductByID(ctx context.Context, id string) (*Product, error) GetDailySale(ctx context.Context) ([]*Sale, error) SearchProduct(ctx context.Context, searchTerm string) ([]*Product, error) }
Query holds all the database record query methods
type Sale ¶
type Sale struct { Base ID string `gorm:"column:id"` Active bool `gorm:"column:active"` ProductID string `gorm:"column:product_id"` Quantity float64 `gorm:"column:quantity"` Unit string `gorm:"column:unit"` Price float64 `gorm:"column:price"` Product Product `gorm:"ForeignKey:product_id;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"` }
Sale is used to show sales data
func (*Sale) BeforeCreate ¶
BeforeCreate is a hook run before creating an OTP
type Update ¶
type Update interface { InvalidatePIN(ctx context.Context, userID string, flavour enums.Flavour) error UpdateUser(ctx context.Context, user *User, updateData map[string]interface{}) error UpdateProduct(ctx context.Context, product *Product, updateData map[string]interface{}) error }
Update holds all the database record update methods
type User ¶
type User struct { Base ID *string `gorm:"column:id"` FirstName string `gorm:"column:first_name"` LastName string `gorm:"column:last_name"` Active bool `gorm:"column:active"` UserName string `gorm:"column:username"` UserType string `gorm:"column:user_type"` PushToken string `gorm:"column:push_token"` Email string `gorm:"column:email"` Contacts Contact `gorm:"ForeignKey:user_id;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"` }
User models the system user
func (*User) BeforeCreate ¶
BeforeCreate is a hook run before creating a user
type UserPIN ¶
type UserPIN struct { Base ID string `gorm:"column:id"` Active bool `gorm:"column:active"` ValidFrom time.Time `gorm:"column:valid_from"` ValidTo time.Time `gorm:"column:valid_to"` HashedPIN string `gorm:"column:hashed_pin"` Salt string `gorm:"column:salt"` UserID string `gorm:"column:user_id"` }
UserPIN models the user's PIN table
func (*UserPIN) BeforeCreate ¶
BeforeCreate is a hook run before creating user PIN