| @@ -0,0 +1,37 @@ | |||
| package main | |||
| import ( | |||
| "biukop.com/sfm/loan" | |||
| log "github.com/sirupsen/logrus" | |||
| "net/http" | |||
| "strconv" | |||
| ) | |||
| func apiV1GridLoanFullOverview(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| var skip int = 0 | |||
| var take int = 0 | |||
| var sort = r.URL.Query().Get("$orderby") // | |||
| sSkip := r.URL.Query().Get("$skip") // | |||
| if sSkip == "" { | |||
| log.Info("query full_loan_summary, skip not present set to 0 ") | |||
| } else { | |||
| s, err := strconv.Atoi(sSkip) // for weird reasons, I cannot replace s with skip | |||
| log.Print(s, err) | |||
| skip = s | |||
| } | |||
| sTake := r.URL.Query().Get("$top") // | |||
| if sTake == "" { | |||
| log.Info("query full_loan_summary, take not present set to 0 ") | |||
| } else { | |||
| t, err := strconv.Atoi(sTake) | |||
| log.Print(t, err) | |||
| take = t | |||
| } | |||
| data := loan.QFullLLoanSummary(skip, take, sort) | |||
| //send out | |||
| apiV1SendJson(data, w, r, ss) | |||
| } | |||
| @@ -35,6 +35,8 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"GET", "chart/past-year-monthly", apiV1ChartPastYearMonthly}, | |||
| {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, | |||
| {"GET", "chart/top-broker", apiV1ChartTopBroker}, | |||
| {"GET", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | |||
| {"GET", "avatar/", apiV1Avatar}, | |||
| {"GET", "login", apiV1DumpRequest}, | |||
| } | |||
| } else { //production | |||
| @@ -46,6 +48,8 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"GET", "chart/past-year-monthly", apiV1ChartPastYearMonthly}, | |||
| {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, | |||
| {"GET", "chart/top-broker", apiV1ChartTopBroker}, | |||
| {"GET", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | |||
| {"GET", "avatar/", apiV1Avatar}, | |||
| {"GET", "login", apiV1EmptyResponse}, | |||
| } | |||
| } | |||
| @@ -79,7 +83,8 @@ func apiV1Main(w http.ResponseWriter, r *http.Request) { | |||
| //search through handler | |||
| path := r.URL.Path[len(apiV1Prefix):] //strip API prefix | |||
| for _, node := range apiV1Handler { | |||
| if (r.Method == node.Method || node.Method == "*") && path == node.Path { | |||
| log.Println(node, path, strings.HasPrefix(path, node.Path)) | |||
| if (r.Method == node.Method || node.Method == "*") && strings.HasPrefix(path, node.Path) { | |||
| node.Handler(w, r, &session) | |||
| e := session.Write() //finish this session to DB | |||
| if e != nil { | |||
| @@ -4,6 +4,7 @@ import ( | |||
| "encoding/json" | |||
| log "github.com/sirupsen/logrus" | |||
| "io/ioutil" | |||
| "strings" | |||
| ) | |||
| type configStaticHtml struct { | |||
| @@ -19,7 +20,7 @@ type configuration struct { | |||
| TlsKey string | |||
| Static []configStaticHtml | |||
| Debug bool | |||
| Session struct { | |||
| Session struct { //TODO: figure what is this intended for | |||
| Guest bool | |||
| Year int //how many years | |||
| Month int //how many years | |||
| @@ -42,3 +43,12 @@ func (m *configuration) readConfig() (e error) { | |||
| //TODO: check config before proceed further | |||
| return | |||
| } | |||
| func (m *configuration) getAvatarPath() (ret string) { | |||
| for _, v := range m.Static { | |||
| if strings.ToLower(v.Dir) == "avatar" { | |||
| return v.Dir //found it | |||
| } | |||
| } | |||
| return "" | |||
| } | |||