accounts

package
v0.0.1-0...-104a2d1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound          = errors.New("accounts.not_found")
	ErrAccountTypeInvalid       = errors.New("accounts.account_invalid")
	ErrColorTypeInvalid         = errors.New("accounts.color_invalid")
	ErrAccountQueryParamInvalid = errors.New("accounts.invalid_start_date")
	ErrEndDateBeforeStart       = errors.New("accounts.end_before_start")
)

Functions

func RegisterHTTPHandlers

func RegisterHTTPHandlers(db *pgxpool.Pool, validate *validation.Validator, tkn *jwt.Service, openFinanceManager *finance.ProviderManager, scheduler *jobs.Service, logger *zerolog.Logger) http.Handler

Types

type AccountWithTrend

type AccountWithTrend struct {
	ID                uuid.UUID              `json:"id"`
	Name              string                 `json:"name"`
	Type              repository.ACCOUNTTYPE `json:"type"`
	Balance           pgtype.Numeric         `json:"balance"`
	Currency          string                 `json:"currency"`
	Color             repository.COLORENUM   `json:"color"`
	Meta              []byte                 `json:"meta"`
	UpdatedAt         time.Time              `json:"updated_at"`
	Trend             pgtype.Numeric         `json:"trend"`
	BalanceTimeseries []BalancePoint         `json:"balance_timeseries"`
	IsExternal        bool                   `json:"is_external"`
}

type BalancePoint

type BalancePoint struct {
	Date    time.Time `json:"date"`
	Balance float64   `json:"balance"`
}

type ConnectAccountRequest

type ConnectAccountRequest struct {
	Provider    string `json:"provider" validate:"required"`
	PublicToken string `json:"public_token" validate:"required"`
}

ConnectAccountRequest represents the request to connect an external account

type CreateAccountRequest

type CreateAccountRequest struct {
	Meta     *[]byte `json:"meta,omitempty" validate:"omitempty"`
	Name     string  `json:"name" validate:"required"`
	Type     string  `json:"type" validate:"required"`
	Currency string  `json:"currency" validate:"required"`
	Color    string  `json:"color" validate:"required"`
	Balance  float64 `json:"balance" validate:"gte=0"`
}

type CreateLinkTokenRequest

type CreateLinkTokenRequest struct {
	Provider     string   `json:"provider" validate:"required,oneof=plaid teller gocardless mono brankas"`
	Products     []string `json:"products,omitempty"`
	CountryCodes []string `json:"country_codes,omitempty"`
	RedirectURI  string   `json:"redirect_uri,omitempty"`
}

type FinancialSyncJob

type FinancialSyncJob struct {
	ID                 uuid.UUID  `json:"id" db:"id"`
	UserID             uuid.UUID  `json:"user_id" db:"user_id"`
	ConnectionID       uuid.UUID  `json:"connection_id" db:"connection_id"`
	ProviderName       string     `json:"provider_name" db:"provider_name"`
	JobType            string     `json:"job_type" db:"job_type"`
	Status             string     `json:"status" db:"status"`
	StartedAt          *time.Time `json:"started_at" db:"started_at"`
	CompletedAt        *time.Time `json:"completed_at" db:"completed_at"`
	ErrorMessage       *string    `json:"error_message" db:"error_message"`
	AccountsSynced     int        `json:"accounts_synced" db:"accounts_synced"`
	TransactionsSynced int        `json:"transactions_synced" db:"transactions_synced"`
	CreatedAt          time.Time  `json:"created_at" db:"created_at"`
}

type Handler

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

func NewHandler

func NewHandler(validator *validation.Validator, db *pgxpool.Pool, repo Repository, openFinanceManager *finance.ProviderManager, scheduler *jobs.Service, logger *zerolog.Logger) *Handler

func (*Handler) CreateAccount

func (h *Handler) CreateAccount(w http.ResponseWriter, r *http.Request)

func (*Handler) DeleteAccount

func (h *Handler) DeleteAccount(w http.ResponseWriter, r *http.Request)

Delete an account

func (*Handler) GetAccount

func (h *Handler) GetAccount(w http.ResponseWriter, r *http.Request)

func (*Handler) GetAccountBTimeline

func (h *Handler) GetAccountBTimeline(w http.ResponseWriter, r *http.Request)

func (*Handler) GetAccounts

func (h *Handler) GetAccounts(w http.ResponseWriter, r *http.Request)

func (*Handler) GetAccountsBTimeline

func (h *Handler) GetAccountsBTimeline(w http.ResponseWriter, r *http.Request)

func (*Handler) GetAccountsTrends

func (h *Handler) GetAccountsTrends(w http.ResponseWriter, r *http.Request)

func (*Handler) MonoConnect

func (h *Handler) MonoConnect(w http.ResponseWriter, r *http.Request)

func (*Handler) TellerConnect

func (h *Handler) TellerConnect(w http.ResponseWriter, r *http.Request)

func (*Handler) UpdateAccount

func (h *Handler) UpdateAccount(w http.ResponseWriter, r *http.Request)

type MonoConnectRequest

