database

package
v0.0.0-...-7b0bed8 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BrokerCredentialsRepo

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

BrokerCredentialsRepo handles broker credentials operations in the database

func NewBrokerCredentialsRepo

func NewBrokerCredentialsRepo(db *DB) *BrokerCredentialsRepo

NewBrokerCredentialsRepo creates a new broker credentials repository

func (*BrokerCredentialsRepo) DeleteCredentials

func (r *BrokerCredentialsRepo) DeleteCredentials(userID string, brokerType string) error

DeleteCredentials deletes broker credentials from the database

func (*BrokerCredentialsRepo) GetAccessToken

func (r *BrokerCredentialsRepo) GetAccessToken(userID string, brokerType string) (string, error)

GetAccessToken retrieves the access token for a user's broker credentials

func (*BrokerCredentialsRepo) GetCredentials

func (r *BrokerCredentialsRepo) GetCredentials(userID string, brokerType string) (*models.Credentials, error)

GetCredentials retrieves broker credentials from the database

func (*BrokerCredentialsRepo) GetCredentialsForAllUsers

func (r *BrokerCredentialsRepo) GetCredentialsForAllUsers() ([]*models.Credentials, error)

GetCredentialsForAllUsers retrieves all broker credentials from the database

func (*BrokerCredentialsRepo) GetExpiredTokens

func (r *BrokerCredentialsRepo) GetExpiredTokens() ([]*models.Credentials, error)

GetExpiredTokens retrieves credentials with expired tokens

func (*BrokerCredentialsRepo) HasCredentials

func (r *BrokerCredentialsRepo) HasCredentials(userID string, brokerType string) (bool, error)

HasCredentials checks if the user has credentials for a specific broker

func (*BrokerCredentialsRepo) SaveCredentials

func (r *BrokerCredentialsRepo) SaveCredentials(userID string, brokerType string, apiKey string, apiSecret string, requestToken string, expiryTime time.Time) error

SaveCredentials saves broker credentials to the database

func (*BrokerCredentialsRepo) UpdateAccessToken

func (r *BrokerCredentialsRepo) UpdateAccessToken(userID string, brokerType string, accessToken string, expiryTime time.Time) error

UpdateAccessToken updates the access token and expiry time for broker credentials

type Config

type Config struct {
	ConnString string // PostgreSQL connection string
}

Config holds database configuration

type DB

type DB struct {
	*sql.DB
}

DB represents the database connection

func New

func New(config Config) (*DB, error)

New creates a new database connection

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection

type PortfolioRepo

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

PortfolioRepo handles portfolio operations in the database

func NewPortfolioRepo

func NewPortfolioRepo(db *DB) *PortfolioRepo

NewPortfolioRepo creates a new portfolio repository

func (*PortfolioRepo) GetHoldings

func (r *PortfolioRepo) GetHoldings(userID string) ([]models.Holding, error)

GetHoldings retrieves portfolio holdings for a user

func (*PortfolioRepo) GetHoldingsByType

func (r *PortfolioRepo) GetHoldingsByType(userID string, holdingType models.HoldingType) ([]models.Holding, error)

GetHoldingsByType retrieves portfolio holdings for a user filtered by holding type

func (*PortfolioRepo) GetPlatformHoldings

func (r *PortfolioRepo) GetPlatformHoldings(userID string, platform string) ([]models.Holding, error)

GetPlatformHoldings retrieves portfolio holdings for a user filtered by platform

func (*PortfolioRepo) GetPortfolioLastUpdated

func (r *PortfolioRepo) GetPortfolioLastUpdated(userID string) (time.Time, bool, error)

GetPortfolioLastUpdated gets the timestamp when the portfolio was last updated

func (*PortfolioRepo) SaveHoldings

func (r *PortfolioRepo) SaveHoldings(userID string, holdings []models.Holding) error

SaveHoldings saves portfolio holdings to the database for a user

type SessionRepo

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

SessionRepo handles session operations in the database

func NewSessionRepo

func NewSessionRepo(db *DB) *SessionRepo

NewSessionRepo creates a new session repository

func (*SessionRepo) CreateSession

func (r *SessionRepo) CreateSession(session *models.UserSession) error

CreateSession creates a new session in the database

func (*SessionRepo) DeleteSession

func (r *SessionRepo) DeleteSession(sessionID string) error

DeleteSession deletes a session from the database

func (*SessionRepo) GetSession

func (r *SessionRepo) GetSession(sessionID string) (*models.UserSession, error)

GetSession retrieves a session from the database

func (*SessionRepo) GetUserSession

func (r *SessionRepo) GetUserSession(userID string) (*models.UserSession, error)

GetUserSession retrieves a session by user ID from the database

func (*SessionRepo) UpdateLastAccessed

func (r *SessionRepo) UpdateLastAccessed(sessionID string) error

UpdateLastAccessed updates the last_accessed_at field for a session

type UserRepo

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

UserRepo handles user operations in the database

func NewUserRepo

func NewUserRepo(db *DB) *UserRepo

NewUserRepo creates a new user repository

func (*UserRepo) CreateUser

func (r *UserRepo) CreateUser(userID string, email string) error

CreateUser creates a new user in the database

func (*UserRepo) FindOrCreateUserByEmail

func (r *UserRepo) FindOrCreateUserByEmail(email string) (string, error)

FindOrCreateUserByEmail finds a user by email or creates one if not found

func (*UserRepo) GetUser

func (r *UserRepo) GetUser(userID string) (bool, error)

GetUser retrieves a user from the database

func (*UserRepo) GetUserByEmail

func (r *UserRepo) GetUserByEmail(email string) (string, bool, error)

GetUserByEmail checks if a user exists with the given email

func (*UserRepo) UpdateLastAccessed

func (r *UserRepo) UpdateLastAccessed(userID string) error

UpdateLastAccessed updates the last_accessed_at field for a user

Jump to

Keyboard shortcuts

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