| u := loan.User{} | u := loan.User{} | ||||
| e = u.Read(id) | e = u.Read(id) | ||||
| if e != nil { | if e != nil { | ||||
| log.Error("cannot save basic loan", e.Error()) | |||||
| log.Error("cannot save basic user", e.Error()) | |||||
| apiV1SendJson(" [ Error Occurred ] : "+e.Error(), w, r, ss) | apiV1SendJson(" [ Error Occurred ] : "+e.Error(), w, r, ss) | ||||
| return | return | ||||
| } | } | ||||
| } | } | ||||
| apiV1SendJson(p.Enabled, w, r, ss) | apiV1SendJson(p.Enabled, w, r, ss) | ||||
| } | } | ||||
| func apiV1UserExGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||||
| id := r.URL.Path[len(apiV1Prefix+"user-ex/"):] | |||||
| ret := loan.UserEx{} | |||||
| e := ret.Read(id) | |||||
| if e != nil { | |||||
| log.Error("read people error", id, e.Error()) | |||||
| apiV1Client404Error(w, r, ss) | |||||
| return | |||||
| } | |||||
| apiV1SendJson(ret, w, r, ss) | |||||
| } | |||||
| func apiV1UserExList(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.GetUserExList(filter) | |||||
| apiV1SendJson(data, w, r, ss) | |||||
| } |
| package main | |||||
| import ( | |||||
| "biukop.com/sfm/loan" | |||||
| "encoding/json" | |||||
| log "github.com/sirupsen/logrus" | |||||
| "net/http" | |||||
| ) | |||||
| func apiV1UserExList(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.GetUserExList(filter) | |||||
| apiV1SendJson(data, w, r, ss) | |||||
| } | |||||
| func apiV1UserExGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||||
| id := r.URL.Path[len(apiV1Prefix+"user-ex/"):] | |||||
| ret := loan.UserEx{} | |||||
| e := ret.Read(id) | |||||
| if e != nil { | |||||
| log.Error("read people error", id, e.Error()) | |||||
| apiV1Client404Error(w, r, ss) | |||||
| return | |||||
| } | |||||
| apiV1SendJson(ret, w, r, ss) | |||||
| } | |||||
| func decodeJsonUserEx(r *http.Request) (ret loan.UserEx, e error) { | |||||
| decoder := json.NewDecoder(r.Body) | |||||
| //decoder.DisallowUnknownFields() | |||||
| e = decoder.Decode(&ret) | |||||
| if e != nil { | |||||
| log.Error("failed decoding json for UserEx ", e.Error()) | |||||
| return | |||||
| } | |||||
| return | |||||
| } | |||||
| func apiV1UserExPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||||
| input, e := decodeJsonUserEx(r) | |||||
| log.Println(input) | |||||
| if e != nil { | |||||
| apiV1Client404Error(w, r, ss) | |||||
| return | |||||
| } | |||||
| e = input.Write() | |||||
| if e != nil { | |||||
| apiV1Client404Error(w, r, ss) | |||||
| return | |||||
| } | |||||
| apiV1SendJson(input, w, r, ss) | |||||
| } |
| if e == nil { | if e == nil { | ||||
| res.add("User", u.People) | res.add("User", u.People) | ||||
| res.add("UserExtra", getUserExtraForLogin(u, ss)) | res.add("UserExtra", getUserExtraForLogin(u, ss)) | ||||
| uex := loan.UserEx{} | |||||
| err := uex.Read(u.People.Id) | |||||
| if err != nil { | |||||
| log.Error("cannot read UserEx when login", err) | |||||
| } else { | |||||
| res.add("UserEx", uex) | |||||
| } | |||||
| } | } | ||||
| res.add("Biukop-Session", ss.Id) | res.add("Biukop-Session", ss.Id) | ||||
| res.add("Biukop-Mid", ss.Get("Biukop-Mid")) | res.add("Biukop-Mid", ss.Get("Biukop-Mid")) |
| {"POST", "user-enable/", apiV1UserEnable}, | {"POST", "user-enable/", apiV1UserEnable}, | ||||
| {"GET", "user-ex/", apiV1UserExGet}, | {"GET", "user-ex/", apiV1UserExGet}, | ||||
| {"POST", "user-ex/", apiV1UserExPost}, | |||||
| {"GET", "user-ex-list/", apiV1UserExList}, | {"GET", "user-ex-list/", apiV1UserExList}, | ||||
| {"GET", "broker/", apiV1BrokerGet}, | {"GET", "broker/", apiV1BrokerGet}, | ||||
| {"POST", "user-enable/", apiV1UserEnable}, | {"POST", "user-enable/", apiV1UserEnable}, | ||||
| {"GET", "user-ex/", apiV1UserExGet}, | {"GET", "user-ex/", apiV1UserExGet}, | ||||
| {"POST", "user-ex/", apiV1UserExPost}, | |||||
| {"GET", "user-ex-list/", apiV1UserExList}, | {"GET", "user-ex-list/", apiV1UserExList}, | ||||
| {"GET", "broker/", apiV1BrokerGet}, | {"GET", "broker/", apiV1BrokerGet}, |