Documentation ¶
Index ¶
- Constants
- Variables
- type Base
- type Bill
- type Contact
- type Create
- type House
- type HouseClient
- type Identifier
- type OTP
- type PGInstance
- func (db *PGInstance) CreateHouse(ctx context.Context, house *House) error
- func (db *PGInstance) CreateResidence(ctx context.Context, payload Residence) (*Residence, error)
- func (db *PGInstance) GetHouseByNumber(ctx context.Context, houseNumber string) (*House, error)
- func (db *PGInstance) GetResidenceByID(ctx context.Context, residenceID string) (*Residence, 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) GetUserResidencesByUserID(ctx context.Context, userID string) ([]*UserResidence, error)
- func (db *PGInstance) InvalidatePIN(ctx context.Context, userID string, flavour enums.Flavour) (bool, error)
- func (db *PGInstance) ListHousesInResidence(ctx context.Context, residenceID string) ([]*House, error)
- func (db *PGInstance) RegisterUser(ctx context.Context, user *User, contact *Contact, identifier *Identifier) error
- func (db *PGInstance) SaveOTP(ctx context.Context, otp *OTP) error
- func (db *PGInstance) SavePIN(ctx context.Context, pinData *UserPIN) (bool, error)
- func (db *PGInstance) SearchUser(ctx context.Context, searchTerm string) ([]*User, error)
- func (db *PGInstance) UpdateUser(ctx context.Context, user *User, updateData map[string]interface{}) (bool, error)
- type Query
- type Residence
- type Update
- type User
- type UserPIN
- type UserResidence
Constants ¶
const ( // DBHost .. DBHost = "POSTGRES_HOST" // DBPort ... DBPort = "POSTGRES_PORT" // DBUser ... DBUser = "POSTGRES_USER" // DBPASSWORD ... DBPASSWORD = "POSTGRES_PASSWORD" // DBName ... DBName = "POSTGRES_DB" )
Variables ¶
var ( // DefaultResidence is the default residence for a user incase none is specified DefaultResidence = helpers.MustGetEnvVar("DEFAULT_RESIDENCE_ID") )
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 Bill ¶
type Bill struct { Base ID string `gorm:"column:id"` Active bool `gorm:"column:active"` Type string `gorm:"column:type"` Amount float64 `gorm:"column:amount"` Penalty float64 `gorm:"column:penalty"` UserID string `gorm:"column:user_id"` }
Bill represents a billing model
func (*Bill) BeforeCreate ¶
BeforeCreate is a hook run before creating a bill
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, identifier *Identifier) error SaveOTP(ctx context.Context, otp *OTP) error SavePIN(ctx context.Context, pinData *UserPIN) (bool, error) CreateResidence(ctx context.Context, payload Residence) (*Residence, error) CreateHouse(ctx context.Context, house *House) error }
Create holds all the database record creation methods
type House ¶
type House struct { Base ID string `gorm:"column:id;primary_key"` Active bool `gorm:"column:active"` Number string `gorm:"column:number"` Category string `gorm:"column:category"` Class string `gorm:"column:class"` // applicable where houses maybe charged differently due to size RentValue float64 `gorm:"column:rent_value"` State string `gorm:"column:state"` ResidenceID string `gorm:"column:residence_id"` }
House models the datastore entity for a house
func (*House) BeforeCreate ¶
BeforeCreate is a hook run before creating a house
type HouseClient ¶
type HouseClient struct { ID string `gorm:"column:id"` HouseID string `gorm:"column:house_id"` TenantID string `gorm:"column:tenant_id"` }
House models the relationship between a tenant and the living house
func (*HouseClient) BeforeCreate ¶
func (h *HouseClient) BeforeCreate(tx *gorm.DB) (err error)
BeforeCreate is a hook run before creating a house client
func (HouseClient) TableName ¶
func (HouseClient) TableName() string
TableName customizes how the table name is generated
type Identifier ¶
type Identifier struct { Base ID string `gorm:"column:id"` Active bool `gorm:"column:active"` IdentifierType enums.IdentifierType `gorm:"column:identifier_type"` IdentifierValue string `gorm:"column:identifier_value"` UserID *string `gorm:"column:user_id"` }
Identifiers models the identifier that may be used in the system
func (*Identifier) BeforeCreate ¶
func (i *Identifier) BeforeCreate(tx *gorm.DB) (err error)
BeforeCreate is a hook run before creating an identifier
func (Identifier) TableName ¶
func (Identifier) TableName() string
TableName customizes how the table name is generated
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"` Medium string `gorm:"column:medium"` 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) CreateHouse ¶
func (db *PGInstance) CreateHouse(ctx context.Context, house *House) error
CreateHouse creates a new house
func (*PGInstance) CreateResidence ¶
CreateResidence creates a new residence
func (*PGInstance) GetHouseByNumber ¶
GetHouseByNumber fetches a house using the house number
func (*PGInstance) GetResidenceByID ¶
GetResidenceByID fetches a residence using the residence 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) GetUserResidencesByUserID ¶
func (db *PGInstance) GetUserResidencesByUserID(ctx context.Context, userID string) ([]*UserResidence, error)
GetUserResidencesByUserID fetches a user's residences using the user ID
func (*PGInstance) InvalidatePIN ¶
func (db *PGInstance) InvalidatePIN(ctx context.Context, userID string, flavour enums.Flavour) (bool, error)
InvalidatePIN invalidates a pin that is linked to the user profile when a new one is created
func (*PGInstance) ListHousesInResidence ¶
func (db *PGInstance) ListHousesInResidence(ctx context.Context, residenceID string) ([]*House, error)
ListHousesInResidence lists all the houses in a residence
func (*PGInstance) RegisterUser ¶
func (db *PGInstance) RegisterUser(ctx context.Context, user *User, contact *Contact, identifier *Identifier) error
RegisterUser creates a new user record. The user can be a resident or a staff member
func (*PGInstance) SaveOTP ¶
func (db *PGInstance) SaveOTP(ctx context.Context, otp *OTP) error
SaveOTP saves an OTP in the database
func (*PGInstance) SearchUser ¶
SearchUser searches for a user using the search term
func (*PGInstance) UpdateUser ¶
func (db *PGInstance) UpdateUser(ctx context.Context, user *User, updateData map[string]interface{}) (bool, error)
UpdateUser updates a user record
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) GetUserResidencesByUserID(ctx context.Context, userID string) ([]*UserResidence, error) GetResidenceByID(ctx context.Context, residenceID string) (*Residence, error) SearchUser(ctx context.Context, searchTerm string) ([]*User, error) GetHouseByNumber(ctx context.Context, houseNumber string) (*House, error) ListHousesInResidence(ctx context.Context, residenceID string) ([]*House, error) }
Query holds all the database record query methods
type Residence ¶
type Residence struct { Base ID string `gorm:"column:id"` Active bool `gorm:"column:active"` Name string `gorm:"column:name"` RegistrationNumber string `gorm:"column:registration_number"` Location string `gorm:"column:location"` LivingRoomsCount int `gorm:"column:living_rooms_count"` Owner string `gorm:"column:owner"` }
Residence models the residence's table
func (*Residence) BeforeCreate ¶
BeforeCreate is a hook run before creating a residence
type Update ¶
type Update interface { InvalidatePIN(ctx context.Context, userID string, flavour enums.Flavour) (bool, error) UpdateUser(ctx context.Context, user *User, updateData map[string]interface{}) (bool, 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"` MiddleName string `gorm:"column:middle_name"` LastName string `gorm:"column:last_name"` Active bool `gorm:"column:active"` Flavour enums.Flavour `gorm:"column:flavour"` UserName string `gorm:"column:username"` UserType string `gorm:"column:user_type"` DeviceToken string `gorm:"column:device_token"` Residence string `gorm:"column:residence"` UserContact Contact `gorm:"ForeignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"` UserIdentifier Identifier `gorm:"ForeignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"` CurrentResidence *string `gorm:"column:current_residence"` CurrentHouse *string `gorm:"column:current_house"` }
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"` Flavour enums.Flavour `gorm:"column:flavour"` 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
type UserResidence ¶
type UserResidence struct { ID string `gorm:"column:id"` UserID string `gorm:"column:user_id"` ResidenceID string `gorm:"column:residence_id"` }
UserResidence models the relationship between a user and the residence they live in
func (*UserResidence) BeforeCreate ¶
func (ur *UserResidence) BeforeCreate(tx *gorm.DB) (err error)
BeforeCreate is a hook run before creating a house client
func (UserResidence) TableName ¶
func (UserResidence) TableName() string
TableName customizes how the table name is generated