-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.go
64 lines (54 loc) · 1.37 KB
/
funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"strconv"
"strings"
"sync"
"github.com/charmbracelet/bubbles/textinput"
)
func printInputs(inputs []textinput.Model) {
fmt.Println()
fmt.Println()
fmt.Println("Your specifications are...")
for _, input := range inputs {
fmt.Printf("%s: %s\n", input.Placeholder, input.Value())
}
fmt.Println()
}
func houseHunt(inputs []textinput.Model) chan string {
areas := strings.Split(inputs[0].Value(), ",")
priceMin := convertStringToNum(inputs[1].Value())
priceMax := convertStringToNum(inputs[2].Value())
bedMin := convertStringToNum(inputs[3].Value())
bathMin := convertStringToNum(inputs[4].Value())
sqftMin := convertStringToNum(inputs[5].Value())
status := calculateStatus(inputs[6].Value())
numResults := convertStringToNum(inputs[7].Value())
ch := make(chan string)
var wg sync.WaitGroup
for _, area := range areas {
wg.Add(1)
go callApi(area, priceMin, priceMax, bedMin, bathMin, sqftMin, status, numResults, ch, &wg)
}
go func() {
wg.Wait()
close(ch)
}()
return ch
}
func calculateStatus(lookingFor string) []string {
if strings.EqualFold(lookingFor, "Buy") {
status := []string{"for_sale", "ready_to_build"}
return status
} else {
status := []string{"for_rent"}
return status
}
}
func convertStringToNum(numStr string) (num int) {
num, err := strconv.Atoi(numStr)
if err != nil {
panic(err)
}
return num
}