/
CompanyController.go
49 lines (36 loc) · 1.04 KB
/
CompanyController.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
package web
import (
"github.com/ProfessorBeekums/PbStockResearcher/filings"
"fmt"
"net/http"
"strconv"
)
func addCompany(w http.ResponseWriter, r *http.Request) {
cikVal := r.FormValue("cik")
companyVal := r.FormValue("company")
cik, parseErr := strconv.Atoi(cikVal)
if parseErr != nil {
fmt.Fprintln(w, "ERROR parsing cik: ", parseErr)
return
}
company := &filings.Company{CIK: int64(cik), Name: companyVal}
mysql.InsertUpdateCompany(company)
ReturnJson(w, company)
}
func getCompanyData(w http.ResponseWriter, r *http.Request) {
cikVal := r.FormValue("cik")
cik, parseErr := strconv.Atoi(cikVal)
if parseErr != nil {
fmt.Fprintln(w, "ERROR parsing cik: ", parseErr)
return
}
// TODO this seems silly, but only for now!
company := mysql.GetCompany(int64(cik))
returnMap := make(map[string]string)
returnMap["name"] = company.Name
ReturnJson(w, returnMap)
}
func InitializeCompanyEndpoints() {
RegisterHttpHandler("company", HttpMethodPost, addCompany)
RegisterHttpHandler("company", HttpMethodGet, getCompanyData)
}