Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

61 line
1.2KB

  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.Rating = input.Rating
  42. l.Description = input.Description
  43. e = l.WriteBasic()
  44. if e != nil {
  45. apiV1Client404Error(w, r, ss)
  46. } else {
  47. apiV1SendJson(l, w, r, ss)
  48. }
  49. }
  50. }