| @@ -2,6 +2,7 @@ | |||
| <module type="WEB_MODULE" version="4"> | |||
| <component name="Go" enabled="true" /> | |||
| <component name="NewModuleRootManager"> | |||
| <content url="file://$USER_HOME$/GolandProjects/SFM-loan" /> | |||
| <content url="file://$MODULE_DIR$" /> | |||
| <orderEntry type="inheritedJdk" /> | |||
| <orderEntry type="sourceFolder" forTests="false" /> | |||
| @@ -0,0 +1,29 @@ | |||
| package main | |||
| import ( | |||
| "biukop.com/sfm/loan" | |||
| log "github.com/sirupsen/logrus" | |||
| "net/http" | |||
| ) | |||
| func apiV1PeopleList(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| filter := "" | |||
| keys, ok := r.URL.Query()["filter"] | |||
| if ok && len(keys) >= 1 { | |||
| filter = keys[0] | |||
| } | |||
| data := loan.GetPeopleList(filter) | |||
| apiV1SendJson(data, w, r, ss) | |||
| } | |||
| func apiV1PeopleGet(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||
| id := r.URL.Path[len(apiV1Prefix+"people/"):] | |||
| p := loan.People{} | |||
| e := p.Read(id) | |||
| if e != nil { | |||
| log.Error("cannot find people by id", id) | |||
| apiV1Client404Error(w, r, ss) | |||
| return | |||
| } | |||
| apiV1SendJson(p, w, r, ss) | |||
| } | |||
| @@ -0,0 +1,66 @@ | |||
| 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) | |||
| } | |||
| @@ -37,8 +37,12 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"GET", "chart/top-broker", apiV1ChartTopBroker}, | |||
| {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | |||
| {"GET", "loan/", apiV1LoanSingleGet}, | |||
| {"GET", "people/", apiV1PeopleGet}, | |||
| {"POST", "loan/basic/", apiV1LoanSinglePostBasic}, | |||
| {"GET", "avatar/", apiV1Avatar}, | |||
| {"POST", "reward/", apiV1RewardPost}, | |||
| {"DELETE", "reward/", apiV1RewardDelete}, | |||
| {"GET", "people-list", apiV1PeopleList}, | |||
| {"GET", "login", apiV1DumpRequest}, | |||
| } | |||
| } else { //production | |||
| @@ -52,8 +56,12 @@ func setupApiV1Handler() []apiV1HandlerMap { | |||
| {"GET", "chart/top-broker", apiV1ChartTopBroker}, | |||
| {"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, | |||
| {"GET", "loan/", apiV1LoanSingleGet}, | |||
| {"GET", "people/", apiV1PeopleGet}, | |||
| {"POST", "loan/basic/", apiV1LoanSinglePostBasic}, | |||
| {"GET", "avatar/", apiV1Avatar}, | |||
| {"POST", "reward/", apiV1RewardPost}, | |||
| {"DELETE", "reward/", apiV1RewardDelete}, | |||
| {"GET", "people-list", apiV1PeopleList}, | |||
| {"GET", "login", apiV1EmptyResponse}, | |||
| } | |||
| } | |||