Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

59 lines
1.2KB

  1. package main
  2. import (
  3. "biukop.com/sfm/loan"
  4. "encoding/json"
  5. log "github.com/sirupsen/logrus"
  6. "net/http"
  7. )
  8. func apiV1UserExList(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  9. filter := ""
  10. keys, ok := r.URL.Query()["filter"]
  11. if ok && len(keys) >= 1 {
  12. filter = keys[0]
  13. }
  14. data := loan.GetUserExList(filter)
  15. apiV1SendJson(data, w, r, ss)
  16. }
  17. func apiV1UserExGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  18. id := r.URL.Path[len(apiV1Prefix+"user-ex/"):]
  19. ret := loan.UserEx{}
  20. e := ret.Read(id)
  21. if e != nil {
  22. log.Error("read people error", id, e.Error())
  23. apiV1Client404Error(w, r, ss)
  24. return
  25. }
  26. apiV1SendJson(ret, w, r, ss)
  27. }
  28. func decodeJsonUserEx(r *http.Request) (ret loan.UserEx, e error) {
  29. decoder := json.NewDecoder(r.Body)
  30. //decoder.DisallowUnknownFields()
  31. e = decoder.Decode(&ret)
  32. if e != nil {
  33. log.Error("failed decoding json for UserEx ", e.Error())
  34. return
  35. }
  36. return
  37. }
  38. func apiV1UserExPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  39. input, e := decodeJsonUserEx(r)
  40. log.Println(input)
  41. if e != nil {
  42. apiV1Client404Error(w, r, ss)
  43. return
  44. }
  45. e = input.Write()
  46. if e != nil {
  47. apiV1Client404Error(w, r, ss)
  48. return
  49. }
  50. apiV1SendJson(input, w, r, ss)
  51. }