瀏覽代碼

query entire loan summary works fine.

master
sp 4 年之前
父節點
當前提交
eccf82a3b3
共有 2 個檔案被更改,包括 21 行新增27 行删除
  1. +17
    -23
      apiV1GridLoanFullOverview.go
  2. +4
    -4
      apiv1.go

+ 17
- 23
apiV1GridLoanFullOverview.go 查看文件



import ( import (
"biukop.com/sfm/loan" "biukop.com/sfm/loan"
"encoding/json"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/http" "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) { 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 { } 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)
} }

+ 4
- 4
apiv1.go 查看文件

{"GET", "chart/past-year-monthly", apiV1ChartPastYearMonthly}, {"GET", "chart/past-year-monthly", apiV1ChartPastYearMonthly},
{"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans},
{"GET", "chart/top-broker", apiV1ChartTopBroker}, {"GET", "chart/top-broker", apiV1ChartTopBroker},
{"GET", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview},
{"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview},
{"GET", "avatar/", apiV1Avatar}, {"GET", "avatar/", apiV1Avatar},
{"GET", "login", apiV1DumpRequest}, {"GET", "login", apiV1DumpRequest},
} }
{"GET", "chart/past-year-monthly", apiV1ChartPastYearMonthly}, {"GET", "chart/past-year-monthly", apiV1ChartPastYearMonthly},
{"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans},
{"GET", "chart/top-broker", apiV1ChartTopBroker}, {"GET", "chart/top-broker", apiV1ChartTopBroker},
{"GET", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview},
{"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview},
{"GET", "avatar/", apiV1Avatar}, {"GET", "avatar/", apiV1Avatar},
{"GET", "login", apiV1EmptyResponse}, {"GET", "login", apiV1EmptyResponse},
} }
//search through handler //search through handler
path := r.URL.Path[len(apiV1Prefix):] //strip API prefix path := r.URL.Path[len(apiV1Prefix):] //strip API prefix
for _, node := range apiV1Handler { 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) { if (r.Method == node.Method || node.Method == "*") && strings.HasPrefix(path, node.Path) {
node.Handler(w, r, &session) node.Handler(w, r, &session)
e := session.Write() //finish this session to DB e := session.Write() //finish this session to DB
} }
} }


//Catch for all Uhandled Request
//Catch for all UnHandled Request
e := session.Write() //finish this session to DB e := session.Write() //finish this session to DB
if e != nil { if e != nil {
log.Warnf("Failed to Save Session %+v \n reason \n%s\n", session, e.Error()) log.Warnf("Failed to Save Session %+v \n reason \n%s\n", session, e.Error())

Loading…
取消
儲存