|
@@ -40,6 +40,16 @@ type Address struct { |
|
|
Zip string `json:"zip"` |
|
|
Zip string `json:"zip"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type Branch struct { |
|
|
|
|
|
Id int `json:"id"` |
|
|
|
|
|
Name string `json:"name"` |
|
|
|
|
|
Type string `json:"type"` |
|
|
|
|
|
Letterhead []byte `json:"letterhead"` |
|
|
|
|
|
Num string `json:"num"` |
|
|
|
|
|
Phone string `json:"phone"` |
|
|
|
|
|
Address Address `json:"address"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type User struct { |
|
|
type User struct { |
|
|
Id int `json:"id"` |
|
|
Id int `json:"id"` |
|
@@ -587,7 +597,6 @@ func getBorrower(db *sql.DB, id int) (Borrower, error) { |
|
|
|
|
|
|
|
|
// Query Lender APIs and parse responses into MI structs |
|
|
// Query Lender APIs and parse responses into MI structs |
|
|
func fetchMi(db *sql.DB, estimate *Estimate, pos int) []MI { |
|
|
func fetchMi(db *sql.DB, estimate *Estimate, pos int) []MI { |
|
|
var err error |
|
|
|
|
|
var loan Loan = estimate.Loans[pos] |
|
|
var loan Loan = estimate.Loans[pos] |
|
|
|
|
|
|
|
|
var ltv = func(l float32) string { |
|
|
var ltv = func(l float32) string { |
|
@@ -648,11 +657,32 @@ func fetchMi(db *sql.DB, estimate *Estimate, pos int) []MI { |
|
|
"armType": "", |
|
|
"armType": "", |
|
|
"userId": 44504, |
|
|
"userId": 44504, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("Could not marshal NationalMI body: \n%v\n%v\n", |
|
|
log.Printf("Could not marshal NationalMI body: \n%v\n%v\n", |
|
|
bytes.NewBuffer(body), err) |
|
|
bytes.NewBuffer(body), err) |
|
|
|
|
|
func queryAddress(db *sql.DB, id int) ( Address, error ) { |
|
|
|
|
|
var address Address = Address{Id: id} |
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
|
row := db.QueryRow( |
|
|
|
|
|
`SELECT id, full_address, street, city, region, country, zip |
|
|
|
|
|
FROM address WHERE id = ?`, id) |
|
|
|
|
|
|
|
|
|
|
|
err = row.Scan( |
|
|
|
|
|
&address.Id, |
|
|
|
|
|
&address.Full, |
|
|
|
|
|
&address.Street, |
|
|
|
|
|
&address.City, |
|
|
|
|
|
&address.Region, |
|
|
|
|
|
&address.Country, |
|
|
|
|
|
&address.Zip, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return address, err |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", |
|
|
req, err := http.NewRequest("POST", |
|
|
"https://rate-gps.nationalmi.com/rates/productRateQuote", |
|
|
"https://rate-gps.nationalmi.com/rates/productRateQuote", |
|
@@ -675,6 +705,8 @@ func fetchMi(db *sql.DB, estimate *Estimate, pos int) []MI { |
|
|
// estimate.Loans[pos].Mi = res |
|
|
// estimate.Loans[pos].Mi = res |
|
|
// Parse res into result here |
|
|
// Parse res into result here |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.Println(err) |
|
|
|
|
|
|
|
|
return result |
|
|
return result |
|
|
} |
|
|
} |
|
@@ -792,7 +824,7 @@ func insertAddress(db *sql.DB, address Address) (int, error){ |
|
|
|
|
|
|
|
|
query = `INSERT INTO address |
|
|
query = `INSERT INTO address |
|
|
( |
|
|
( |
|
|
full, |
|
|
|
|
|
|
|
|
full_address, |
|
|
street, |
|
|
street, |
|
|
city, |
|
|
city, |
|
|
region, |
|
|
region, |
|
@@ -817,6 +849,40 @@ func insertAddress(db *sql.DB, address Address) (int, error){ |
|
|
return id, err |
|
|
return id, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Inserts an address and returns it's ID along with any errors. |
|
|
|
|
|
func insertBranch(db *sql.DB, branch Branch) (int, error){ |
|
|
|
|
|
var query string |
|
|
|
|
|
var row *sql.Row |
|
|
|
|
|
var err error |
|
|
|
|
|
var id int // Inserted user's id |
|
|
|
|
|
|
|
|
|
|
|
query = `INSERT INTO branch |
|
|
|
|
|
( |
|
|
|
|
|
name, |
|
|
|
|
|
type, |
|
|
|
|
|
letterhead, |
|
|
|
|
|
num, |
|
|
|
|
|
phone, |
|
|
|
|
|
address |
|
|
|
|
|
) |
|
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?) |
|
|
|
|
|
RETURNING id |
|
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
row = db.QueryRow(query, |
|
|
|
|
|
branch.Name, |
|
|
|
|
|
branch.Type, |
|
|
|
|
|
branch.Letterhead, |
|
|
|
|
|
branch.Num, |
|
|
|
|
|
branch.Phone, |
|
|
|
|
|
branch.Address.Id, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
err = row.Scan(&id) |
|
|
|
|
|
|
|
|
|
|
|
return id, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func queryAddress(db *sql.DB, id int) ( Address, error ) { |
|
|
func queryAddress(db *sql.DB, id int) ( Address, error ) { |
|
|
var address Address = Address{Id: id} |
|
|
var address Address = Address{Id: id} |
|
|
var err error |
|
|
var err error |
|
@@ -838,6 +904,27 @@ func queryAddress(db *sql.DB, id int) ( Address, error ) { |
|
|
return address, err |
|
|
return address, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func queryBranch(db *sql.DB, id int) ( Branch, error ) { |
|
|
|
|
|
var branch Branch = Branch{Id: id} |
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
|
row := db.QueryRow( |
|
|
|
|
|
`SELECT id, name, type, letterhead, num, phone, address |
|
|
|
|
|
FROM branch WHERE id = ?`, id) |
|
|
|
|
|
|
|
|
|
|
|
err = row.Scan( |
|
|
|
|
|
&branch.Id, |
|
|
|
|
|
&branch.Name, |
|
|
|
|
|
&branch.Type, |
|
|
|
|
|
&branch.Letterhead, |
|
|
|
|
|
&branch.Num, |
|
|
|
|
|
&branch.Phone, |
|
|
|
|
|
&branch.Address.Id, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return branch, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func queryUsers(db *sql.DB, id int) ( []User, error ) { |
|
|
func queryUsers(db *sql.DB, id int) ( []User, error ) { |
|
|
var users []User |
|
|
var users []User |
|
|
var query string |
|
|
var query string |
|
@@ -2145,13 +2232,39 @@ func dbSeed() { |
|
|
panic(err) |
|
|
panic(err) |
|
|
// maybe os.Exit(1) instead |
|
|
// maybe os.Exit(1) instead |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addresses := make([]Address, 10) |
|
|
|
|
|
for i, a := range addresses { |
|
|
|
|
|
a.Street = gofakeit.Street() |
|
|
|
|
|
a.City = gofakeit.City() |
|
|
|
|
|
a.Region = gofakeit.State() |
|
|
|
|
|
a.Country = "Canada" |
|
|
|
|
|
a.Full = fmt.Sprintf("%s, %s %s", a.Street, a.City, a.Region) |
|
|
|
|
|
id, err := insertAddress(db, a) |
|
|
|
|
|
if err != nil {log.Println(err); break} |
|
|
|
|
|
addresses[i].Id = id |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
branches := make([]Branch, 3) |
|
|
|
|
|
for i := range branches { |
|
|
|
|
|
branches[i].Name = gofakeit.Street() |
|
|
|
|
|
branches[i].Type = "NMLS" |
|
|
|
|
|
branches[i].Letterhead = gofakeit.ImagePng(400, 200) |
|
|
|
|
|
branches[i].Num = gofakeit.HexUint8() |
|
|
|
|
|
branches[i].Phone = gofakeit.Phone() |
|
|
|
|
|
branches[i].Address.Id = gofakeit.Number(1, 5) |
|
|
|
|
|
id, err := insertBranch(db, branches[i]) |
|
|
|
|
|
if err != nil {log.Println(err); break} |
|
|
|
|
|
branches[i].Address.Id = id |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func dev(args []string) { |
|
|
func dev(args []string) { |
|
|
|
|
|
os.Setenv("DBName", "skouter_dev") |
|
|
|
|
|
os.Setenv("DBUser", "tester") |
|
|
|
|
|
os.Setenv("DBPass", "test123") |
|
|
|
|
|
|
|
|
if len(args) == 0 { |
|
|
if len(args) == 0 { |
|
|
os.Setenv("DBName", "skouter_dev") |
|
|
|
|
|
os.Setenv("DBUser", "tester") |
|
|
|
|
|
os.Setenv("DBPass", "test123") |
|
|
|
|
|
serve() |
|
|
serve() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|