| @@ -0,0 +1,29 @@ | |||
| package main | |||
| import ( | |||
| "biukop.com/sfm/loan" | |||
| log "github.com/sirupsen/logrus" | |||
| "net/http" | |||
| ) | |||
| func apiV1BrokerList(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| filter := "" | |||
| keys, ok := r.URL.Query()["filter"] | |||
| if ok && len(keys) >= 1 { | |||
| filter = keys[0] | |||
| } | |||
| data := loan.GetBrokerList(filter) | |||
| apiV1SendJson(data, w, r, ss) | |||
| } | |||
| func apiV1BrokerGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| id := r.URL.Path[len(apiV1Prefix+"broker/"):] | |||
| b := loan.Broker{} | |||
| e := b.Read(id) | |||
| if e != nil { | |||
| log.Error("cannot find people by id", id) | |||
| apiV1Client404Error(w, r, ss) | |||
| return | |||
| } | |||
| apiV1SendJson(b, w, r, ss) | |||
| } | |||
| @@ -0,0 +1,35 @@ | |||
| package main | |||
| import ( | |||
| "biukop.com/sfm/loan" | |||
| log "github.com/sirupsen/logrus" | |||
| "net/http" | |||
| ) | |||
| func apiV1SyncPeople(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| input, e := decodeJsonLoanEdit(r) | |||
| log.Println(input) | |||
| if e != nil { | |||
| apiV1Client404Error(w, r, ss) | |||
| return | |||
| } else { | |||
| e = input.ClearPeopleMap() | |||
| if e != nil { | |||
| log.Error("FATAL ERROR for deleting people map with LoanId=", input.Id) | |||
| } | |||
| for _, v := range input.PeopleMap { | |||
| e = v.Write() | |||
| if e != nil { | |||
| apiV1Client404Error(w, r, ss) | |||
| return | |||
| } | |||
| } | |||
| // all successfully written to db | |||
| apiV1SendJson(input.PeopleMap, w, r, ss) | |||
| } | |||
| return | |||
| } | |||
| @@ -38,11 +38,14 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | |||
| {"GET", "loan/", apiV1LoanSingleGet}, | |||
| {"GET", "people/", apiV1PeopleGet}, | |||
| {"GET", "broker/", apiV1BrokerGet}, | |||
| {"POST", "loan/basic/", apiV1LoanSinglePostBasic}, | |||
| {"GET", "avatar/", apiV1Avatar}, | |||
| {"POST", "reward/", apiV1RewardPost}, | |||
| {"DELETE", "reward/", apiV1RewardDelete}, | |||
| {"GET", "people-list", apiV1PeopleList}, | |||
| {"GET", "people-list/", apiV1PeopleList}, | |||
| {"GET", "broker-list/", apiV1BrokerList}, | |||
| {"POST", "sync-people/", apiV1SyncPeople}, | |||
| {"GET", "login", apiV1DumpRequest}, | |||
| } | |||
| } else { //production | |||
| @@ -57,11 +60,14 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | |||
| {"GET", "loan/", apiV1LoanSingleGet}, | |||
| {"GET", "people/", apiV1PeopleGet}, | |||
| {"GET", "broker/", apiV1BrokerGet}, | |||
| {"POST", "loan/basic/", apiV1LoanSinglePostBasic}, | |||
| {"GET", "avatar/", apiV1Avatar}, | |||
| {"POST", "reward/", apiV1RewardPost}, | |||
| {"DELETE", "reward/", apiV1RewardDelete}, | |||
| {"GET", "people-list", apiV1PeopleList}, | |||
| {"GET", "broker-list/", apiV1BrokerList}, | |||
| {"POST", "sync-people/", apiV1SyncPeople}, | |||
| {"GET", "login", apiV1EmptyResponse}, | |||
| } | |||
| } | |||