Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

105 lines
2.5KB

  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 apiV1LoanSingleGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  9. l := loan.Loan{}
  10. loanId := r.URL.Path[len(apiV1Prefix+"loan/"):] //remove prefix
  11. e := l.Read(loanId)
  12. if e != nil {
  13. log.Error("cannot read loan by id ", loanId)
  14. apiV1Client404Error(w, r, ss)
  15. return
  16. }
  17. apiV1SendJson(l, w, r, ss)
  18. }
  19. func decodeJsonLoanEdit(r *http.Request) (ret loan.Loan, e error) {
  20. decoder := json.NewDecoder(r.Body)
  21. //decoder.DisallowUnknownFields()
  22. e = decoder.Decode(&ret)
  23. if e != nil {
  24. log.Error("failed decoding json for Filtering full_loan_summary ", e.Error())
  25. return
  26. }
  27. return
  28. }
  29. func apiV1LoanSinglePostBasic(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  30. l := loan.Loan{}
  31. input, e := decodeJsonLoanEdit(r)
  32. log.Println(input)
  33. if e != nil {
  34. apiV1Client404Error(w, r, ss)
  35. return
  36. } else {
  37. l.Id = input.Id
  38. l.Status = input.Status
  39. l.Amount = input.Amount
  40. l.Item = input.Item
  41. l.Lender = input.Lender
  42. l.LenderLoanNumber = input.LenderLoanNumber
  43. l.Rating = input.Rating
  44. l.Settlement = input.Settlement
  45. l.Description = input.Description
  46. l.ApplicationReceived = input.ApplicationReceived
  47. l.Lodgement = input.Lodgement
  48. l.ValuationOrdered = input.ValuationOrdered
  49. l.ValuationCompleted = input.ValuationCompleted
  50. l.ConditionalApproved = input.ConditionalApproved
  51. l.OutstandingReturned = input.OutstandingReturned
  52. l.FormalApproved = input.FormalApproved
  53. l.SettlementBooked = input.SettlementBooked
  54. l.SettlementCompleted = input.SettlementCompleted
  55. e = l.WriteBasic()
  56. if e != nil {
  57. log.Error("cannot save basic loan", e.Error())
  58. apiV1Client404Error(w, r, ss)
  59. return
  60. }
  61. e = l.WriteMileStone()
  62. if e != nil {
  63. log.Error("cannot save milestone ", e.Error())
  64. apiV1Server500Error(w, r)
  65. return
  66. }
  67. apiV1SendJson(l, w, r, ss)
  68. }
  69. }
  70. func apiV1LoanSingleDelete(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  71. loanId := r.URL.Path[len(apiV1Prefix+"loan/"):] //remove prefix
  72. e := loan.Delete(loanId)
  73. if e != nil {
  74. log.Error("cannot delete loan by id ", loanId, e.Error())
  75. apiV1Client404Error(w, r, ss)
  76. return
  77. }
  78. apiV1SendJson(loanId, w, r, ss)
  79. }
  80. func apiV1LoanByClient(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  81. clientId := r.URL.Path[len(apiV1Prefix+"loan-by-client/"):] //remove prefix
  82. data := loan.GetLoansByClient(clientId)
  83. apiV1SendJson(data, w, r, ss)
  84. }