| if e != nil { | if e != nil { | ||||
| apiV1EmptyResponse(w, r, ss) | apiV1EmptyResponse(w, r, ss) | ||||
| } else { | } else { | ||||
| switch ss.GetRole() { | |||||
| case "broker": | |||||
| input.Filter.Filters = append(input.Filter.Filters, loan.FullLoanSummaryFilter{ | |||||
| Field: "broker_ids", | |||||
| Operator: "contains", | |||||
| Value: loan.JsonString(ss.User)}) | |||||
| break | |||||
| case "user": | |||||
| input.Filter.Filters = append(input.Filter.Filters, loan.FullLoanSummaryFilter{ | |||||
| Field: "client_ids", | |||||
| Operator: "contains", | |||||
| Value: loan.JsonString(ss.User)}) | |||||
| break | |||||
| } | |||||
| data := loan.QFullLLoanSummary(input) | data := loan.QFullLLoanSummary(input) | ||||
| //send out | //send out | ||||
| apiV1SendJson(data, w, r, ss) | apiV1SendJson(data, w, r, ss) |
| package main | |||||
| import ( | |||||
| "biukop.com/sfm/loan" | |||||
| "net/http" | |||||
| ) | |||||
| func apiV1UserReward(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||||
| if ss.User == "" { | |||||
| apiV1Client403Error(w, r, ss) | |||||
| return | |||||
| } | |||||
| userId := ss.User | |||||
| if ss.GetRole() == "admin" { //allow admin to query other user | |||||
| userId = r.URL.Path[len(apiV1Prefix+"user-reward/"):] //remove prefix | |||||
| } | |||||
| data := loan.GetUserReward(userId) | |||||
| apiV1SendJson(data, w, r, ss) | |||||
| } |
| //format response | //format response | ||||
| res.add("login", true) | res.add("login", true) | ||||
| res.add("role", ss.GetRole()) | res.add("role", ss.GetRole()) | ||||
| u, e := ss.GetUser() | |||||
| if e == nil { | |||||
| res.add("user", u.People) | |||||
| } | |||||
| res.add("Biukop-Session", ss.Id) | res.add("Biukop-Session", ss.Id) | ||||
| res.add("Biukop-Mid", ss.Get("Biukop-Mid")) | res.add("Biukop-Mid", ss.Get("Biukop-Mid")) | ||||
| res.add("sessionExpire", ss.ExpireStr()) | res.add("sessionExpire", ss.ExpireStr()) |
| {"POST", "sync-people/", apiV1SyncPeople}, | {"POST", "sync-people/", apiV1SyncPeople}, | ||||
| {"POST", "payIn/", apiV1PayInPost}, | {"POST", "payIn/", apiV1PayInPost}, | ||||
| {"DELETE", "payIn/", apiV1PayInDelete}, | {"DELETE", "payIn/", apiV1PayInDelete}, | ||||
| {"GET", "user-reward/", apiV1UserReward}, | |||||
| {"GET", "login", apiV1DumpRequest}, | {"GET", "login", apiV1DumpRequest}, | ||||
| } | } | ||||
| } else { //production | } else { //production | ||||
| {"POST", "sync-people/", apiV1SyncPeople}, | {"POST", "sync-people/", apiV1SyncPeople}, | ||||
| {"POST", "payIn/", apiV1PayInPost}, | {"POST", "payIn/", apiV1PayInPost}, | ||||
| {"DELETE", "payIn/", apiV1PayInDelete}, | {"DELETE", "payIn/", apiV1PayInDelete}, | ||||
| {"GET", "user-reward/", apiV1UserReward}, | |||||
| {"GET", "login", apiV1EmptyResponse}, | {"GET", "login", apiV1EmptyResponse}, | ||||
| } | } | ||||
| } | } |