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.

67 Zeilen
1.4KB

  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 decodeJsonPayInEdit(r *http.Request) (ret loan.PayIn, 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 PayIn for updating", e.Error())
  15. return
  16. }
  17. return
  18. }
  19. func apiV1PayInPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  20. input, e := decodeJsonPayInEdit(r)
  21. log.Println(input)
  22. if e != nil {
  23. apiV1Client404Error(w, r, ss)
  24. return
  25. } else {
  26. e = input.Write()
  27. if e != nil {
  28. log.Error("cannot save basic loan", e.Error())
  29. apiV1Client404Error(w, r, ss)
  30. } else {
  31. piEx := loan.PayInEx{}
  32. e = piEx.Read(input.Id)
  33. if e != nil {
  34. log.Error("weird failed to read PayInEx after successfully write PayIn", input, piEx, e.Error())
  35. apiV1Client404Error(w, r, ss)
  36. } else {
  37. apiV1SendJson(piEx, w, r, ss)
  38. }
  39. }
  40. }
  41. }
  42. func apiV1PayInDelete(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  43. id := r.URL.Path[len(apiV1Prefix+"payIn/"):] //remove prefix
  44. idx, e := strconv.Atoi(id)
  45. if e != nil {
  46. log.Error("cannot identify PayInId ", id, e.Error())
  47. apiV1Client404Error(w, r, ss)
  48. return
  49. }
  50. e = loan.DeletePayIn(int64(idx))
  51. if e != nil {
  52. log.Error("cannot delete PayIn by id ", id, e.Error())
  53. apiV1Client404Error(w, r, ss)
  54. return
  55. }
  56. apiV1SendJson(idx, w, r, ss)
  57. }