From 75fbbd8ca489dea8dc303d5e9044da48a162fe97 Mon Sep 17 00:00:00 2001 From: Yuli Date: Mon, 27 Jan 2020 11:29:22 +0200 Subject: [PATCH] refactor code --- src/bunker.go | 2 +- src/consent_api.go | 5 ++--- src/consent_db.go | 4 ++-- src/qldb.go | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/bunker.go b/src/bunker.go index c669fbe..bf315e6 100644 --- a/src/bunker.go +++ b/src/bunker.go @@ -172,7 +172,7 @@ func (e mainEnv) setupRouter() *httprouter.Router { router.GET("/v1/consent/:mode/:address", e.consentAllUserRecords) router.GET("/v1/consent/:mode/:address/:brief", e.consentUserRecord) router.GET("/v1/consents/:brief", e.consentFilterRecords) - router.GET("/v1/consents", e.consentTypes) + router.GET("/v1/consents", e.consentBriefs) router.POST("/v1/consent/:mode/:address/:brief", e.consentAccept) router.DELETE("/v1/consent/:mode/:address/:brief", e.consentWithdraw) diff --git a/src/consent_api.go b/src/consent_api.go index 0b359b6..d2f0f59 100644 --- a/src/consent_api.go +++ b/src/consent_api.go @@ -378,11 +378,11 @@ func (e mainEnv) consentFilterRecords(w http.ResponseWriter, r *http.Request, ps w.Write([]byte(str)) } -func (e mainEnv) consentTypes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { +func (e mainEnv) consentBriefs(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { if e.enforceAuth(w, r, nil) == "" { return } - resultJSON, numRecords, err := e.db.getConsentTypes() + resultJSON, numRecords, err := e.db.getConsentBriefs() if err != nil { returnError(w, r, "internal error", 405, err, nil) return @@ -395,4 +395,3 @@ func (e mainEnv) consentTypes(w http.ResponseWriter, r *http.Request, ps httprou str := fmt.Sprintf(`{"status":"ok","total":%d,"briefs":%s}`, numRecords, resultJSON) w.Write([]byte(str)) } - diff --git a/src/consent_db.go b/src/consent_db.go index 56c8a91..f7cd68c 100644 --- a/src/consent_db.go +++ b/src/consent_db.go @@ -194,12 +194,12 @@ func (dbobj dbcon) filterConsentRecords(brief string, offset int32, limit int32) return resultJSON, count, nil } -func (dbobj dbcon) getConsentTypes() ([]byte, int64, error) { +func (dbobj dbcon) getConsentBriefs() ([]byte, int64, error) { records, err := dbobj.getUniqueList(TblName.Consent, "brief") if err != nil { return nil, 0, err } - count:= int64(len(records)) + count := int64(len(records)) // we need to return only list of briefs var result []string for _, rec := range records { diff --git a/src/qldb.go b/src/qldb.go index 5c89d46..b668f8e 100644 --- a/src/qldb.go +++ b/src/qldb.go @@ -680,7 +680,7 @@ func (dbobj dbcon) getExpiring(t Tbl, keyName string, keyValue string) ([]bson.M func (dbobj dbcon) getUniqueList(t Tbl, keyName string) ([]bson.M, error) { table := getTable(t) keyName = escapeName(keyName) - q := "select distinct " + keyName +" from " + table + " ORDER BY " + keyName + q := "select distinct " + keyName + " from " + table + " ORDER BY " + keyName fmt.Printf("q: %s\n", q) return dbobj.getListDo(q, "") }