type MonoConnectRequest struct {
	Code string `json:"code" validate:"required"`
}

type Repository

type Repository interface {
	// GetAccounts retrieves all accounts for a specific user
	GetAccounts(ctx context.Context, userID uuid.UUID) ([]repository.GetAccountsRow, error)
	// GetAccountByID retrieves a specific account by its ID
	GetAccountByID(ctx context.Context, id uuid.UUID) (repository.GetAccountByIdRow, error)
	// CreateAccount creates a new account
	CreateAccount(ctx context.Context, account repository.CreateAccountParams) (repository.Account, error)
	CreateAccountWInitalTrs(ctx context.Context, act repository.CreateAccountParams) (repository.Account, error)

	// UpdateAccount updates an existing account
	UpdateAccount(ctx context.Context, account repository.UpdateAccountParams) (repository.Account, error)
	// DeleteAccount marks an account as deleted
	DeleteAccount(ctx context.Context, id uuid.UUID) error
	// UpdateAccountBalance updates just the balance of an account
	UpdateAccountBalance(ctx context.Context, id uuid.UUID, amount pgtype.Numeric) error

	// GetAccountsBTimeline
	GetAccountsBTimeline(ctx context.Context, userID *uuid.UUID) ([]repository.GetAccountsBalanceTimelineRow, error)
	GetAccountBTimeline(ctx context.Context, id uuid.UUID) ([]repository.GetAccountBalanceTimelineRow, error)
	GetAccountsTrends(ctx context.Context, userID *uuid.UUID, startTime time.Time, endTime time.Time) ([]AccountWithTrend, error)

	// Connection management
	CreateConnection(ctx context.Context, params repository.CreateConnectionParams) (repository.UserFinancialConnection, error)
	GetConnectionByID(ctx context.Context, id uuid.UUID) (repository.UserFinancialConnection, error)
	GetConnectionsByUserID(ctx context.Context, userID uuid.UUID) ([]repository.UserFinancialConnection, error)
	GetConnectionByProviderItemID(ctx context.Context, params repository.GetConnectionByProviderItemIDParams) (repository.UserFinancialConnection, error)
	UpdateConnection(ctx context.Context, params repository.UpdateConnectionParams) (repository.UserFinancialConnection, error)
	DeleteConnection(ctx context.Context, params repository.DeleteConnectionParams) error
	SetConnectionSyncStatus(ctx context.Context, params repository.SetConnectionSyncStatusParams) (repository.UserFinancialConnection, error)
	SetConnectionErrorStatus(ctx context.Context, params repository.SetConnectionErrorStatusParams) (repository.UserFinancialConnection, error)
	ListConnections(ctx context.Context, params repository.ListConnectionsParams) ([]repository.UserFinancialConnection, error)
}

Repository defines the interface for account data operations

func NewRepository

func NewRepository(queries *repository.Queries, db *pgxpool.Pool) Repository

NewRepository creates a new account repository

type SyncAccountsRequest

type SyncAccountsRequest struct {
	Provider string `json:"provider" validate:"required"`
	Force    bool   `json:"force,omitempty"` // Force sync even if recently synced
}

SyncAccountsRequest represents the request to sync accounts from a provider

type TellerConnectRequest

type TellerConnectRequest struct {
	AccessToken string `json:"accessToken" validate:"required"`
	Enrollment  struct {
		ID          string `json:"id"`
		Institution struct {
			ID   string `json:"id"`
			Name string `json:"name"`
		} `json:"institution"`
	} `json:"enrollment"`
	User struct {
		ID string `json:"id"`
	} `json:"user"`
}

type UpdateAccountRequest

type UpdateAccountRequest struct {
	Name     *string  `json:"name" validate:"required"`
	Type     *string  `json:"type" validate:"required"`
	Balance  *float64 `json:"balance" validate:"required"`
	Currency *string  `json:"currency" validate:"required"`
	Color    *string  `json:"color" validate:"required"`
	Meta     *[]byte  `json:"meta,omitempty" validate:"omitempty"`
}

type UserFinancialConnection

type UserFinancialConnection struct {
	ID                   uuid.UUID  `json:"id" db:"id"`
	UserID               uuid.UUID  `json:"user_id" db:"user_id"`
	ProviderName         string     `json:"provider_name" db:"provider_name"`
	AccessTokenEncrypted string     `json:"-" db:"access_token_encrypted"` // Never expose in JSON
	ItemID               *string    `json:"item_id" db:"item_id"`
	InstitutionID        *string    `json:"institution_id" db:"institution_id"`
	InstitutionName      *string    `json:"institution_name" db:"institution_name"`
	Status               string     `json:"status" db:"status"`
	LastSyncAt           *time.Time `json:"last_sync_at" db:"last_sync_at"`
	ExpiresAt            *time.Time `json:"expires_at" db:"expires_at"`
	CreatedAt            time.Time  `json:"created_at" db:"created_at"`
	UpdatedAt            time.Time  `json:"updated_at" db:"updated_at"`
}

Jump to

Keyboard shortcuts

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