Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidAmount indicates the monetary amount is invalid (e.g., negative or zero). ErrInvalidAmount = errors.New("amount must be greater than zero") // ErrInvalidDuration indicates the loan duration is invalid. ErrInvalidDuration = errors.New("duration must be between 1 and 120 months") // ErrApplicationNotPending indicates an operation was attempted on a non-pending application. ErrApplicationNotPending = errors.New("loan application is not in a pending state") // ErrOfferExpired indicates an attempt to accept an expired offer. ErrOfferExpired = errors.New("loan offer has expired") // ErrOfferNotAvailable indicates the offer is no longer available for acceptance. ErrOfferNotAvailable = errors.New("loan offer is not in a generated state") )
Functions ¶
This section is empty.
Types ¶
type ApplicationStatus ¶
type ApplicationStatus string
ApplicationStatus represents the lifecycle state of a LoanApplication.
const ( ApplicationStatusPending ApplicationStatus = "PENDING" ApplicationStatusUnderReview ApplicationStatus = "UNDER_REVIEW" ApplicationStatusApproved ApplicationStatus = "APPROVED" ApplicationStatusRejected ApplicationStatus = "REJECTED" ApplicationStatusCancelled ApplicationStatus = "CANCELLED" )
type LoanApplication ¶
type LoanApplication struct {
ID uuid.UUID `json:"id"`
BorrowerID uuid.UUID `json:"borrower_id"`
RequestedAmount Money `json:"requested_amount"`
DurationMonths int `json:"duration_months"`
Purpose string `json:"purpose"`
Status ApplicationStatus `json:"status"`
Metadata map[string]string `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
LoanApplication is the aggregate root representing a user's request for a loan.
func NewLoanApplication ¶
func NewLoanApplication(borrowerID uuid.UUID, amount int64, currency string, durationMonths int, purpose string) (*LoanApplication, error)
NewLoanApplication creates a new LoanApplication with initial validation.
func (*LoanApplication) Approve ¶
func (la *LoanApplication) Approve()
Approve marks the application as approved.
func (*LoanApplication) Reject ¶
func (la *LoanApplication) Reject()
Reject marks the application as rejected.
func (*LoanApplication) Review ¶
func (la *LoanApplication) Review() error
Review transitions the application to the UnderReview state.
type LoanOffer ¶
type LoanOffer struct {
ID uuid.UUID `json:"id"`
ApplicationID uuid.UUID `json:"application_id"`
Principal Money `json:"principal"`
InterestRateBps int64 `json:"interest_rate_bps"` // Basis Points (e.g., 500 = 5.00%)
TermMonths int `json:"term_months"`
MonthlyPayment Money `json:"monthly_payment"`
TotalRepayment Money `json:"total_repayment"`
Status OfferStatus `json:"status"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
LoanOffer represents a formal offer extended to the borrower based on an application.
func NewLoanOffer ¶
func NewLoanOffer(appID uuid.UUID, principal Money, rateBps int64, term int, monthlyPayment Money, totalRepayment Money, validityDuration time.Duration) *LoanOffer
NewLoanOffer creates a new offer for a specific application.
type Money ¶
type Money struct {
Amount int64 `json:"amount"` // Amount in minor units (e.g., cents)
Currency string `json:"currency"` // ISO 4217 Currency Code (e.g., "USD")
}
Money represents a monetary value safely using integer math for minor units.
type OfferStatus ¶
type OfferStatus string
OfferStatus represents the lifecycle state of a LoanOffer.
const ( OfferStatusGenerated OfferStatus = "GENERATED" OfferStatusAccepted OfferStatus = "ACCEPTED" OfferStatusRejected OfferStatus = "REJECTED" OfferStatusExpired OfferStatus = "EXPIRED" )