Documentation
¶
Index ¶
- Variables
- func Close() error
- func CreateChat(chat Chat) error
- func CreateMessage(msg Message) error
- func CreatePlatformError(error PlatformError) error
- func CreateTransaction(tx Transaction) error
- func CreateUser(user User) error
- func DeleteAllChatsByUserID(userID string) error
- func DeleteAllMessageByChatID(chatID string) error
- func DeleteAllPlatformErrorByUserID(userID string) error
- func DeleteChatByID(ID string) error
- func DeleteMessageByID(ID string) error
- func DeletePlatformErrorByID(errorID string) error
- func DeleteUser(userID string) error
- func ForceMigrationVersion(version int) error
- func GetMigrationVersion() (uint, bool, error)
- func GetVersion() string
- func InitStorage(connString string) error
- func InitStorageWithoutMigration(connString string) error
- func MigrateDown() error
- func MigrateSteps(steps int) error
- func MigrateTo(version uint) error
- func MigrateUp() error
- func RunMigrations() error
- func UpdateChat(chat Chat) error
- func UpdateMessage(msg Message) error
- func UpdatePlatformError(error PlatformError) error
- func UpdateTransaction(tx Transaction) error
- func UpdateUser(user User) error
- type Chat
- type Message
- type Modes
- type PlatformError
- type RequestCount
- type Response
- type Transaction
- type User
- func FindUserByEmailOrUsername(identifier string) (*User, string, bool)
- func GetUserByEmail(email string) (*User, error)
- func GetUserByID(userID string) (*User, error)
- func GetUserByPhoneWithTransactions(phoneNumber string) (*User, error)
- func GetUserByUsername(username string) (*User, error)
- func GetUsers() ([]User, error)
Constants ¶
This section is empty.
Variables ¶
var (
DB *sql.DB
)
Functions ¶
func CreateChat ¶
func CreateMessage ¶
func CreatePlatformError ¶
func CreatePlatformError(error PlatformError) error
func CreateTransaction ¶
func CreateTransaction(tx Transaction) error
func CreateUser ¶
func DeleteAllChatsByUserID ¶
func DeleteChatByID ¶
func DeleteMessageByID ¶
func DeletePlatformErrorByID ¶
func DeleteUser ¶
func ForceMigrationVersion ¶
ForceMigrationVersion forces the migration version (use when in dirty state)
func GetMigrationVersion ¶
GetMigrationVersion returns the current migration version and dirty state
func GetVersion ¶
func GetVersion() string
func InitStorage ¶
InitStorage initializes the PostgreSQL database connection and runs migrations
func InitStorageWithoutMigration ¶
InitStorageWithoutMigration initializes connection without running migrations
func MigrateDown ¶
func MigrateDown() error
MigrateDown rolls back the last migration (use with caution)
func MigrateSteps ¶
MigrateSteps migrates up or down by the specified number of steps Positive number = migrate up, Negative number = migrate down
func UpdateChat ¶
func UpdateMessage ¶
func UpdatePlatformError ¶
func UpdatePlatformError(error PlatformError) error
func UpdateTransaction ¶
func UpdateTransaction(tx Transaction) error
func UpdateUser ¶
Types ¶
type Chat ¶
type Chat struct {
ID string `json:"id"`
UserId string `json:"user_id"`
Title string `json:"title"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
IsArchived bool `json:"is_archived"`
MessageCount int `json:"message_count"`
LastMessageAt time.Time `json:"last_message_at"`
IsPrivate bool `json:"is_private"`
Messages []Message `json:"messages"`
IsReadOnly bool `json:"is_read_only"`
}
func GetChatById ¶
func GetChatsByUserId ¶
type Message ¶
type Message struct {
ID string `json:"id"`
ChatId string `json:"chat_id"`
Prompt string `json:"prompt,omitempty"`
Response string `json:"response"`
CreatedAt time.Time `json:"created_at"`
Model string `json:"model,omitempty"`
References []string `json:"references,omitempty"`
}
func GetMessageById ¶
func GetMessagesByChatId ¶
type PlatformError ¶
type PlatformError struct {
ID string `json:"id"`
Message string `json:"message"`
Description string `json:"description,omitempty"`
Action string `json:"action"`
Status string `json:"status,omitempty"`
UserId string `json:"user_id"`
Context string `json:"context,omitempty"`
Severity string `json:"severity"`
CreatedAt string `json:"created_at"`
UpdatedAt time.Time `json:"UpdatedAt"`
}
func GetPlatformErrorByID ¶
func GetPlatformErrorByID(errorID string) (*PlatformError, error)
func GetPlatformErrors ¶
func GetPlatformErrors() ([]PlatformError, error)
type RequestCount ¶
type Response ¶
type Response struct {
Success bool `json:"success"`
Status int `json:"status,omitempty"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
Response represents API response
type Transaction ¶
type Transaction struct {
ID string `json:"id"`
ExternalReference string `json:"ExternalReference"`
MpesaReceiptNumber string `json:"MpesaReceiptNumber"`
CheckoutRequestID string `json:"CheckoutRequestID"`
MerchantRequestID string `json:"MerchantRequestID"`
Amount int `json:"Amount"`
PhoneNumber string `json:"Phone"`
ResultCode int `json:"ResultCode"`
ResultDescription string `json:"ResultDesc"`
Status string `json:"Status"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
}
func GetTransactionByExtRef ¶
func GetTransactionByExtRef(ref string) (*Transaction, error)
func GetTransactionByID ¶
func GetTransactionByID(txID string) (*Transaction, error)
func GetTransactions ¶
func GetTransactions() ([]Transaction, error)
func GetUserTransactions ¶
func GetUserTransactions(phoneNumber string) ([]Transaction, error)
GetUserTransactions retrieves all transactions for a user based on their phone number
type User ¶
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
PasswordHash string `json:"password_hash"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Preferences string `json:"preferences,omitempty"`
WorkFunction string `json:"work_function,omitempty"`
Theme string `json:"theme,omitempty"`
SyncEnabled bool `json:"sync_enabled"`
Plan string `json:"plan,omitempty"`
PlanName string `json:"plan_name,omitempty"`
Amount int `json:"amount,omitempty"`
Duration string `json:"duration,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"`
ExpiryTimestamp int64 `json:"expiry_timestamp,omitempty"`
ExpireDuration int64 `json:"expire_duration,omitempty"`
Price string `json:"price,omitempty"`
ResponseMode Modes `json:"response_mode,omitempty"`
AgreeToTerms bool `json:"agree_to_terms"`
RequestCount RequestCount `json:"request_count"`
EmailVerified bool `json:"email_verified"`
EmailSubscribed bool `json:"email_subscribed"`
VerificationToken string `json:"verification_token,omitempty"`
VerificationTokenExpiry time.Time `json:"verification_token_expiry"`
UnsubscribeToken string `json:"unsubscribe_token,omitempty"`
UserTransactions []Transaction `json:"user_transactions,omitempty"`
UserAgent string `json:"user_agent"`
}
func FindUserByEmailOrUsername ¶
findUserByEmailOrUsername tries to find user by email or username in storage
func GetUserByEmail ¶
func GetUserByID ¶
func GetUserByPhoneWithTransactions ¶
GetUserByPhoneWithTransactions retrieves a user and their transactions