| @@ -62,7 +62,11 @@ func apiV1BrokerPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| b.First = input.First | |||
| b.Last = input.Last | |||
| b.License = input.License | |||
| b.Organization = input.Organization | |||
| if ss.GetRole() == "admin" { | |||
| b.Login = input.Login | |||
| b.Organization = input.Organization | |||
| } | |||
| e = b.Write() | |||
| if e != nil { | |||
| @@ -74,3 +74,12 @@ func apiV1LoanSingleDelete(w http.ResponseWriter, r *http.Request, ss *loan.Sess | |||
| 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) | |||
| } | |||
| @@ -2,6 +2,7 @@ package main | |||
| import ( | |||
| "biukop.com/sfm/loan" | |||
| "encoding/json" | |||
| log "github.com/sirupsen/logrus" | |||
| "net/http" | |||
| ) | |||
| @@ -27,3 +28,50 @@ func apiV1PeopleGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| } | |||
| 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) | |||
| } | |||
| @@ -36,9 +36,12 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, | |||
| {"GET", "chart/top-broker", apiV1ChartTopBroker}, | |||
| {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | |||
| {"GET", "chart/reward-vs-income-monthly", apiV1ChartRewardVsIncomeMonthly}, | |||
| {"GET", "loan/", apiV1LoanSingleGet}, | |||
| {"DELETE", "loan/", apiV1LoanSingleDelete}, | |||
| {"GET", "loan-by-client/", apiV1LoanByClient}, | |||
| {"GET", "people/", apiV1PeopleGet}, | |||
| {"POST", "people/", apiV1PeoplePost}, | |||
| {"GET", "broker/", apiV1BrokerGet}, | |||
| {"POST", "broker/", apiV1BrokerPost}, | |||
| {"POST", "change-pass/", apiV1ChangePass}, | |||
| @@ -65,9 +68,12 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, | |||
| {"GET", "chart/top-broker", apiV1ChartTopBroker}, | |||
| {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | |||
| {"GET", "chart/reward-vs-income-monthly", apiV1ChartRewardVsIncomeMonthly}, | |||
| {"GET", "loan/", apiV1LoanSingleGet}, | |||
| {"DELETE", "loan/", apiV1LoanSingleDelete}, | |||
| {"GET", "loan-by-client/", apiV1LoanByClient}, | |||
| {"GET", "people/", apiV1PeopleGet}, | |||
| {"POST", "people/", apiV1PeoplePost}, | |||
| {"GET", "broker/", apiV1BrokerGet}, | |||
| {"POST", "broker/", apiV1BrokerPost}, | |||
| {"POST", "change-pass/", apiV1ChangePass}, | |||
| @@ -0,0 +1,12 @@ | |||
| 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) | |||
| } | |||