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