|
|
|
@@ -0,0 +1,59 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"biukop.com/sfm/loan" |
|
|
|
"encoding/json" |
|
|
|
log "github.com/sirupsen/logrus" |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
|
|
|
|
func decodeJsonPayInEdit(r *http.Request) (ret loan.PayIn, e error) { |
|
|
|
decoder := json.NewDecoder(r.Body) |
|
|
|
//decoder.DisallowUnknownFields() |
|
|
|
e = decoder.Decode(&ret) |
|
|
|
if e != nil { |
|
|
|
log.Error("failed decoding PayIn for updating", e.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func apiV1PayInPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) { |
|
|
|
|
|
|
|
input, e := decodeJsonPayInEdit(r) |
|
|
|
log.Println(input) |
|
|
|
|
|
|
|
if e != nil { |
|
|
|
apiV1Client404Error(w, r, ss) |
|
|
|
return |
|
|
|
} else { |
|
|
|
e = input.Write() |
|
|
|
if e != nil { |
|
|
|
log.Error("cannot save basic loan", e.Error()) |
|
|
|
apiV1Client404Error(w, r, ss) |
|
|
|
} else { |
|
|
|
apiV1SendJson(input, w, r, ss) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func apiV1PayInDelete(w http.ResponseWriter, r *http.Request, ss *loan.Session) { |
|
|
|
id := r.URL.Path[len(apiV1Prefix+"payIn/"):] //remove prefix |
|
|
|
idx, e := strconv.Atoi(id) |
|
|
|
|
|
|
|
if e != nil { |
|
|
|
log.Error("cannot identify PayInId ", id, e.Error()) |
|
|
|
apiV1Client404Error(w, r, ss) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
e = loan.DeletePayIn(int64(idx)) |
|
|
|
if e != nil { |
|
|
|
log.Error("cannot delete PayIn by id ", id, e.Error()) |
|
|
|
apiV1Client404Error(w, r, ss) |
|
|
|
return |
|
|
|
} |
|
|
|
apiV1SendJson(idx, w, r, ss) |
|
|
|
} |