|
@@ -182,31 +182,40 @@ func getLoanType( |
|
|
|
|
|
|
|
|
func getEstimate(db *sql.DB, id int) (Estimate, error) { |
|
|
func getEstimate(db *sql.DB, id int) (Estimate, error) { |
|
|
var estimate Estimate |
|
|
var estimate Estimate |
|
|
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
|
query := `SELECT e.id, e.user_id, e.transaction, |
|
|
|
|
|
e.price, e.property, e.occupancy, e.zip, e.pud, |
|
|
|
|
|
b.id, b.credit_score, b.monthly_income, b.num |
|
|
|
|
|
FROM estimate e |
|
|
|
|
|
INNER JOIN borrower b ON e.borrower_id = b.id |
|
|
|
|
|
WHERE e.id = ? |
|
|
|
|
|
` |
|
|
// Inner join should always be valid because a borrower is a required |
|
|
// Inner join should always be valid because a borrower is a required |
|
|
// foreign key. |
|
|
// foreign key. |
|
|
row := db.QueryRow( |
|
|
|
|
|
"SELECT * FROM estimate "+ |
|
|
|
|
|
"WHERE id = ? " + |
|
|
|
|
|
"INNER JOIN borrower ON estimate.borrower = borrower.id", |
|
|
|
|
|
id) |
|
|
|
|
|
|
|
|
row := db.QueryRow(query, id) |
|
|
|
|
|
|
|
|
if err := row.Scan( |
|
|
|
|
|
|
|
|
if err = row.Scan( |
|
|
&estimate.Id, |
|
|
&estimate.Id, |
|
|
&estimate.User, |
|
|
&estimate.User, |
|
|
&estimate.Borrower.Id, |
|
|
|
|
|
&estimate.Transaction, |
|
|
&estimate.Transaction, |
|
|
&estimate.Price, |
|
|
&estimate.Price, |
|
|
&estimate.Property, |
|
|
&estimate.Property, |
|
|
&estimate.Occupancy, |
|
|
&estimate.Occupancy, |
|
|
&estimate.Zip, |
|
|
&estimate.Zip, |
|
|
&estimate.Pud, |
|
|
&estimate.Pud, |
|
|
|
|
|
&estimate.Borrower.Id, |
|
|
|
|
|
&estimate.Borrower.Credit, |
|
|
|
|
|
&estimate.Borrower.Income, |
|
|
|
|
|
&estimate.Borrower.Num, |
|
|
) |
|
|
) |
|
|
err != nil { |
|
|
err != nil { |
|
|
return estimate, fmt.Errorf("Estimate scanning error: %v", err) |
|
|
return estimate, fmt.Errorf("Estimate scanning error: %v", err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return estimate, nil |
|
|
|
|
|
|
|
|
estimate.Loans, err = getLoans(db, estimate.Id) |
|
|
|
|
|
|
|
|
|
|
|
return estimate, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func getFees(db *sql.DB, loan int) ([]Fee, error) { |
|
|
func getFees(db *sql.DB, loan int) ([]Fee, error) { |
|
@@ -282,10 +291,6 @@ func getFeesTemp(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
fees = append(fees, fee) |
|
|
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 |
|
|
return fees, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -293,11 +298,10 @@ func getLoans(db *sql.DB, estimate int) ([]Loan, error) { |
|
|
var loans []Loan |
|
|
var loans []Loan |
|
|
|
|
|
|
|
|
query := `SELECT |
|
|
query := `SELECT |
|
|
loan.id, loan.amount, loan.term, loan.interest, loan.ltv, loan.dti, |
|
|
|
|
|
loan.hoi, loan.mi_name, loan.mi_amount |
|
|
|
|
|
loan_type.id, loan_type.user_id, loan_type.branch_id, loan_type.name |
|
|
|
|
|
FROM loan INNER JOIN loan_type ON loan.type_id = loan_type(id) |
|
|
|
|
|
WHERE loan.estimate_id = ? |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
FROM loan l INNER JOIN loan_type lt ON l.type_id = lt.id |
|
|
|
|
|
WHERE l.estimate_id = ? |
|
|
` |
|
|
` |
|
|
rows, err := db.Query(query, estimate) |
|
|
rows, err := db.Query(query, estimate) |
|
|
|
|
|
|
|
@@ -332,10 +336,6 @@ func getLoans(db *sql.DB, estimate int) ([]Loan, error) { |
|
|
loans = append(loans, loan) |
|
|
loans = append(loans, loan) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
est, err := getEstimate(db, 1) |
|
|
|
|
|
fmt.Printf("the loan: %v,\nthe error %v\n", est, err) |
|
|
|
|
|
// getMi(db, getEstimate(db, 1), getBorrower(db, 1)) |
|
|
|
|
|
|
|
|
|
|
|
return loans, nil |
|
|
return loans, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -360,7 +360,7 @@ func getBorrower(db *sql.DB, id int) (Borrower, error) { |
|
|
return borrower, nil |
|
|
return borrower, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func getMi(db *sql.DB, estimate Estimate, borrower Borrower) { |
|
|
|
|
|
|
|
|
func getMi(db *sql.DB, estimate *Estimate) { |
|
|
// body := map[string]string{ |
|
|
// body := map[string]string{ |
|
|
// "zipCode": estimate.Zip, |
|
|
// "zipCode": estimate.Zip, |
|
|
// // "stateCode": "CA", |
|
|
// // "stateCode": "CA", |
|
@@ -420,13 +420,13 @@ func getMi(db *sql.DB, estimate Estimate, borrower Borrower) { |
|
|
"productCode": "BPM", |
|
|
"productCode": "BPM", |
|
|
"renewalTypeCode": "CON", |
|
|
"renewalTypeCode": "CON", |
|
|
"numberOfBorrowers": 1, |
|
|
"numberOfBorrowers": 1, |
|
|
"borrowerCreditScore": strconv.Itoa(borrower.Credit), |
|
|
|
|
|
|
|
|
"borrowerCreditScore": strconv.Itoa(estimate.Borrower.Credit), |
|
|
"masterPolicy": nil, |
|
|
"masterPolicy": nil, |
|
|
"selfEmployedIndicator": false, |
|
|
"selfEmployedIndicator": false, |
|
|
"armType": "", |
|
|
"armType": "", |
|
|
"userId": 44504, |
|
|
"userId": 44504, |
|
|
}) |
|
|
}) |
|
|
log.Println(bytes.NewBuffer(body)) |
|
|
|
|
|
|
|
|
log.Println("the bytes: %v", bytes.NewBuffer(body)) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -459,6 +459,7 @@ func route(w http.ResponseWriter, r *http.Request) { |
|
|
func api(w http.ResponseWriter, r *http.Request) { |
|
|
func api(w http.ResponseWriter, r *http.Request) { |
|
|
var args []string |
|
|
var args []string |
|
|
// var response string |
|
|
// var response string |
|
|
|
|
|
|
|
|
p := r.URL.Path |
|
|
p := r.URL.Path |
|
|
db, err := sql.Open("mysql", |
|
|
db, err := sql.Open("mysql", |
|
|
fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/skouter", |
|
|
fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/skouter", |
|
@@ -492,6 +493,24 @@ func api(w http.ResponseWriter, r *http.Request) { |
|
|
} else { |
|
|
} else { |
|
|
json.NewEncoder(w).Encode(err) |
|
|
json.NewEncoder(w).Encode(err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case match(p, "/api/mi", &args): |
|
|
|
|
|
var err error |
|
|
|
|
|
est, err := getEstimate(db, 1) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
json.NewEncoder(w).Encode(err) |
|
|
|
|
|
log.Println("error occured:", err) |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getMi(db, &est) |
|
|
|
|
|
|
|
|
|
|
|
// if err != nil { |
|
|
|
|
|
// json.NewEncoder(w).Encode(err) |
|
|
|
|
|
// break |
|
|
|
|
|
// } else { |
|
|
|
|
|
// json.NewEncoder(w).Encode(resp) |
|
|
|
|
|
// } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|