|
- package main
-
- import (
- "biukop.com/sfm/loan"
- "database/sql"
- log "github.com/sirupsen/logrus"
- "net/http"
- "strconv"
- )
-
- func apiV1PayOutExGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
- strId := r.URL.Path[len(apiV1Prefix+"payout-ex/"):]
- ret := loan.PayOutEx{}
- id, e := strconv.Atoi(strId)
- if e != nil {
- log.Error("invalid id for PayOutEx", strId, e.Error())
- apiV1Client403Error(w, r, ss)
- }
- e = ret.Read(int64(id))
- if e != nil {
- if e == sql.ErrNoRows {
- apiV1Client404Error(w, r, ss)
- return
- }
- log.Error("failed to read PayOutEx", strId, e.Error())
- apiV1Server500Error(w, r)
- return
- }
-
- apiV1SendJson(ret, w, r, ss)
- return
- }
-
- func apiV1PayOutExListGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
- // strId := r.URL.Path[len(apiV1Prefix+"payout-ex-list/"):]
- input, e := decodeJsonFullLoanOverview(r)
-
- // TODO; Generalize that input, and return a list of filters and sort
-
- // Todo: do some serious query for the data in the Grid, and make it a pattern. Get it done!
-
- if e != nil {
- apiV1EmptyResponse(w, r, ss)
- } else {
-
- switch ss.GetRole() {
- case "broker":
- input.Filter.Filters = append(input.Filter.Filters, loan.FullLoanSummaryFilter{
- Field: "broker_ids",
- Operator: "contains",
- Value: loan.JsonString(ss.User)})
- break
- case "user":
- input.Filter.Filters = append(input.Filter.Filters, loan.FullLoanSummaryFilter{
- Field: "client_ids",
- Operator: "contains",
- Value: loan.JsonString(ss.User)})
- break
- }
-
- data := loan.QFullLLoanSummary(input)
- //send out
- apiV1SendJson(data, w, r, ss)
- }
- }
|