|
- 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)
- }
|