2022-11-09 04:21:11 +00:00
|
|
|
// 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{
|
2023-04-18 13:21:46 +00:00
|
|
|
{
|
|
|
|
"gender": bson.M{
|
|
|
|
"$ne": arg1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"age": bson.M{
|
|
|
|
"$lt": arg2,
|
|
|
|
},
|
|
|
|
},
|
2022-11-09 04:21:11 +00:00
|
|
|
},
|
|
|
|
}, 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{
|
2023-04-18 13:21:46 +00:00
|
|
|
"age": bson.M{
|
|
|
|
"$lte": arg1,
|
|
|
|
},
|
2022-11-09 04:21:11 +00:00
|
|
|
}, 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{
|
2023-04-18 13:21:46 +00:00
|
|
|
"age": bson.M{
|
|
|
|
"$gt": arg1,
|
|
|
|
},
|
2022-11-09 04:21:11 +00:00
|
|
|
}, 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{
|
2023-04-18 13:21:46 +00:00
|
|
|
"age": bson.M{
|
|
|
|
"$gte": arg1,
|
|
|
|
},
|
2022-11-09 04:21:11 +00:00
|
|
|
}, 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{
|
2023-04-18 13:21:46 +00:00
|
|
|
"age": bson.M{
|
|
|
|
"$gte": arg1,
|
|
|
|
"$lte": arg2,
|
|
|
|
},
|
2022-11-09 04:21:11 +00:00
|
|
|
}, 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{
|
2023-04-18 13:21:46 +00:00
|
|
|
{
|
|
|
|
"gender": arg1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"age": arg2,
|
|
|
|
},
|
2022-11-09 04:21:11 +00:00
|
|
|
},
|
|
|
|
}, 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
|
|
|
|
}
|