Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

80 lines
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. "strconv"
  8. )
  9. func decodeJsonRewardEdit(r *http.Request) (ret loan.Reward, e error) {
  10. decoder := json.NewDecoder(r.Body)
  11. //decoder.DisallowUnknownFields()
  12. e = decoder.Decode(&ret)
  13. if e != nil {
  14. log.Error("failed decoding json for edit Reward ", e.Error())
  15. return
  16. }
  17. return
  18. }
  19. func apiV1RewardPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  20. re := loan.Reward{}
  21. input, e := decodeJsonRewardEdit(r)
  22. log.Println(input)
  23. if e != nil {
  24. apiV1Client404Error(w, r, ss)
  25. return
  26. } else {
  27. re.Id = input.Id
  28. re.PayOutId = input.PayOutId
  29. re.Description = input.Description
  30. re.LoanId = input.LoanId
  31. re.Amount = input.Amount
  32. re.FromId = input.FromId
  33. re.ToId = input.ToId
  34. re.Ts = input.Ts
  35. e = re.Write()
  36. if e != nil {
  37. apiV1Client404Error(w, r, ss)
  38. } else {
  39. apiV1SendJson(re, w, r, ss)
  40. }
  41. }
  42. }
  43. func apiV1RewardDelete(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  44. id := r.URL.Path[len(apiV1Prefix+"reward/"):]
  45. id64, e := strconv.Atoi(id)
  46. if e != nil {
  47. log.Error("cannot find people by id", id)
  48. apiV1Client404Error(w, r, ss)
  49. return
  50. }
  51. e = loan.DeleteReward(int64(id64))
  52. if e != nil {
  53. log.Error("cannot find people by id", id)
  54. apiV1Client404Error(w, r, ss)
  55. return
  56. }
  57. apiV1SendJson(id64, w, r, ss)
  58. }
  59. func apiV1RewardExListPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  60. input := loan.KdQueryInput{}
  61. e := input.ReadFromHttpRequest(r)
  62. if e != nil {
  63. apiV1Client404Error(w, r, ss)
  64. return
  65. }
  66. rewardListFilter := loan.RewardExListFilter{KdQueryInput: input}
  67. ret := rewardListFilter.Retrieve()
  68. apiV1SendJson(ret, w, r, ss)
  69. return
  70. }