package main import ( "biukop.com/sfm/loan" "encoding/json" log "github.com/sirupsen/logrus" "net/http" "strconv" ) func decodeJsonRewardEdit(r *http.Request) (ret loan.Reward, e error) { decoder := json.NewDecoder(r.Body) //decoder.DisallowUnknownFields() e = decoder.Decode(&ret) if e != nil { log.Error("failed decoding json for edit Reward ", e.Error()) return } return } func apiV1RewardPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) { re := loan.Reward{} input, e := decodeJsonRewardEdit(r) log.Println(input) if e != nil { apiV1Client404Error(w, r, ss) return } else { re.Id = input.Id re.PayoutId = input.PayoutId re.Description = input.Description re.LoanId = input.LoanId re.Amount = input.Amount re.From = input.From re.To = input.To re.Ts = input.Ts e = re.Write() if e != nil { apiV1Client404Error(w, r, ss) } else { apiV1SendJson(re, w, r, ss) } } } func apiV1RewardDelete(w http.ResponseWriter, r *http.Request, ss *loan.Session) { id := r.URL.Path[len(apiV1Prefix+"reward/"):] id64, e := strconv.Atoi(id) if e != nil { log.Error("cannot find people by id", id) apiV1Client404Error(w, r, ss) return } e = loan.DeleteReward(int64(id64)) if e != nil { log.Error("cannot find people by id", id) apiV1Client404Error(w, r, ss) return } apiV1SendJson(id64, w, r, ss) }