| @@ -103,7 +103,7 @@ func apiV1UserPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| u := loan.User{} | |||
| e = u.Read(id) | |||
| 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) | |||
| return | |||
| } | |||
| @@ -151,25 +151,3 @@ func apiV1UserEnable(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| } | |||
| 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) | |||
| } | |||
| @@ -0,0 +1,58 @@ | |||
| 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) | |||
| } | |||
| @@ -53,6 +53,13 @@ func apiV1Login(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| if e == nil { | |||
| res.add("User", u.People) | |||
| 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-Mid", ss.Get("Biukop-Mid")) | |||
| @@ -54,6 +54,7 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"POST", "user-enable/", apiV1UserEnable}, | |||
| {"GET", "user-ex/", apiV1UserExGet}, | |||
| {"POST", "user-ex/", apiV1UserExPost}, | |||
| {"GET", "user-ex-list/", apiV1UserExList}, | |||
| {"GET", "broker/", apiV1BrokerGet}, | |||
| @@ -139,6 +140,7 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"POST", "user-enable/", apiV1UserEnable}, | |||
| {"GET", "user-ex/", apiV1UserExGet}, | |||
| {"POST", "user-ex/", apiV1UserExPost}, | |||
| {"GET", "user-ex-list/", apiV1UserExList}, | |||
| {"GET", "broker/", apiV1BrokerGet}, | |||