Exemple #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
}
Exemple #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
}
Exemple #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
}