Skip to content

Commit

Permalink
modify order parameters in functions (#109)
Browse files Browse the repository at this point in the history
Signed-off-by: Patricia Reinoso <patricia.reinoso@canonical.com>
  • Loading branch information
patriciareinoso authored Jan 23, 2025
1 parent 5794aa4 commit 29eb1c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.12-dev
1.2.12
30 changes: 15 additions & 15 deletions mongoapi/dbadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
26 changes: 15 additions & 11 deletions mongoapi/mongoapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 29eb1c7

Please # to comment.