|
|
@@ -10,6 +10,9 @@ import ( |
|
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
|
"fmt" |
|
|
|
"encoding/json" |
|
|
|
// "io" |
|
|
|
"strconv" |
|
|
|
"bytes" |
|
|
|
) |
|
|
|
|
|
|
|
type Page struct { |
|
|
@@ -19,7 +22,7 @@ type Page struct { |
|
|
|
} |
|
|
|
|
|
|
|
type LoanType struct { |
|
|
|
Id int `json:"id"` |
|
|
|
Id int `json:"id"` |
|
|
|
User int `json:"user"` |
|
|
|
Branch int `json:"branch"` |
|
|
|
Name string `json:"name"` |
|
|
@@ -39,21 +42,33 @@ type FeeTemplate struct { |
|
|
|
} |
|
|
|
|
|
|
|
type Estimate struct { |
|
|
|
Id int `json:"id"` |
|
|
|
Id int `json:"id"` |
|
|
|
User int `json:"user"` |
|
|
|
Borrower int `json:"borrower"` |
|
|
|
Borrower Borrower `json:"borrower"` |
|
|
|
Comparison int `json:"comparison"` |
|
|
|
Transaction int `json:"transaction"` |
|
|
|
LoanType LoanType `json:"loanType"` |
|
|
|
Transaction string `json:"transaction"` |
|
|
|
LoanType LoanType `json:"loanType"` |
|
|
|
LoanAmount int `json:"loanAmount"` |
|
|
|
Price int `json:"price"` |
|
|
|
Property string `json:"property"` |
|
|
|
Pud bool `json:"pud"` |
|
|
|
Occupancy string `json:"occupancy"` |
|
|
|
Zip string `json:"zip"` |
|
|
|
Pud bool `json:"pud"` |
|
|
|
Term int `json:"term"` |
|
|
|
Interest int `json:"interest"` |
|
|
|
Hoi int `json:"hoi"` |
|
|
|
Hoi int `json:"hoi"` |
|
|
|
MiName string `json:"miName"` |
|
|
|
MiAmount int `json:"miAmount"` |
|
|
|
Lender string `json:"lender"` |
|
|
|
Name string `json:"name"` |
|
|
|
Fees []Fee `json:"fees"` |
|
|
|
} |
|
|
|
|
|
|
|
type Borrower struct { |
|
|
|
Id int `json:"id"` |
|
|
|
Credit int `json:"credit"` |
|
|
|
Income int `json:"income"` |
|
|
|
Num int `json:"num"` |
|
|
|
} |
|
|
|
|
|
|
|
var ( |
|
|
@@ -147,17 +162,53 @@ func getLoanType( |
|
|
|
return loans, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getEstimate(db *sql.DB, id int) (Estimate, error) { |
|
|
|
var estimate Estimate |
|
|
|
|
|
|
|
row := db.QueryRow( |
|
|
|
"SELECT * FROM estimate " + |
|
|
|
"WHERE id = ? LIMIT 1", |
|
|
|
id) |
|
|
|
|
|
|
|
if err := row.Scan( |
|
|
|
&estimate.Id, |
|
|
|
&estimate.User, |
|
|
|
&estimate.Borrower.Id, |
|
|
|
&estimate.Comparison, |
|
|
|
&estimate.Transaction, |
|
|
|
&estimate.LoanType.Id, |
|
|
|
&estimate.LoanAmount, |
|
|
|
&estimate.Price, |
|
|
|
&estimate.Property, |
|
|
|
&estimate.Occupancy, |
|
|
|
&estimate.Zip, |
|
|
|
&estimate.Pud, |
|
|
|
&estimate.Term, |
|
|
|
&estimate.Interest, |
|
|
|
&estimate.Hoi, |
|
|
|
&estimate.MiName, |
|
|
|
&estimate.MiAmount, |
|
|
|
&estimate.Lender, |
|
|
|
&estimate.Name, |
|
|
|
) |
|
|
|
err != nil { |
|
|
|
return estimate, fmt.Errorf("Estimate scanning error: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
return estimate, nil |
|
|
|
} |
|
|
|
|
|
|
|
// Fetch fees from the database |
|
|
|
func getFees(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
|
var fees []FeeTemplate |
|
|
|
|
|
|
|
// Should be changed to specify user |
|
|
|
rows, err := db.Query( |
|
|
|
"SELECT * FROM fee_template " + |
|
|
|
"WHERE user_id = ? OR user_id = 0", |
|
|
|
user) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("Fee error %v", err) |
|
|
|
return nil, fmt.Errorf("Fee query error %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
defer rows.Close() |
|
|
@@ -177,16 +228,113 @@ func getFees(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
|
&fee.Category, |
|
|
|
&fee.Auto) |
|
|
|
err != nil { |
|
|
|
return nil, fmt.Errorf("The fees %q: %v", user, err) |
|
|
|
return nil, fmt.Errorf("Fees scanning error: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
fees = append(fees, fee) |
|
|
|
} |
|
|
|
|
|
|
|
est, err := getEstimate(db, 1) |
|
|
|
fmt.Printf("the estimate: %v,\nthe error %v\n", est, err) |
|
|
|
// getMi(db, getEstimate(db, 1), getBorrower(db, 1)) |
|
|
|
|
|
|
|
return fees, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getMi(db *sql.DB, ) |
|
|
|
func getBorrower(db *sql.DB, id int) (Borrower, error) { |
|
|
|
var borrower Borrower |
|
|
|
|
|
|
|
row := db.QueryRow( |
|
|
|
"SELECT * FROM borrower " + |
|
|
|
"WHERE id = ? LIMIT 1", |
|
|
|
id) |
|
|
|
|
|
|
|
if err := row.Scan( |
|
|
|
&borrower.Id, |
|
|
|
&borrower.Credit, |
|
|
|
&borrower.Income, |
|
|
|
&borrower.Num, |
|
|
|
) |
|
|
|
err != nil { |
|
|
|
return borrower, fmt.Errorf("Borrower scanning error: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
return borrower, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getMi(db *sql.DB, estimate Estimate, borrower Borrower) { |
|
|
|
// body := map[string]string{ |
|
|
|
// "zipCode": estimate.Zip, |
|
|
|
// // "stateCode": "CA", |
|
|
|
// // "address": "", |
|
|
|
// "propertyTypeCode": "SFO", |
|
|
|
// "occupancyTypeCode": "PRS", |
|
|
|
// "loanPurposeCode": "PUR", |
|
|
|
// "loanAmount": "1000000", |
|
|
|
// "loanToValue": "LTV95", |
|
|
|
// "amortizationTerm": "A30", |
|
|
|
// "loanTypeCode": "FXD", |
|
|
|
// "duLpDecisionCode": "DAE", |
|
|
|
// "loanProgramCodes": [], |
|
|
|
// "debtToIncome": "5", |
|
|
|
// "wholesaleLoan": 0, |
|
|
|
// "coveragePercentageCode": "L30", |
|
|
|
// "productCode": "BPM", |
|
|
|
// "renewalTypeCode": "CON", |
|
|
|
// "numberOfBorrowers": 1, |
|
|
|
// "coBorrowerCreditScores": [], |
|
|
|
// "borrowerCreditScore": "740", |
|
|
|
// "masterPolicy": null, |
|
|
|
// "selfEmployedIndicator": false, |
|
|
|
// "armType": "", |
|
|
|
// "userId": 44504 |
|
|
|
// } |
|
|
|
|
|
|
|
var propertyCodes = map[string]string { |
|
|
|
"Single Family Attached": "SFO", |
|
|
|
"Single Family Detached": "SFO", |
|
|
|
"Condominium Lo-rise": "CON", |
|
|
|
"Condominium Hi-rise": "CON", |
|
|
|
} |
|
|
|
|
|
|
|
/* var occupancyCodes = map[string]string { |
|
|
|
"Primary Residence": "PRS", |
|
|
|
"Second Home": "SCH", |
|
|
|
"Condominium Lo-rise": "CON", |
|
|
|
"Condominium Hi-rise": "CON", |
|
|
|
} */ |
|
|
|
|
|
|
|
body, _ := json.Marshal(map[string]any{ |
|
|
|
"zipCode": estimate.Zip, |
|
|
|
// "stateCode": "CA", |
|
|
|
// "address": "", |
|
|
|
"propertyTypeCode": propertyCodes[estimate.Property], |
|
|
|
"occupancyTypeCode": "PRS", |
|
|
|
"loanPurposeCode": "PUR", |
|
|
|
"loanAmount": strconv.Itoa(estimate.LoanAmount / 100), |
|
|
|
"loanToValue": "LTV95", |
|
|
|
"amortizationTerm": "A30", |
|
|
|
"loanTypeCode": "FXD", |
|
|
|
"duLpDecisionCode": "DAE", |
|
|
|
"debtToIncome": 5, |
|
|
|
"wholesaleLoan": 0, |
|
|
|
"coveragePercentageCode": "L30", |
|
|
|
"productCode": "BPM", |
|
|
|
"renewalTypeCode": "CON", |
|
|
|
"numberOfBorrowers": 1, |
|
|
|
"borrowerCreditScore": strconv.Itoa(borrower.Credit), |
|
|
|
"masterPolicy": nil, |
|
|
|
"selfEmployedIndicator": false, |
|
|
|
"armType": "", |
|
|
|
"userId": 44504, |
|
|
|
}) |
|
|
|
log.Println(bytes.NewBuffer(body)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func validateEstimate() { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func route(w http.ResponseWriter, r *http.Request) { |
|
|
|
var page Page |
|
|
@@ -252,6 +400,7 @@ func api(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
func main() { |
|
|
|
files := http.FileServer(http.Dir("")) |
|
|
|
|
|
|
|
|
|
|
|
http.Handle("/assets/", files) |
|
|
|
http.HandleFunc("/api/", api) |
|
|
|