From d52fc8c5cff155950835baf5a185d9abb3999f86 Mon Sep 17 00:00:00 2001 From: sp Date: Sat, 10 Apr 2021 17:14:14 +1000 Subject: [PATCH] PayIn list wit new filter --- apiV1PayInList.go | 37 +++++++++++++++++++++++++++++++++++++ apiV1Uploads.go | 4 ++-- apiv1.go | 6 ++++++ html/index.html | 5 +++++ payIn-AAA.go | 16 +++++++++------- 5 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 apiV1PayInList.go diff --git a/apiV1PayInList.go b/apiV1PayInList.go new file mode 100644 index 0000000..f14dcda --- /dev/null +++ b/apiV1PayInList.go @@ -0,0 +1,37 @@ +package main + +import ( + "biukop.com/sfm/loan" + "encoding/json" + log "github.com/sirupsen/logrus" + "net/http" +) + +func decodePayInFilter(r *http.Request) (ret loan.PayInListFilter, e error) { + decoder := json.NewDecoder(r.Body) + //decoder.DisallowUnknownFields() + e = decoder.Decode(&ret) + if e != nil { + log.Error("failed decoding PayIn list filter", e.Error()) + return + } + return +} + +func apiV1PayInList(w http.ResponseWriter, r *http.Request, ss *loan.Session) { + filter, e := decodePayInFilter(r) + if e != nil { + log.Error("invalid pay in list filter", filter, e) + apiV1Client404Error(w, r, ss) + return + } + + ret, e := filter.RetrieveData() + if e != nil { + log.Error("failed to retrieve PayIn list", filter, e) + apiV1Server500Error(w, r) + return + } + + apiV1SendJson(ret, w, r, ss) +} diff --git a/apiV1Uploads.go b/apiV1Uploads.go index 24fae6a..4c5af11 100644 --- a/apiV1Uploads.go +++ b/apiV1Uploads.go @@ -242,7 +242,7 @@ func apiV1UploadAsImage(w http.ResponseWriter, r *http.Request, ss *loan.Session if e != nil { return } - + //time.Sleep(5* time.Second); // if this is image itself, serve it directly if strings.Contains(strings.ToLower(ul.Upload.Format), "image") { f, e := os.Open(ul.filePath()) @@ -336,7 +336,7 @@ func apiV1UploadAsPDF(w http.ResponseWriter, r *http.Request, ss *loan.Session) if forceHttpDownload(r) { w.Header().Set("Content-Disposition", "attachment; filename="+ul.Upload.FileName) } - http.ServeContent(w, r, ul.filePath(), fi.ModTime(), f) + http.ServeContent(w, r, ul.Upload.FileName, fi.ModTime(), f) return } } diff --git a/apiv1.go b/apiv1.go index cb21af1..d8c1b6d 100644 --- a/apiv1.go +++ b/apiv1.go @@ -66,8 +66,11 @@ func setupApiV1Handler() []apiV1HandlerMap { {"GET", "people-list/", apiV1PeopleList}, {"GET", "broker-list/", apiV1BrokerList}, {"POST", "sync-people/", apiV1SyncPeople}, + {"POST", "payIn/", apiV1PayInPost}, {"DELETE", "payIn/", apiV1PayInDelete}, + {"POST", "pay-in-list/", apiV1PayInList}, + {"GET", "user-reward/", apiV1UserReward}, {"GET", "login-available/", apiV1LoginAvailable}, @@ -124,8 +127,11 @@ func setupApiV1Handler() []apiV1HandlerMap { {"GET", "people-list", apiV1PeopleList}, {"GET", "broker-list/", apiV1BrokerList}, {"POST", "sync-people/", apiV1SyncPeople}, + {"POST", "payIn/", apiV1PayInPost}, {"DELETE", "payIn/", apiV1PayInDelete}, + {"POST", "pay-in-list/", apiV1PayInList}, + {"GET", "user-reward/", apiV1UserReward}, {"GET", "login-available/", apiV1LoginAvailable}, diff --git a/html/index.html b/html/index.html index 55e588c..6161a80 100644 --- a/html/index.html +++ b/html/index.html @@ -59,6 +59,11 @@

+ + + + + diff --git a/payIn-AAA.go b/payIn-AAA.go index c2ce446..8cda041 100644 --- a/payIn-AAA.go +++ b/payIn-AAA.go @@ -42,7 +42,7 @@ func (m *AiDecodeIncome) decodeAAAPdf(raw string) (e error) { m.AAA = make([]PayInAAAPeriod, 0, 10) lines := strings.Split(raw, "\n") - currentDecoder := PayInAAAPeriod{} + var currentDecoder *PayInAAAPeriod = nil state := "start" for _, l := range lines { // DFA, wow, finally it's used. after years of learning switch state { @@ -55,25 +55,27 @@ func (m *AiDecodeIncome) decodeAAAPdf(raw string) (e error) { case "LookingForPeriod": state = currentDecoder.processPeriod(l) if state == "LookingForRows" { - currentDecoder.Period, e = currentDecoder.getPeriod(l) - currentDecoder.Rows = make([]PayInAAARow, 0, 10) + Period, e := currentDecoder.getPeriod(l) if e != nil { log.Warn("cannot find period", l, e) state = "LookingForPeriod" } else { - m.AAA = append(m.AAA, currentDecoder) - + m.AAA = append(m.AAA, PayInAAAPeriod{}) + idx := len(m.AAA) - 1 + currentDecoder = &(m.AAA[idx]) + currentDecoder.Rows = make([]PayInAAARow, 0, 10) + currentDecoder.Period = Period } } break case "LookingForRows", "LookingForRowsSkipCurrent": nextState, row, valid := currentDecoder.processRow(l) - if valid { + if valid && currentDecoder != nil { currentDecoder.Rows = append(currentDecoder.Rows, row) } state = nextState if nextState == "start" { - currentDecoder = PayInAAAPeriod{} //renew to a empty state + currentDecoder = nil //renew to a empty state } break }