|
- package main
-
- import (
- "biukop.com/sfm/loan"
- "encoding/json"
- log "github.com/sirupsen/logrus"
- "net/http"
- )
-
- func apiV1LoanSingleGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
- l := loan.Loan{}
-
- loanId := r.URL.Path[len(apiV1Prefix+"loan/"):] //remove prefix
- e := l.Read(loanId)
- if e != nil {
- log.Error("cannot read loan by id ", loanId)
- apiV1Client404Error(w, r, ss)
- return
- }
-
- apiV1SendJson(l, w, r, ss)
-
- }
-
- func decodeJsonLoanEdit(r *http.Request) (ret loan.Loan, e error) {
- decoder := json.NewDecoder(r.Body)
- //decoder.DisallowUnknownFields()
- e = decoder.Decode(&ret)
- if e != nil {
- log.Error("failed decoding json for Filtering full_loan_summary ", e.Error())
- return
- }
- return
- }
- func apiV1LoanSinglePostBasic(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
- l := loan.Loan{}
-
- input, e := decodeJsonLoanEdit(r)
-
- log.Println(input)
- if e != nil {
- apiV1Client404Error(w, r, ss)
- return
- } else {
- l.Id = input.Id
- l.Status = input.Status
- l.Amount = input.Amount
- l.Item = input.Item
- l.Rating = input.Rating
- l.Settlement = input.Settlement
- l.Description = input.Description
- e = l.WriteBasic()
- if e != nil {
- log.Error("cannot save basic loan", e.Error())
- apiV1Client404Error(w, r, ss)
- } else {
- apiV1SendJson(l, w, r, ss)
- }
-
- }
-
- }
-
- func apiV1LoanSingleDelete(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
- loanId := r.URL.Path[len(apiV1Prefix+"loan/"):] //remove prefix
-
- e := loan.Delete(loanId)
- if e != nil {
- log.Error("cannot delete loan by id ", loanId, e.Error())
- apiV1Client404Error(w, r, ss)
- return
- }
-
- apiV1SendJson(loanId, w, r, ss)
-
- }
|