From 29eb1c7b4408f149ec77e6f5fe1ef87575ce42c6 Mon Sep 17 00:00:00 2001 From: Patricia Reinoso Date: Thu, 23 Jan 2025 17:41:14 +0100 Subject: [PATCH] modify order parameters in functions (#109) Signed-off-by: Patricia Reinoso --- VERSION | 2 +- mongoapi/dbadapter.go | 30 +++++++++++++++--------------- mongoapi/mongoapi.go | 26 +++++++++++++++----------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/VERSION b/VERSION index eea37bd..f2ae0b4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.12-dev +1.2.12 diff --git a/mongoapi/dbadapter.go b/mongoapi/dbadapter.go index 2ed05ea..3d09073 100644 --- a/mongoapi/dbadapter.go +++ b/mongoapi/dbadapter.go @@ -18,20 +18,20 @@ type DBInterface interface { RestfulAPIGetMany(collName string, filter bson.M) ([]map[string]interface{}, error) RestfulAPIPutOneTimeout(collName string, filter bson.M, putData map[string]interface{}, timeout int32, timeField string) bool RestfulAPIPutOne(collName string, filter bson.M, putData map[string]interface{}) (bool, error) - RestfulAPIPutOneWithContext(collName string, filter bson.M, putData map[string]interface{}, context context.Context) (bool, error) + RestfulAPIPutOneWithContext(context context.Context, collName string, filter bson.M, putData map[string]interface{}) (bool, error) RestfulAPIPutOneNotUpdate(collName string, filter bson.M, putData map[string]interface{}) (bool, error) RestfulAPIPutMany(collName string, filterArray []primitive.M, putDataArray []map[string]interface{}) error RestfulAPIDeleteOne(collName string, filter bson.M) error - RestfulAPIDeleteOneWithContext(collName string, filter bson.M, context context.Context) error + RestfulAPIDeleteOneWithContext(context context.Context, collName string, filter bson.M) error RestfulAPIDeleteMany(collName string, filter bson.M) error RestfulAPIMergePatch(collName string, filter bson.M, patchData map[string]interface{}) error RestfulAPIJSONPatch(collName string, filter bson.M, patchJSON []byte) error - RestfulAPIJSONPatchWithContext(collName string, filter bson.M, patchJSON []byte, context context.Context) error + RestfulAPIJSONPatchWithContext(context context.Context, collName string, filter bson.M, patchJSON []byte) error RestfulAPIJSONPatchExtend(collName string, filter bson.M, patchJSON []byte, dataName string) error RestfulAPIPost(collName string, filter bson.M, postData map[string]interface{}) (bool, error) - RestfulAPIPostWithContext(collName string, filter bson.M, postData map[string]interface{}, context context.Context) (bool, error) + RestfulAPIPostWithContext(context context.Context, collName string, filter bson.M, postData map[string]interface{}) (bool, error) RestfulAPIPostMany(collName string, filter bson.M, postDataArray []interface{}) error - RestfulAPIPostManyWithContext(collName string, filter bson.M, postDataArray []interface{}, context context.Context) error + RestfulAPIPostManyWithContext(context context.Context, collName string, filter bson.M, postDataArray []interface{}) error GetUniqueIdentity(idName string) int32 CreateIndex(collName string, keyField string) (bool, error) StartSession() (mongo.Session, error) @@ -90,8 +90,8 @@ func (db *MongoDBClient) RestfulAPIPutOne(collName string, filter bson.M, putDat return db.MongoClient.RestfulAPIPutOne(collName, filter, putData) } -func (db *MongoDBClient) RestfulAPIPutOneWithContext(collName string, filter bson.M, putData map[string]interface{}, context context.Context) (bool, error) { - return db.MongoClient.RestfulAPIPutOneWithContext(collName, filter, putData, context) +func (db *MongoDBClient) RestfulAPIPutOneWithContext(context context.Context, collName string, filter bson.M, putData map[string]interface{}) (bool, error) { + return db.MongoClient.RestfulAPIPutOneWithContext(context, collName, filter, putData) } func (db *MongoDBClient) RestfulAPIPutOneNotUpdate(collName string, filter bson.M, putData map[string]interface{}) (bool, error) { @@ -106,8 +106,8 @@ func (db *MongoDBClient) RestfulAPIDeleteOne(collName string, filter bson.M) err return db.MongoClient.RestfulAPIDeleteOne(collName, filter) } -func (db *MongoDBClient) RestfulAPIDeleteOneWithContext(collName string, filter bson.M, context context.Context) error { - return db.MongoClient.RestfulAPIDeleteOneWithContext(collName, filter, context) +func (db *MongoDBClient) RestfulAPIDeleteOneWithContext(context context.Context, collName string, filter bson.M) error { + return db.MongoClient.RestfulAPIDeleteOneWithContext(context, collName, filter) } func (db *MongoDBClient) RestfulAPIDeleteMany(collName string, filter bson.M) error { @@ -122,8 +122,8 @@ func (db *MongoDBClient) RestfulAPIJSONPatch(collName string, filter bson.M, pat return db.MongoClient.RestfulAPIJSONPatch(collName, filter, patchJSON) } -func (db *MongoDBClient) RestfulAPIJSONPatchWithContext(collName string, filter bson.M, patchJSON []byte, context context.Context) error { - return db.MongoClient.RestfulAPIJSONPatchWithContext(collName, filter, patchJSON, context) +func (db *MongoDBClient) RestfulAPIJSONPatchWithContext(context context.Context, collName string, filter bson.M, patchJSON []byte) error { + return db.MongoClient.RestfulAPIJSONPatchWithContext(context, collName, filter, patchJSON) } func (db *MongoDBClient) RestfulAPIJSONPatchExtend(collName string, filter bson.M, patchJSON []byte, dataName string) error { @@ -134,16 +134,16 @@ func (db *MongoDBClient) RestfulAPIPost(collName string, filter bson.M, postData return db.MongoClient.RestfulAPIPost(collName, filter, postData) } -func (db *MongoDBClient) RestfulAPIPostWithContext(collName string, filter bson.M, postData map[string]interface{}, context context.Context) (bool, error) { - return db.MongoClient.RestfulAPIPostWithContext(collName, filter, postData, context) +func (db *MongoDBClient) RestfulAPIPostWithContext(context context.Context, collName string, filter bson.M, postData map[string]interface{}) (bool, error) { + return db.MongoClient.RestfulAPIPostWithContext(context, collName, filter, postData) } func (db *MongoDBClient) RestfulAPIPostMany(collName string, filter bson.M, postDataArray []interface{}) error { return db.MongoClient.RestfulAPIPostMany(collName, filter, postDataArray) } -func (db *MongoDBClient) RestfulAPIPostManyWithContext(collName string, filter bson.M, postDataArray []interface{}, context context.Context) error { - return db.MongoClient.RestfulAPIPostManyWithContext(collName, filter, postDataArray, context) +func (db *MongoDBClient) RestfulAPIPostManyWithContext(context context.Context, collName string, filter bson.M, postDataArray []interface{}) error { + return db.MongoClient.RestfulAPIPostManyWithContext(context, collName, filter, postDataArray) } func (db *MongoDBClient) GetUniqueIdentity(idName string) int32 { diff --git a/mongoapi/mongoapi.go b/mongoapi/mongoapi.go index 5c2d761..de027de 100644 --- a/mongoapi/mongoapi.go +++ b/mongoapi/mongoapi.go @@ -125,11 +125,11 @@ func (c *MongoClient) RestfulAPIGetMany(collName string, filter bson.M) ([]map[s // if no error happened, return true means data existed and false means data not existed func (c *MongoClient) RestfulAPIPutOne(collName string, filter bson.M, putData map[string]interface{}) (bool, error) { - return c.RestfulAPIPutOneWithContext(collName, filter, putData, context.TODO()) + return c.RestfulAPIPutOneWithContext(context.TODO(), collName, filter, putData) } // if no error happened, return true means data existed and false means data not existed -func (c *MongoClient) RestfulAPIPutOneWithContext(collName string, filter bson.M, putData map[string]interface{}, context context.Context) (bool, error) { +func (c *MongoClient) RestfulAPIPutOneWithContext(context context.Context, collName string, filter bson.M, putData map[string]interface{}) (bool, error) { collection := c.Client.Database(c.dbName).Collection(collName) existed, err := checkDataExisted(collection, filter) if err != nil { @@ -150,8 +150,12 @@ func (c *MongoClient) RestfulAPIPutOneWithContext(collName string, filter bson.M } func (c *MongoClient) RestfulAPIPullOne(collName string, filter bson.M, putData map[string]interface{}) error { + return c.RestfulAPIPullOneWithContext(context.TODO(), collName, filter, putData) +} + +func (c *MongoClient) RestfulAPIPullOneWithContext(context context.Context, collName string, filter bson.M, putData map[string]interface{}) error { collection := c.Client.Database(c.dbName).Collection(collName) - if _, err := collection.UpdateOne(context.TODO(), filter, bson.M{"$pull": putData}); err != nil { + if _, err := collection.UpdateOne(context, filter, bson.M{"$pull": putData}); err != nil { return fmt.Errorf("RestfulAPIPullOne err: %+v", err) } return nil @@ -199,10 +203,10 @@ func (c *MongoClient) RestfulAPIPutMany(collName string, filterArray []bson.M, p } func (c *MongoClient) RestfulAPIDeleteOne(collName string, filter bson.M) error { - return c.RestfulAPIDeleteOneWithContext(collName, filter, context.TODO()) + return c.RestfulAPIDeleteOneWithContext(context.TODO(), collName, filter) } -func (c *MongoClient) RestfulAPIDeleteOneWithContext(collName string, filter bson.M, context context.Context) error { +func (c *MongoClient) RestfulAPIDeleteOneWithContext(context context.Context, collName string, filter bson.M) error { collection := c.Client.Database(c.dbName).Collection(collName) if _, err := collection.DeleteOne(context, filter); err != nil { @@ -254,10 +258,10 @@ func (c *MongoClient) RestfulAPIMergePatch(collName string, filter bson.M, patch } func (c *MongoClient) RestfulAPIJSONPatch(collName string, filter bson.M, patchJSON []byte) error { - return c.RestfulAPIJSONPatchWithContext(collName, filter, patchJSON, context.TODO()) + return c.RestfulAPIJSONPatchWithContext(context.TODO(), collName, filter, patchJSON) } -func (c *MongoClient) RestfulAPIJSONPatchWithContext(collName string, filter bson.M, patchJSON []byte, context context.Context) error { +func (c *MongoClient) RestfulAPIJSONPatchWithContext(context context.Context, collName string, filter bson.M, patchJSON []byte) error { collection := c.Client.Database(c.dbName).Collection(collName) originalData, err := getOrigData(collection, filter) @@ -328,15 +332,15 @@ func (c *MongoClient) RestfulAPIPost(collName string, filter bson.M, postData ma return c.RestfulAPIPutOne(collName, filter, postData) } -func (c *MongoClient) RestfulAPIPostWithContext(collName string, filter bson.M, postData map[string]interface{}, context context.Context) (bool, error) { - return c.RestfulAPIPutOneWithContext(collName, filter, postData, context) +func (c *MongoClient) RestfulAPIPostWithContext(context context.Context, collName string, filter bson.M, postData map[string]interface{}) (bool, error) { + return c.RestfulAPIPutOneWithContext(context, collName, filter, postData) } func (c *MongoClient) RestfulAPIPostMany(collName string, filter bson.M, postDataArray []interface{}) error { - return c.RestfulAPIPostManyWithContext(collName, filter, postDataArray, context.TODO()) + return c.RestfulAPIPostManyWithContext(context.TODO(), collName, filter, postDataArray) } -func (c *MongoClient) RestfulAPIPostManyWithContext(collName string, filter bson.M, postDataArray []interface{}, context context.Context) error { +func (c *MongoClient) RestfulAPIPostManyWithContext(context context.Context, collName string, filter bson.M, postDataArray []interface{}) error { collection := c.Client.Database(c.dbName).Collection(collName) if _, err := collection.InsertMany(context, postDataArray); err != nil {