Przeglądaj źródła

PayIn Api implemented

master
sp 4 lat temu
rodzic
commit
f49416e1ec
2 zmienionych plików z 63 dodań i 0 usunięć
  1. +59
    -0
      apiV1PayIn.go
  2. +4
    -0
      apiv1.go

+ 59
- 0
apiV1PayIn.go Wyświetl plik

@@ -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)
}

+ 4
- 0
apiv1.go Wyświetl plik

@@ -47,6 +47,8 @@ func setupApiV1Handler() []apiV1HandlerMap {
{"GET", "people-list/", apiV1PeopleList},
{"GET", "broker-list/", apiV1BrokerList},
{"POST", "sync-people/", apiV1SyncPeople},
{"POST", "payIn/", apiV1PayInPost},
{"DELETE", "payIn/", apiV1PayInDelete},
{"GET", "login", apiV1DumpRequest},
}
} else { //production
@@ -70,6 +72,8 @@ func setupApiV1Handler() []apiV1HandlerMap {
{"GET", "people-list", apiV1PeopleList},
{"GET", "broker-list/", apiV1BrokerList},
{"POST", "sync-people/", apiV1SyncPeople},
{"POST", "payIn/", apiV1PayInPost},
{"DELETE", "payIn/", apiV1PayInDelete},
{"GET", "login", apiV1EmptyResponse},
}
}

Ładowanie…
Anuluj
Zapisz