diff --git a/apiV1GridLoanFullOverview.go b/apiV1GridLoanFullOverview.go index 6a576e0..5d822e2 100644 --- a/apiV1GridLoanFullOverview.go +++ b/apiV1GridLoanFullOverview.go @@ -2,36 +2,30 @@ package main import ( "biukop.com/sfm/loan" + "encoding/json" log "github.com/sirupsen/logrus" "net/http" - "strconv" ) +func decodeJsonFullLoanOverview(r *http.Request) (ret loan.FullLoanSummaryQueryInput, e error) { + decoder := json.NewDecoder(r.Body) + //decoder.DisallowUnknownFields() + e = decoder.Decode(&ret) + if e != nil { + log.Error("failed decoding json for Filtering full_loan_summary ", e.Error()) + return + } + return +} 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 - } + input, e := decodeJsonFullLoanOverview(r) - sTake := r.URL.Query().Get("$top") // - if sTake == "" { - log.Info("query full_loan_summary, take not present set to 0 ") + if e != nil { + apiV1EmptyResponse(w, r, ss) } else { - t, err := strconv.Atoi(sTake) - log.Print(t, err) - take = t + data := loan.QFullLLoanSummary(input) + //send out + apiV1SendJson(data, w, r, ss) } - - data := loan.QFullLLoanSummary(skip, take, sort) - //send out - apiV1SendJson(data, w, r, ss) } diff --git a/apiv1.go b/apiv1.go index a95588b..7679deb 100644 --- a/apiv1.go +++ b/apiv1.go @@ -35,7 +35,7 @@ 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}, + {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, {"GET", "avatar/", apiV1Avatar}, {"GET", "login", apiV1DumpRequest}, } @@ -48,7 +48,7 @@ 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}, + {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, {"GET", "avatar/", apiV1Avatar}, {"GET", "login", apiV1EmptyResponse}, } @@ -83,7 +83,7 @@ func apiV1Main(w http.ResponseWriter, r *http.Request) { //search through handler path := r.URL.Path[len(apiV1Prefix):] //strip API prefix for _, node := range apiV1Handler { - log.Println(node, path, strings.HasPrefix(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 @@ -94,7 +94,7 @@ func apiV1Main(w http.ResponseWriter, r *http.Request) { } } - //Catch for all Uhandled Request + //Catch for all UnHandled Request e := session.Write() //finish this session to DB if e != nil { log.Warnf("Failed to Save Session %+v \n reason \n%s\n", session, e.Error())