mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2026-01-06 06:51:32 +00:00
refactor code
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user