| b.First = input.First | b.First = input.First | ||||
| b.Last = input.Last | b.Last = input.Last | ||||
| b.License = input.License | b.License = input.License | ||||
| b.Organization = input.Organization | |||||
| if ss.GetRole() == "admin" { | |||||
| b.Login = input.Login | |||||
| b.Organization = input.Organization | |||||
| } | |||||
| e = b.Write() | e = b.Write() | ||||
| if e != nil { | if e != nil { |
| apiV1SendJson(loanId, w, r, ss) | apiV1SendJson(loanId, w, r, ss) | ||||
| } | } | ||||
| func apiV1LoanByClient(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||||
| clientId := r.URL.Path[len(apiV1Prefix+"loan-by-client/"):] //remove prefix | |||||
| data := loan.GetLoansByClient(clientId) | |||||
| apiV1SendJson(data, w, r, ss) | |||||
| } |
| 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" | ||||
| ) | ) | ||||
| } | } | ||||
| apiV1SendJson(p, w, r, ss) | apiV1SendJson(p, w, r, ss) | ||||
| } | } | ||||
| func decodeJsonPeopleEdit(r *http.Request) (ret loan.People, 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 apiV1PeoplePost(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||||
| id := r.URL.Path[len(apiV1Prefix+"people/"):] | |||||
| p := loan.People{} | |||||
| e := p.Read(id) | |||||
| if e != nil { | |||||
| log.Error("cannot find people by id", id, e.Error()) | |||||
| apiV1Client404Error(w, r, ss) | |||||
| return | |||||
| } | |||||
| input, e := decodeJsonPeopleEdit(r) | |||||
| if e != nil { | |||||
| log.Error("invalid input for update people", id, e.Error()) | |||||
| apiV1Client404Error(w, r, ss) | |||||
| return | |||||
| } | |||||
| p.First = input.First | |||||
| p.Last = input.Last | |||||
| p.Display = input.Display | |||||
| if ss.GetRole() == "admin" { | |||||
| p.Title = input.Title | |||||
| p.Nick = input.Nick | |||||
| p.Title = input.Title | |||||
| } | |||||
| e = p.Write() | |||||
| if e != nil { | |||||
| log.Error("fail to update people", p, e.Error()) | |||||
| apiV1Server500Error(w, r) | |||||
| return | |||||
| } | |||||
| apiV1SendJson(p, w, r, ss) | |||||
| } |
| {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, | {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, | ||||
| {"GET", "chart/top-broker", apiV1ChartTopBroker}, | {"GET", "chart/top-broker", apiV1ChartTopBroker}, | ||||
| {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | ||||
| {"GET", "chart/reward-vs-income-monthly", apiV1ChartRewardVsIncomeMonthly}, | |||||
| {"GET", "loan/", apiV1LoanSingleGet}, | {"GET", "loan/", apiV1LoanSingleGet}, | ||||
| {"DELETE", "loan/", apiV1LoanSingleDelete}, | {"DELETE", "loan/", apiV1LoanSingleDelete}, | ||||
| {"GET", "loan-by-client/", apiV1LoanByClient}, | |||||
| {"GET", "people/", apiV1PeopleGet}, | {"GET", "people/", apiV1PeopleGet}, | ||||
| {"POST", "people/", apiV1PeoplePost}, | |||||
| {"GET", "broker/", apiV1BrokerGet}, | {"GET", "broker/", apiV1BrokerGet}, | ||||
| {"POST", "broker/", apiV1BrokerPost}, | {"POST", "broker/", apiV1BrokerPost}, | ||||
| {"POST", "change-pass/", apiV1ChangePass}, | {"POST", "change-pass/", apiV1ChangePass}, | ||||
| {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, | {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, | ||||
| {"GET", "chart/top-broker", apiV1ChartTopBroker}, | {"GET", "chart/top-broker", apiV1ChartTopBroker}, | ||||
| {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | ||||
| {"GET", "chart/reward-vs-income-monthly", apiV1ChartRewardVsIncomeMonthly}, | |||||
| {"GET", "loan/", apiV1LoanSingleGet}, | {"GET", "loan/", apiV1LoanSingleGet}, | ||||
| {"DELETE", "loan/", apiV1LoanSingleDelete}, | {"DELETE", "loan/", apiV1LoanSingleDelete}, | ||||
| {"GET", "loan-by-client/", apiV1LoanByClient}, | |||||
| {"GET", "people/", apiV1PeopleGet}, | {"GET", "people/", apiV1PeopleGet}, | ||||
| {"POST", "people/", apiV1PeoplePost}, | |||||
| {"GET", "broker/", apiV1BrokerGet}, | {"GET", "broker/", apiV1BrokerGet}, | ||||
| {"POST", "broker/", apiV1BrokerPost}, | {"POST", "broker/", apiV1BrokerPost}, | ||||
| {"POST", "change-pass/", apiV1ChangePass}, | {"POST", "change-pass/", apiV1ChangePass}, |
| package main | |||||
| import ( | |||||
| "biukop.com/sfm/loan" | |||||
| "net/http" | |||||
| ) | |||||
| func apiV1ChartRewardVsIncomeMonthly(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||||
| data := loan.RewardVsIncomeMonthly() | |||||
| //send out | |||||
| apiV1SendJson(data, w, r, ss) | |||||
| } |