|
@@ -69,16 +69,22 @@ type Loan struct { |
|
|
Dti float32 `json:"dti"` |
|
|
Dti float32 `json:"dti"` |
|
|
Hoi int `json:"hoi"` |
|
|
Hoi int `json:"hoi"` |
|
|
Interest int `json:"interest"` |
|
|
Interest int `json:"interest"` |
|
|
Lender string `json:"lender"` |
|
|
|
|
|
MiName string `json:"miName"` |
|
|
|
|
|
MiAmount int `json:"miAmount"` |
|
|
|
|
|
Mi map[string]interface{} `json:"mi"` |
|
|
|
|
|
|
|
|
Mi MI `json:"mi"` |
|
|
Fees []Fee `json:"fees"` |
|
|
Fees []Fee `json:"fees"` |
|
|
Name string `json:"name"` |
|
|
Name string `json:"name"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type MI struct { |
|
|
type MI struct { |
|
|
Id int |
|
|
|
|
|
|
|
|
Type string |
|
|
|
|
|
Label string |
|
|
|
|
|
Lender string |
|
|
|
|
|
Rate float32 |
|
|
|
|
|
Premium float32 |
|
|
|
|
|
Upfront float32 |
|
|
|
|
|
FiveYearTotal float32 |
|
|
|
|
|
InitialAllInPremium float32 |
|
|
|
|
|
InitialAllInRate float32 |
|
|
|
|
|
InitialAmount float32 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type Estimate struct { |
|
|
type Estimate struct { |
|
@@ -299,12 +305,41 @@ func getFeesTemp(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
return fees, nil |
|
|
return fees, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getMi(db *sql.DB, loan int) (MI, error) { |
|
|
|
|
|
var mi MI |
|
|
|
|
|
|
|
|
|
|
|
query := `SELECT |
|
|
|
|
|
type, label, lender, rate, premium, upfront, five_year_total, |
|
|
|
|
|
initial_premium, initial_rate, initial_amount |
|
|
|
|
|
FROM mi WHERE loan_id = ?` |
|
|
|
|
|
|
|
|
|
|
|
row := db.QueryRow(query, loan) |
|
|
|
|
|
|
|
|
|
|
|
if err := row.Scan( |
|
|
|
|
|
&mi.Type, |
|
|
|
|
|
&mi.Label, |
|
|
|
|
|
&mi.Lender, |
|
|
|
|
|
&mi.Rate, |
|
|
|
|
|
&mi.Premium, |
|
|
|
|
|
&mi.Upfront, |
|
|
|
|
|
&mi.FiveYearTotal, |
|
|
|
|
|
&mi.InitialAllInPremium, |
|
|
|
|
|
&mi.InitialAllInRate, |
|
|
|
|
|
&mi.InitialAmount, |
|
|
|
|
|
) |
|
|
|
|
|
err != nil { |
|
|
|
|
|
return mi, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return mi, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func getLoans(db *sql.DB, estimate int) ([]Loan, error) { |
|
|
func getLoans(db *sql.DB, estimate int) ([]Loan, error) { |
|
|
var loans []Loan |
|
|
var loans []Loan |
|
|
|
|
|
|
|
|
query := `SELECT |
|
|
query := `SELECT |
|
|
l.id, l.amount, l.term, l.interest, l.ltv, l.dti, l.hoi, l.mi_name, |
|
|
|
|
|
l.mi_amount, lt.id, lt.user_id, lt.branch_id, lt.name |
|
|
|
|
|
|
|
|
l.id, l.amount, l.term, l.interest, l.ltv, l.dti, l.hoi, |
|
|
|
|
|
lt.id, lt.user_id, lt.branch_id, lt.name |
|
|
FROM loan l INNER JOIN loan_type lt ON l.type_id = lt.id |
|
|
FROM loan l INNER JOIN loan_type lt ON l.type_id = lt.id |
|
|
WHERE l.estimate_id = ? |
|
|
WHERE l.estimate_id = ? |
|
|
` |
|
|
` |
|
@@ -327,8 +362,6 @@ func getLoans(db *sql.DB, estimate int) ([]Loan, error) { |
|
|
&loan.Ltv, |
|
|
&loan.Ltv, |
|
|
&loan.Dti, |
|
|
&loan.Dti, |
|
|
&loan.Hoi, |
|
|
&loan.Hoi, |
|
|
&loan.MiName, |
|
|
|
|
|
&loan.MiAmount, |
|
|
|
|
|
&loan.Type.Id, |
|
|
&loan.Type.Id, |
|
|
&loan.Type.User, |
|
|
&loan.Type.User, |
|
|
&loan.Type.Branch, |
|
|
&loan.Type.Branch, |
|
@@ -337,7 +370,11 @@ func getLoans(db *sql.DB, estimate int) ([]Loan, error) { |
|
|
err != nil { |
|
|
err != nil { |
|
|
return loans, fmt.Errorf("Loans scanning error: %v", err) |
|
|
return loans, fmt.Errorf("Loans scanning error: %v", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mi, err := getMi(db, loan.Id) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return loans, err |
|
|
|
|
|
} |
|
|
|
|
|
loan.Mi = mi |
|
|
loans = append(loans, loan) |
|
|
loans = append(loans, loan) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -365,7 +402,8 @@ func getBorrower(db *sql.DB, id int) (Borrower, error) { |
|
|
return borrower, nil |
|
|
return borrower, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func getMi(db *sql.DB, estimate *Estimate, pos int) (*Estimate) { |
|
|
|
|
|
|
|
|
// Query Lender APIs and parse responses into MI structs |
|
|
|
|
|
func fetchMi(db *sql.DB, estimate *Estimate, pos int) []MI { |
|
|
var err error |
|
|
var err error |
|
|
var loan Loan = estimate.Loans[pos] |
|
|
var loan Loan = estimate.Loans[pos] |
|
|
|
|
|
|
|
@@ -447,11 +485,10 @@ func getMi(db *sql.DB, estimate *Estimate, pos int) (*Estimate) { |
|
|
|
|
|
|
|
|
if resp.StatusCode != 200 { |
|
|
if resp.StatusCode != 200 { |
|
|
log.Printf("the status: %v\nthe resp: %v\n the req: %v\n the body: %v\n", |
|
|
log.Printf("the status: %v\nthe resp: %v\n the req: %v\n the body: %v\n", |
|
|
resp.Status, resp, req.Body, bytes.NewBuffer(body)) |
|
|
|
|
|
|
|
|
resp.Status, resp, req.Body, bytes.NewBuffer(body)) |
|
|
} else { |
|
|
} else { |
|
|
json.NewDecoder(resp.Body).Decode(&res) |
|
|
json.NewDecoder(resp.Body).Decode(&res) |
|
|
log.Printf("the valid resp: %v", res) |
|
|
|
|
|
estimate.Loans[pos].Mi = res |
|
|
|
|
|
|
|
|
// estimate.Loans[pos].Mi = res |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return estimate |
|
|
return estimate |
|
@@ -530,7 +567,7 @@ func api(w http.ResponseWriter, r *http.Request) { |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
json.NewEncoder(w).Encode(getMi(db, &est, 0)) |
|
|
|
|
|
|
|
|
json.NewEncoder(w).Encode(fetchMi(db, &est, 0).Loans[0].Mi) |
|
|
|
|
|
|
|
|
// if err != nil { |
|
|
// if err != nil { |
|
|
// json.NewEncoder(w).Encode(err) |
|
|
// json.NewEncoder(w).Encode(err) |
|
|