sunboyy/repogen

View on GitHub
test/generator_test_expected.txt

Summary

Maintainability
Test Coverage
// Code generated by repogen. DO NOT EDIT.
package teststub

import (
    "context"

    "go.mongodb.org/mongo-driver/bson"
    "go.mongodb.org/mongo-driver/bson/primitive"
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
)

func NewUserRepositoryIntegration(collection *mongo.Collection) *UserRepositoryIntegrationMongo {
    return &UserRepositoryIntegrationMongo{
        collection: collection,
    }
}

type UserRepositoryIntegrationMongo struct {
    collection *mongo.Collection
}

func (r *UserRepositoryIntegrationMongo) FindAll(arg0 context.Context) ([]*User, error) {
    findOptions := options.Find().SetSort(bson.M{})
    cursor, err := r.collection.Find(arg0, bson.M{}, findOptions)
    if err != nil {
        return nil, err
    }
    entities := []*User{}
    if err := cursor.All(arg0, &entities); err != nil {
        return nil, err
    }
    return entities, nil
}

func (r *UserRepositoryIntegrationMongo) FindByAgeBetween(arg0 context.Context, arg1 int, arg2 int) ([]*User, error) {
    findOptions := options.Find().SetSort(bson.M{})
    cursor, err := r.collection.Find(arg0, bson.M{
        "age": bson.M{
            "$gte": arg1,
            "$lte": arg2,
        },
    }, findOptions)
    if err != nil {
        return nil, err
    }
    entities := []*User{}
    if err := cursor.All(arg0, &entities); err != nil {
        return nil, err
    }
    return entities, nil
}

func (r *UserRepositoryIntegrationMongo) FindByAgeGreaterThanEqualOrderByAgeDesc(arg0 context.Context, arg1 int) ([]*User, error) {
    findOptions := options.Find().SetSort(bson.M{
        "age": -1,
    })
    cursor, err := r.collection.Find(arg0, bson.M{
        "age": bson.M{
            "$gte": arg1,
        },
    }, findOptions)
    if err != nil {
        return nil, err
    }
    entities := []*User{}
    if err := cursor.All(arg0, &entities); err != nil {
        return nil, err
    }
    return entities, nil
}

func (r *UserRepositoryIntegrationMongo) FindByAgeGreaterThanOrderByAgeAsc(arg0 context.Context, arg1 int) ([]*User, error) {
    findOptions := options.Find().SetSort(bson.M{
        "age": 1,
    })
    cursor, err := r.collection.Find(arg0, bson.M{
        "age": bson.M{
            "$gt": arg1,
        },
    }, findOptions)
    if err != nil {
        return nil, err
    }
    entities := []*User{}
    if err := cursor.All(arg0, &entities); err != nil {
        return nil, err
    }
    return entities, nil
}

func (r *UserRepositoryIntegrationMongo) FindByAgeLessThanEqualOrderByAge(arg0 context.Context, arg1 int) ([]*User, error) {
    findOptions := options.Find().SetSort(bson.M{
        "age": 1,
    })
    cursor, err := r.collection.Find(arg0, bson.M{
        "age": bson.M{
            "$lte": arg1,
        },
    }, findOptions)
    if err != nil {
        return nil, err
    }
    entities := []*User{}
    if err := cursor.All(arg0, &entities); err != nil {
        return nil, err
    }
    return entities, nil
}

func (r *UserRepositoryIntegrationMongo) FindByGenderNotAndAgeLessThan(arg0 context.Context, arg1 Gender, arg2 int) ([]*User, error) {
    findOptions := options.Find().SetSort(bson.M{})
    cursor, err := r.collection.Find(arg0, bson.M{
        "$and": []bson.M{
            {
                "gender": bson.M{
                    "$ne": arg1,
                },
            },
            {
                "age": bson.M{
                    "$lt": arg2,
                },
            },
        },
    }, findOptions)
    if err != nil {
        return nil, err
    }
    entities := []*User{}
    if err := cursor.All(arg0, &entities); err != nil {
        return nil, err
    }
    return entities, nil
}

func (r *UserRepositoryIntegrationMongo) FindByGenderOrAge(arg0 context.Context, arg1 Gender, arg2 int) ([]*User, error) {
    findOptions := options.Find().SetSort(bson.M{})
    cursor, err := r.collection.Find(arg0, bson.M{
        "$or": []bson.M{
            {
                "gender": arg1,
            },
            {
                "age": arg2,
            },
        },
    }, findOptions)
    if err != nil {
        return nil, err
    }
    entities := []*User{}
    if err := cursor.All(arg0, &entities); err != nil {
        return nil, err
    }
    return entities, nil
}

func (r *UserRepositoryIntegrationMongo) FindByID(arg0 context.Context, arg1 primitive.ObjectID) (*User, error) {
    findOptions := options.FindOne().SetSort(bson.M{})
    var entity User
    if err := r.collection.FindOne(arg0, bson.M{
        "_id": arg1,
    }, findOptions).Decode(&entity); err != nil {
        return nil, err
    }
    return &entity, nil
}

func (r *UserRepositoryIntegrationMongo) InsertMany(arg0 context.Context, arg1 []*User) ([]interface{}, error) {
    var entities []interface{}
    for _, model := range arg1 {
        entities = append(entities, model)
    }
    result, err := r.collection.InsertMany(arg0, entities)
    if err != nil {
        return nil, err
    }
    return result.InsertedIDs, nil
}

func (r *UserRepositoryIntegrationMongo) InsertOne(arg0 context.Context, arg1 *User) (interface{}, error) {
    result, err := r.collection.InsertOne(arg0, arg1)
    if err != nil {
        return nil, err
    }
    return result.InsertedID, nil
}