Documentation
¶
Index ¶
- Variables
- func RegisterHTTPHandlers(db *pgxpool.Pool, validate *validation.Validator, tkn *jwt.Service, ...) http.Handler
- type Attachment
- type AttachmentDownloadResponse
- type AttachmentUploadResponse
- type CreateMerchantRequest
- type CreateTagRequest
- type CreateTransactionRequest
- type CreateTransactionSplit
- type CreateTransfertRequest
- type Currency
- type Details
- type EnhancedTransaction
- type ExchangeRate
- type Group
- type Handler
- func (h *Handler) CreateTransaction(w http.ResponseWriter, r *http.Request)
- func (h *Handler) CreateTransfert(w http.ResponseWriter, r *http.Request)
- func (h *Handler) DeleteTransaction(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetTransaction(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetTransactions(w http.ResponseWriter, r *http.Request)
- func (h *Handler) UpdateTransaction(w http.ResponseWriter, r *http.Request)
- type LocationData
- type Merchant
- type Repository
- type SubTransaction
- type Tag
- type Transaction
- type TransactionResponse
- type TransactionSplit
- type TransactionTag
- type TransfertParams
- type Trsrepo
- func (r *Trsrepo) CreateTransaction(ctx context.Context, params repository.CreateTransactionParams) (repository.Transaction, error)
- func (r *Trsrepo) CreateTransactionClean(ctx context.Context, params repository.CreateTransactionParams) (repository.Transaction, error)
- func (r *Trsrepo) CreateTransfertTransaction(ctx context.Context, params TransfertParams) (repository.Transaction, error)
- func (r *Trsrepo) DeleteTransaction(ctx context.Context, id uuid.UUID) error
- func (r *Trsrepo) GetTransaction(ctx context.Context, id uuid.UUID) (repository.Transaction, error)
- func (r *Trsrepo) GetTransactions(ctx context.Context, params repository.ListTransactionsParams) ([]Group, error)
- func (r *Trsrepo) UpdateTransaction(ctx context.Context, params repository.UpdateTransactionParams) (repository.Transaction, error)
- type UploadAttachmentRequest
Constants ¶
This section is empty.
Variables ¶
var ErrDestAccNotFound = errors.New("destination account not found")
var ErrLowBalance = errors.New("insufficent balance")
var ErrNoTransactions = errors.New("no transaction with given ID")
var ErrSameAccount = errors.New("source and destination accounts cannot be the same")
var ErrSrcAccNotFound = errors.New("source account not found")
Functions ¶
Types ¶
type Attachment ¶
type Attachment struct {
ID uuid.UUID `json:"id" db:"id"`
TransactionID uuid.UUID `json:"transaction_id" db:"transaction_id"`
Filename string `json:"filename" db:"filename"`
OriginalFilename string `json:"original_filename" db:"original_filename"`
FileSize int64 `json:"file_size" db:"file_size"`
MimeType string `json:"mime_type" db:"mime_type"`
StorageKey string `json:"storage_key" db:"storage_key"`
BucketName string `json:"bucket_name" db:"bucket_name"`
IsEncrypted bool `json:"is_encrypted" db:"is_encrypted"`
EncryptionKeyID *string `json:"encryption_key_id,omitempty" db:"encryption_key_id"`
UploadedBy uuid.UUID `json:"uploaded_by" db:"uploaded_by"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
// Computed fields
PresignedURL *string `json:"presigned_url,omitempty"` // Temporary download URL
}
Attachment represents a file attached to a transaction
type CreateMerchantRequest ¶
type CreateMerchantRequest struct {
Name string `json:"name" validate:"required,min=1,max=255"`
Category *string `json:"category,omitempty"`
Website *string `json:"website,omitempty" validate:"omitempty,url"`
Phone *string `json:"phone,omitempty"`
Address *Details `json:"address,omitempty"`
LogoURL *string `json:"logo_url,omitempty" validate:"omitempty,url"`
}
type CreateTagRequest ¶
type CreateTransactionRequest ¶
type CreateTransactionRequest struct {
TransactionDatetime time.Time `json:"transaction_datetime"`
Description *string `json:"description"`
Type string `json:"type"`
AccountID string `json:"account_id"`
CategoryID string `json:"category_id"`
Details dto.Details `json:"details"`
Amount float64 `json:"amount"`
}
type CreateTransactionSplit ¶
type CreateTransfertRequest ¶
type CreateTransfertRequest struct {
TransactionDatetime time.Time `json:"transaction_datetime"`
Description *string `json:"description"`
Type string `json:"type"`
AccountID string `json:"account_id"`
DestinationAccountID string `json:"destination_account_id"`
CategoryID string `json:"category_id"`
Details dto.Details `json:"details"`
Amount float64 `json:"amount"`
}
type Currency ¶
type Currency struct {
Code string `json:"code" db:"code"`
Name string `json:"name" db:"name"`
Symbol *string `json:"symbol,omitempty" db:"symbol"`
DecimalPlaces int `json:"decimal_places" db:"decimal_places"`
IsActive bool `json:"is_active" db:"is_active"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
Currency represents a currency with exchange rate information
type Details ¶
type Details struct {
PaymentMedium string `json:"payment_medium"` // credit_card, debit_card, cash, check, etc.
Location string `json:"location"`
Note string `json:"note"`
PaymentStatus string `json:"payment_status"` // pending, completed, failed, cancelled
CardLastFour string `json:"card_last_four,omitempty"`
AuthorizationCode string `json:"authorization_code,omitempty"`
MerchantCategoryCode string `json:"merchant_category_code,omitempty"` // MCC code
RewardsEarned *decimal.Decimal `json:"rewards_earned,omitempty"`
ReceiptNumber string `json:"receipt_number,omitempty"`
TipAmount *decimal.Decimal `json:"tip_amount,omitempty"`
TaxAmount *decimal.Decimal `json:"tax_amount,omitempty"`
DiscountAmount *decimal.Decimal `json:"discount_amount,omitempty"`
InvoiceNumber string `json:"invoice_number,omitempty"`
ProjectCode string `json:"project_code,omitempty"` // For business expense tracking
ClientName string `json:"client_name,omitempty"`
SubTransactions []SubTransaction `json:"sub_transactions,omitempty"` // For itemized receipts
}
Enhanced Details struct with more comprehensive transaction metadata
type EnhancedTransaction ¶
type EnhancedTransaction struct {
repository.ListTransactionsRow
DestinationAccount *repository.GetAccountsRow `json:"destination_account,omitempty"`
}
type ExchangeRate ¶
type ExchangeRate struct {
ID uuid.UUID `json:"id" db:"id"`
FromCurrency string `json:"from_currency" db:"from_currency"`
ToCurrency string `json:"to_currency" db:"to_currency"`
Rate decimal.Decimal `json:"rate" db:"rate"`
RateDate time.Time `json:"rate_date" db:"rate_date"`
Source *string `json:"source,omitempty" db:"source"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
ExchangeRate represents historical exchange rates
type Group ¶
type Group struct {
ID string `json:"id"`
Date string `json:"date"` // e.g., "October 19 2029 - 2"
Total float64 `json:"total"` // e.g., "$700.00"
Transactions []EnhancedTransaction `json:"transactions"`
}
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func NewHandler(validator *validation.Validator, repo Repository, logger *zerolog.Logger) *Handler
func (*Handler) CreateTransaction ¶
func (h *Handler) CreateTransaction(w http.ResponseWriter, r *http.Request)
func (*Handler) CreateTransfert ¶
func (h *Handler) CreateTransfert(w http.ResponseWriter, r *http.Request)
func (*Handler) DeleteTransaction ¶
func (h *Handler) DeleteTransaction(w http.ResponseWriter, r *http.Request)
func (*Handler) GetTransaction ¶
func (h *Handler) GetTransaction(w http.ResponseWriter, r *http.Request)
func (*Handler) GetTransactions ¶
func (h *Handler) GetTransactions(w http.ResponseWriter, r *http.Request)
func (*Handler) UpdateTransaction ¶
func (h *Handler) UpdateTransaction(w http.ResponseWriter, r *http.Request)
type LocationData ¶
type LocationData struct {
Latitude *float64 `json:"latitude,omitempty"`
Longitude *float64 `json:"longitude,omitempty"`
Address string `json:"address,omitempty"`
City string `json:"city,omitempty"`
State string `json:"state,omitempty"`
Country string `json:"country,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
PlaceID string `json:"place_id,omitempty"` // Google Places ID
Accuracy *float64 `json:"accuracy,omitempty"` // GPS accuracy in meters
}
LocationData for GPS and address information
func (*LocationData) Scan ¶
func (ld *LocationData) Scan(value interface{}) error
type Merchant ¶
type Merchant struct {
ID uuid.UUID `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Category *string `json:"category,omitempty" db:"category"`
Website *string `json:"website,omitempty" db:"website"`
Phone *string `json:"phone,omitempty" db:"phone"`
Address *Details `json:"address,omitempty" db:"address"` // Reuse Details for address structure
LogoURL *string `json:"logo_url,omitempty" db:"logo_url"`
CreatedBy *uuid.UUID `json:"created_by,omitempty" db:"created_by"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
DeletedAt *time.Time `json:"deleted_at,omitempty" db:"deleted_at"`
}
Merchant represents a business or vendor
type Repository ¶
type Repository interface {
// Transaction operations
GetTransactions(ctx context.Context, params repository.ListTransactionsParams) ([]Group, error)
GetTransaction(ctx context.Context, id uuid.UUID) (repository.Transaction, error)
CreateTransaction(ctx context.Context, params repository.CreateTransactionParams) (repository.Transaction, error)
CreateTransfertTransaction(ctx context.Context, params TransfertParams) (repository.Transaction, error)
UpdateTransaction(ctx context.Context, params repository.UpdateTransactionParams) (repository.Transaction, error)
DeleteTransaction(ctx context.Context, id uuid.UUID) error
}
func NewRepository ¶
func NewRepository(db *pgxpool.Pool, queries *repository.Queries) Repository
type SubTransaction ¶
type SubTransaction struct {
Description string `json:"description"`
Amount decimal.Decimal `json:"amount"`
Quantity int `json:"quantity,omitempty"`
UnitPrice *decimal.Decimal `json:"unit_price,omitempty"`
Category string `json:"category,omitempty"`
}
SubTransaction for itemized receipts
type Tag ¶
type Tag struct {
ID uuid.UUID `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Color *string `json:"color,omitempty" db:"color"`
Icon *string `json:"icon,omitempty" db:"icon"`
UserID uuid.UUID `json:"user_id" db:"user_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
Tag represents a user-defined tag for categorization
type Transaction ¶
type Transaction struct {
ID uuid.UUID `json:"id" db:"id"`
Amount decimal.Decimal `json:"amount" db:"amount"`
Type string `json:"type" db:"type"`
AccountID uuid.UUID `json:"account_id" db:"account_id"`
CategoryID uuid.UUID `json:"category_id" db:"category_id"`
DestinationAccountID *uuid.UUID `json:"destination_account_id,omitempty" db:"destination_account_id"`
MerchantID *uuid.UUID `json:"merchant_id,omitempty" db:"merchant_id"`
Payee *string `json:"payee,omitempty" db:"payee"`
CurrencyCode string `json:"currency_code" db:"currency_code"`
ExchangeRate *decimal.Decimal `json:"exchange_rate,omitempty" db:"exchange_rate"`
BaseCurrencyAmount *decimal.Decimal `json:"base_currency_amount,omitempty" db:"base_currency_amount"`
LocationData *LocationData `json:"location_data,omitempty" db:"location_data"`
RecurringTransactionID *uuid.UUID `json:"recurring_transaction_id,omitempty" db:"recurring_transaction_id"`
ExternalTransactionID *string `json:"external_transaction_id,omitempty" db:"external_transaction_id"`
ReferenceNumber *string `json:"reference_number,omitempty" db:"reference_number"`
TaxDeductible bool `json:"tax_deductible" db:"tax_deductible"`
BusinessExpense bool `json:"business_expense" db:"business_expense"`
SplitTransactionGroupID *uuid.UUID `json:"split_transaction_group_id,omitempty" db:"split_transaction_group_id"`
TransactionDatetime time.Time `json:"transaction_datetime" db:"transaction_datetime"`
Description *string `json:"description,omitempty" db:"description"`
Details *Details `json:"details,omitempty" db:"details"`
CreatedBy *uuid.UUID `json:"created_by,omitempty" db:"created_by"`
UpdatedBy *uuid.UUID `json:"updated_by,omitempty" db:"updated_by"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
DeletedAt *time.Time `json:"deleted_at,omitempty" db:"deleted_at"`
// Related data that can be loaded with joins
Merchant *Merchant `json:"merchant,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
Splits []TransactionSplit `json:"splits,omitempty"`
}
Enhanced Transaction struct
type TransactionResponse ¶
type TransactionResponse struct {
*Transaction
Currency *Currency `json:"currency,omitempty"`
}
Response structs for API
type TransactionSplit ¶
type TransactionSplit struct {
ID uuid.UUID `json:"id" db:"id"`
ParentTransactionID uuid.UUID `json:"parent_transaction_id" db:"parent_transaction_id"`
CategoryID uuid.UUID `json:"category_id" db:"category_id"`
Amount decimal.Decimal `json:"amount" db:"amount"`
Description *string `json:"description,omitempty" db:"description"`
Percentage *decimal.Decimal `json:"percentage,omitempty" db:"percentage"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
TransactionSplit for splitting transactions across categories
type TransactionTag ¶
type TransactionTag struct {
TransactionID uuid.UUID `json:"transaction_id" db:"transaction_id"`
TagID uuid.UUID `json:"tag_id" db:"tag_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
TransactionTag represents the many-to-many relationship
type TransfertParams ¶
type TransfertParams struct {
Amount float64
Type string
AccountID uuid.UUID
DestinationAccountID uuid.UUID
CategoryID uuid.UUID
Description *string
TransactionDatetime time.Time
Details dto.Details
UserID uuid.UUID
}
TransfertParams holds parameters for creating a transfer transaction
type Trsrepo ¶
type Trsrepo struct {
DB *pgxpool.Pool
Queries *repository.Queries
}
func (*Trsrepo) CreateTransaction ¶
func (r *Trsrepo) CreateTransaction(ctx context.Context, params repository.CreateTransactionParams) (repository.Transaction, error)
CreateTransaction creates a new transaction
func (*Trsrepo) CreateTransactionClean ¶
func (r *Trsrepo) CreateTransactionClean(ctx context.Context, params repository.CreateTransactionParams) (repository.Transaction, error)
func (*Trsrepo) CreateTransfertTransaction ¶
func (r *Trsrepo) CreateTransfertTransaction(ctx context.Context, params TransfertParams) (repository.Transaction, error)
CreateTransfertTransaction handles the creation of a transfer transaction between accounts
func (*Trsrepo) DeleteTransaction ¶
DeleteTransaction deletes a transaction
func (*Trsrepo) GetTransaction ¶
func (r *Trsrepo) GetTransaction(ctx context.Context, id uuid.UUID) (repository.Transaction, error)
GetTransaction retrieves a specific transaction by its ID
func (*Trsrepo) GetTransactions ¶
func (r *Trsrepo) GetTransactions(ctx context.Context, params repository.ListTransactionsParams) ([]Group, error)
func (*Trsrepo) UpdateTransaction ¶
func (r *Trsrepo) UpdateTransaction(ctx context.Context, params repository.UpdateTransactionParams) (repository.Transaction, error)
UpdateTransaction updates an existing transaction