Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

80 Zeilen
1.7KB

  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 apiV1BrokerList(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.GetBrokerList(filter)
  15. apiV1SendJson(data, w, r, ss)
  16. }
  17. func apiV1BrokerGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  18. id := r.URL.Path[len(apiV1Prefix+"broker/"):]
  19. b := loan.Broker{}
  20. e := b.Read(id)
  21. if e != nil {
  22. log.Error("cannot find people by id", id)
  23. apiV1Client404Error(w, r, ss)
  24. return
  25. }
  26. apiV1SendJson(b, w, r, ss)
  27. }
  28. func decodeJsonBrokerEdit(r *http.Request) (ret loan.Broker, 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 Filtering full_loan_summary ", e.Error())
  34. return
  35. }
  36. return
  37. }
  38. func apiV1BrokerPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  39. id := r.URL.Path[len(apiV1Prefix+"broker/"):]
  40. b := loan.Broker{}
  41. e := b.Read(id)
  42. if e != nil {
  43. log.Error("cannot find broker by id", id, e.Error())
  44. apiV1Client404Error(w, r, ss)
  45. return
  46. }
  47. input, e := decodeJsonBrokerEdit(r)
  48. if e != nil {
  49. log.Error("cannot find broker by id", id, e.Error())
  50. apiV1Client404Error(w, r, ss)
  51. return
  52. }
  53. b.BSB = input.BSB
  54. b.ACC = input.ACC
  55. b.Display = input.Display
  56. b.First = input.First
  57. b.Last = input.Last
  58. b.License = input.License
  59. if ss.GetRole() == "admin" {
  60. b.Login = input.Login
  61. b.Organization = input.Organization
  62. }
  63. e = b.Write()
  64. if e != nil {
  65. log.Error("failed to save broker ", b, e.Error())
  66. apiV1Client404Error(w, r, ss)
  67. return
  68. }
  69. apiV1SendJson(b, w, r, ss)
  70. }