package mongodb import ( "context" "git.aiterp.net/rpdata/api/models" "git.aiterp.net/rpdata/api/repositories" "github.com/globalsign/mgo" ) type userRepository struct { users *mgo.Collection } func newUserRepository(db *mgo.Database) (repositories.UserRepository, error) { collection := db.C("core.users") return &userRepository{users: collection}, nil } func (r *userRepository) Find(ctx context.Context, id string) (*models.User, error) { user := new(models.User) err := r.users.FindId(id).One(user) if err != nil { if err == mgo.ErrNotFound { return nil, repositories.ErrNotFound } return nil, err } return user, nil } func (r *userRepository) Insert(ctx context.Context, user models.User) (*models.User, error) { err := r.users.Insert(user) if err != nil { return nil, err } return &user, nil }