128 lines
3.2 KiB
Text
128 lines
3.2 KiB
Text
|
// Code generated by repogen. DO NOT EDIT.
|
||
|
package user
|
||
|
|
||
|
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 NewUserRepository(collection *mongo.Collection) UserRepository {
|
||
|
return &UserRepositoryMongo{
|
||
|
collection: collection,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
type UserRepositoryMongo struct {
|
||
|
collection *mongo.Collection
|
||
|
}
|
||
|
|
||
|
func (r *UserRepositoryMongo) FindByID(arg0 context.Context, arg1 primitive.ObjectID) (*UserModel, error) {
|
||
|
var entity UserModel
|
||
|
if err := r.collection.FindOne(arg0, bson.M{
|
||
|
"_id": arg1,
|
||
|
}, options.FindOne().SetSort(bson.M{})).Decode(&entity); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &entity, nil
|
||
|
}
|
||
|
|
||
|
func (r *UserRepositoryMongo) FindByGenderNotAndAgeLessThan(arg0 context.Context, arg1 Gender, arg2 int) (*UserModel, error) {
|
||
|
cursor, err := r.collection.Find(arg0, bson.M{
|
||
|
"$and": []bson.M{
|
||
|
{"gender": bson.M{"$ne": arg1}},
|
||
|
{"age": bson.M{"$lt": arg2}},
|
||
|
},
|
||
|
}, options.Find().SetSort(bson.M{}))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var entities []*UserModel
|
||
|
if err := cursor.All(arg0, &entities); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return entities, nil
|
||
|
}
|
||
|
|
||
|
func (r *UserRepositoryMongo) FindByAgeLessThanEqualOrderByAge(arg0 context.Context, arg1 int) ([]*UserModel, error) {
|
||
|
cursor, err := r.collection.Find(arg0, bson.M{
|
||
|
"age": bson.M{"$lte": arg1},
|
||
|
}, options.Find().SetSort(bson.M{
|
||
|
"age": 1,
|
||
|
}))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var entities []*UserModel
|
||
|
if err := cursor.All(arg0, &entities); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return entities, nil
|
||
|
}
|
||
|
|
||
|
func (r *UserRepositoryMongo) FindByAgeGreaterThanOrderByAgeAsc(arg0 context.Context, arg1 int) ([]*UserModel, error) {
|
||
|
cursor, err := r.collection.Find(arg0, bson.M{
|
||
|
"age": bson.M{"$gt": arg1},
|
||
|
}, options.Find().SetSort(bson.M{
|
||
|
"age": 1,
|
||
|
}))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var entities []*UserModel
|
||
|
if err := cursor.All(arg0, &entities); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return entities, nil
|
||
|
}
|
||
|
|
||
|
func (r *UserRepositoryMongo) FindByAgeGreaterThanEqualOrderByAgeDesc(arg0 context.Context, arg1 int) ([]*UserModel, error) {
|
||
|
cursor, err := r.collection.Find(arg0, bson.M{
|
||
|
"age": bson.M{"$gte": arg1},
|
||
|
}, options.Find().SetSort(bson.M{
|
||
|
"age": -1,
|
||
|
}))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var entities []*UserModel
|
||
|
if err := cursor.All(arg0, &entities); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return entities, nil
|
||
|
}
|
||
|
|
||
|
func (r *UserRepositoryMongo) FindByAgeBetween(arg0 context.Context, arg1 int, arg2 int) ([]*UserModel, error) {
|
||
|
cursor, err := r.collection.Find(arg0, bson.M{
|
||
|
"age": bson.M{"$gte": arg1, "$lte": arg2},
|
||
|
}, options.Find().SetSort(bson.M{}))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var entities []*UserModel
|
||
|
if err := cursor.All(arg0, &entities); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return entities, nil
|
||
|
}
|
||
|
|
||
|
func (r *UserRepositoryMongo) FindByGenderOrAge(arg0 context.Context, arg1 Gender, arg2 int) ([]*UserModel, error) {
|
||
|
cursor, err := r.collection.Find(arg0, bson.M{
|
||
|
"$or": []bson.M{
|
||
|
{"gender": arg1},
|
||
|
{"age": arg2},
|
||
|
},
|
||
|
}, options.Find().SetSort(bson.M{}))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var entities []*UserModel
|
||
|
if err := cursor.All(arg0, &entities); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return entities, nil
|
||
|
}
|