Esempio n. 1
0
func (s *vicusServer) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.UserResponse, error) {
	user := new(model.User)

	err := user.FindById(bson.ObjectId(req.Id))
	if err != nil {
		log.Fatalf("Couldn't get user: %s\n", err)
		return &pb.UserResponse{}, err
	}
	fmt.Printf("%v\n", user)

	userResponse := &pb.UserResponse{User: &pb.User{Id: user.Id.String(), FirstName: user.FirstName, LastName: user.LastName, Location: user.Location, Bio: user.Bio}}

	return userResponse, nil
}
Esempio n. 2
0
func (s *vicusServer) DeleteUser(ctx context.Context, req *pb.DeleteUserRequest) (*pb.DeleteUserResponse, error) {
	user := new(model.User)

	err := user.FindById(bson.ObjectId(req.UserId))
	if err != nil {
		log.Fatalf("Couldn't get user: %s\n", err)
		return &pb.DeleteUserResponse{Status: "failure"}, nil
	}

	err = user.Delete()
	if err != nil {
		log.Fatalf("Couldn't delete user: %s\n", err)
		return &pb.DeleteUserResponse{Status: "failure"}, nil
	}

	return &pb.DeleteUserResponse{Status: "success"}, nil
}
Esempio n. 3
0
func (s *vicusServer) UpdateUser(ctx context.Context, req *pb.UpdateUserRequest) (*pb.UserResponse, error) {
	user := new(model.User)

	err := user.FindById(bson.ObjectId(req.UserId))
	if err != nil {
		log.Fatalf("Couldn't get user: %s\n", err)
		return &pb.UserResponse{}, nil
	}

	err = user.Update(req.Email, req.Password)
	if err != nil {
		log.Fatalf("Couldn't update user: %s\n", err)
		return &pb.UserResponse{}, nil
	}

	return &pb.UserResponse{}, nil
}
Esempio n. 4
0
func tarjanSort(successors map[bson.ObjectId][]bson.ObjectId) [][]bson.ObjectId {
	// http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
	data := &tarjanData{
		successors: successors,
		nodes:      make([]tarjanNode, 0, len(successors)),
		index:      make(map[bson.ObjectId]int, len(successors)),
	}

	for id := range successors {
		id := bson.ObjectId(string(id))
		if _, seen := data.index[id]; !seen {
			data.strongConnect(id)
		}
	}

	// Sort connected components to stabilize the algorithm.
	for _, ids := range data.output {
		if len(ids) > 1 {
			sort.Sort(idList(ids))
		}
	}
	return data.output
}