|
- 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.Lender = input.Lender
- l.LenderLoanNumber = input.LenderLoanNumber
- l.Rating = input.Rating
- l.Settlement = input.Settlement
- l.Description = input.Description
-
- l.ApplicationReceived = input.ApplicationReceived
- l.Lodgement = input.Lodgement
- l.ValuationOrdered = input.ValuationOrdered
- l.ValuationCompleted = input.ValuationCompleted
- l.ConditionalApproved = input.ConditionalApproved
- l.OutstandingReturned = input.OutstandingReturned
- l.FormalApproved = input.FormalApproved
- l.SettlementBooked = input.SettlementBooked
- l.SettlementCompleted = input.SettlementCompleted
-
- e = l.WriteBasic()
- if e != nil {
- log.Error("cannot save basic loan", e.Error())
- apiV1Client404Error(w, r, ss)
- return
- }
-
- e = l.WriteMileStone()
- if e != nil {
- log.Error("cannot save milestone ", e.Error())
- apiV1Server500Error(w, r)
- return
- }
- 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)
-
- }
-
- func apiV1LoanByClient(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
- clientId := r.URL.Path[len(apiV1Prefix+"loan-by-client/"):] //remove prefix
-
- data := loan.GetLoansByClient(clientId)
-
- apiV1SendJson(data, w, r, ss)
-
- }
|