package main import ( "biukop.com/sfm/loan" "encoding/json" 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) } func decodeJsonBrokerEdit(r *http.Request) (ret loan.Broker, 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 apiV1BrokerPost(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 broker by id", id, e.Error()) apiV1Client404Error(w, r, ss) return } input, e := decodeJsonBrokerEdit(r) if e != nil { log.Error("cannot find broker by id", id, e.Error()) apiV1Client404Error(w, r, ss) return } b.BSB = input.BSB b.ACC = input.ACC b.Display = input.Display b.First = input.First b.Last = input.Last b.License = input.License if ss.GetRole() == "admin" { b.Login = input.Login b.Organization = input.Organization } e = b.Write() if e != nil { log.Error("failed to save broker ", b, e.Error()) apiV1Client404Error(w, r, ss) return } apiV1SendJson(b, w, r, ss) }