From eaaa1a62245bbb60951c2a2318b5799193ce84b0 Mon Sep 17 00:00:00 2001 From: Leonardo Domingues Date: Tue, 9 Nov 2021 09:43:25 -0300 Subject: [PATCH] =?UTF-8?q?Inclus=C3=A3o=20de=20erro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dataapi/lib.go | 61 ++++++++++++++++++++------- api/dataapi/lib_test.go | 93 ++++++++++++++++++++++++++++++----------- 2 files changed, 114 insertions(+), 40 deletions(-) diff --git a/api/dataapi/lib.go b/api/dataapi/lib.go index 1909cc3..bb1e1ba 100644 --- a/api/dataapi/lib.go +++ b/api/dataapi/lib.go @@ -62,9 +62,11 @@ func LCR_Create() { } } -func RegistrarExec(table string) { +func RegistrarExec(table string, check bool) { //Para robôs, age como contador e registra cada repetição no mês c := NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") + var registros int + var erro int current := time.Now().Format("2006-01") res, err := c.Do(&DataAPIRequest{ Col: table, @@ -75,29 +77,56 @@ func RegistrarExec(table string) { panic(err) } if len(res.Data) > 0 { - result := res.Data[0].(map[string]interface{}) - registros := result["exec"].(float64) - registros = registros + 1 - ident := strconv.Itoa(int(result["ID"].(float64))) + if check { + result := res.Data[0].(map[string]interface{}) + registros = int(result["exec"].(float64)) + registros = registros + 1 + ident := strconv.Itoa(int(result["ID"].(float64))) - _, err = c.Do(&DataAPIRequest{ - Col: table, - Op: UPDATE, - Id: ident, - Data: map[string]interface{}{ - "exec": registros, - }, - }) - if err != nil { - panic(err) + _, err = c.Do(&DataAPIRequest{ + Col: table, + Op: UPDATE, + Id: ident, + Data: map[string]interface{}{ + "exec": registros, + }, + }) + if err != nil { + panic(err) + } + } else { + result := res.Data[0].(map[string]interface{}) + registros = int(result["err"].(float64)) + registros = registros + 1 + ident := strconv.Itoa(int(result["ID"].(float64))) + + _, err = c.Do(&DataAPIRequest{ + Col: table, + Op: UPDATE, + Id: ident, + Data: map[string]interface{}{ + "err": registros, + }, + }) + if err != nil { + panic(err) + } } } else { + if check { + registros = 1 + erro = 0 + } else { + registros = 0 + erro = 1 + } _, err = c.Do(&DataAPIRequest{ Col: table, Op: CREATE, Data: map[string]interface{}{ "date": current, - "exec": 1, + "exec": registros, + "err": erro, }, }) if err != nil { diff --git a/api/dataapi/lib_test.go b/api/dataapi/lib_test.go index 953ff4f..7893da8 100644 --- a/api/dataapi/lib_test.go +++ b/api/dataapi/lib_test.go @@ -2,7 +2,9 @@ package dataapi_test import ( "log" + "strconv" "testing" + "time" "go.digitalcircle.com.br/open/replaycli-go/api/dataapi" ) @@ -10,7 +12,7 @@ import ( func TestAPIRetrieve(t *testing.T) { c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") res, err := c.Do(&dataapi.DataAPIRequest{ - Col: "C1", + Col: "teste3", Op: dataapi.RETRIEVE, }) if err != nil { @@ -66,35 +68,78 @@ func TestAPIDelete(t *testing.T) { } func TestAPICreate(t *testing.T) { + if true { + print("a") + print("b") + } c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") - + var registros int + var erro int + current := time.Now().Format("2006-01") res, err := c.Do(&dataapi.DataAPIRequest{ - Col: "C1", - Op: dataapi.CREATE, - Data: map[string]interface{}{ - "MSG": "OI LEO", - }, + Col: "teste3", + Op: dataapi.RETRIEVE, + Q: "@[?date=='" + current + "']", }) if err != nil { - t.Fatal(err.Error()) + panic(err) } + check := false + if len(res.Data) > 0 { + if check { + result := res.Data[0].(map[string]interface{}) + registros = int(result["exec"].(float64)) + registros = registros + 1 + ident := strconv.Itoa(int(result["ID"].(float64))) - log.Printf("%#v", res) -} + _, err = c.Do(&dataapi.DataAPIRequest{ + Col: "teste3", + Op: dataapi.UPDATE, + Id: ident, + Data: map[string]interface{}{ + "exec": registros, + }, + }) + if err != nil { + panic(err) + } + } else { + result := res.Data[0].(map[string]interface{}) + registros = int(result["err"].(float64)) + registros = registros + 1 + ident := strconv.Itoa(int(result["ID"].(float64))) -func LCR_Create(t *testing.T) { - c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") - - res, err := c.Do(&dataapi.DataAPIRequest{ - Col: "LCR_Bot", - Op: dataapi.CREATE, - Data: map[string]interface{}{ - "Registro": "1", - }, - }) - if err != nil { - t.Fatal(err.Error()) + _, err = c.Do(&dataapi.DataAPIRequest{ + Col: "teste3", + Op: dataapi.UPDATE, + Id: ident, + Data: map[string]interface{}{ + "err": registros, + }, + }) + if err != nil { + panic(err) + } + } + } else { + if check { + registros = 1 + erro = 0 + } else { + registros = 0 + erro = 1 + } + _, err = c.Do(&dataapi.DataAPIRequest{ + Col: "teste3", + Op: dataapi.CREATE, + Data: map[string]interface{}{ + "date": current, + "exec": registros, + "err": erro, + }, + }) + if err != nil { + panic(err) + } } - - log.Printf("%#v", res) }