Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

66 linhas
1.6KB

  1. package main
  2. import (
  3. "biukop.com/sfm/loan"
  4. "database/sql"
  5. log "github.com/sirupsen/logrus"
  6. "net/http"
  7. "strconv"
  8. )
  9. func apiV1PayOutExGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  10. strId := r.URL.Path[len(apiV1Prefix+"payout-ex/"):]
  11. ret := loan.PayOutEx{}
  12. id, e := strconv.Atoi(strId)
  13. if e != nil {
  14. log.Error("invalid id for PayOutEx", strId, e.Error())
  15. apiV1Client403Error(w, r, ss)
  16. }
  17. e = ret.Read(int64(id))
  18. if e != nil {
  19. if e == sql.ErrNoRows {
  20. apiV1Client404Error(w, r, ss)
  21. return
  22. }
  23. log.Error("failed to read PayOutEx", strId, e.Error())
  24. apiV1Server500Error(w, r)
  25. return
  26. }
  27. apiV1SendJson(ret, w, r, ss)
  28. return
  29. }
  30. func apiV1PayOutExListGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  31. // strId := r.URL.Path[len(apiV1Prefix+"payout-ex-list/"):]
  32. input, e := decodeJsonFullLoanOverview(r)
  33. // TODO; Generalize that input, and return a list of filters and sort
  34. // Todo: do some serious query for the data in the Grid, and make it a pattern. Get it done!
  35. if e != nil {
  36. apiV1EmptyResponse(w, r, ss)
  37. } else {
  38. switch ss.GetRole() {
  39. case "broker":
  40. input.Filter.Filters = append(input.Filter.Filters, loan.FullLoanSummaryFilter{
  41. Field: "broker_ids",
  42. Operator: "contains",
  43. Value: loan.JsonString(ss.User)})
  44. break
  45. case "user":
  46. input.Filter.Filters = append(input.Filter.Filters, loan.FullLoanSummaryFilter{
  47. Field: "client_ids",
  48. Operator: "contains",
  49. Value: loan.JsonString(ss.User)})
  50. break
  51. }
  52. data := loan.QFullLLoanSummary(input)
  53. //send out
  54. apiV1SendJson(data, w, r, ss)
  55. }
  56. }