def addGroup(request):
    #here i wanna call your method here
    groupName = request.POST.get('newgroup')
    print("group name top " + groupName)
    with grpc.insecure_channel('localhost:50052') as channel2:
        stub2 = groupDB_pb2_grpc.databaseStub(channel2)
        stub2.addGroup(
            groupDB_pb2.addGroupRequest(userId=request.user.id,
                                        groupName=groupName))
        print(
            stub2.getGroupNames(
                groupDB_pb2.getGroupNamesRequest(userId=request.user.id)))

    with grpc.insecure_channel('localhost:50052') as channel2:
        stub2 = groupDB_pb2_grpc.databaseStub(channel2)
        print("group name from user " + groupName)
        groupID = stub2.getGroupId(
            groupDB_pb2.getGroupRequest(groupName=groupName,
                                        userId=request.user.id))
        print(
            stub2.getGroupNames(
                groupDB_pb2.getGroupNamesRequest(userId=request.user.id)))
        print('group id is' + str(groupID.groupId))

    with grpc.insecure_channel('localhost:50051') as channel:
        stub = groups_pb2_grpc.Groups_ManagerStub(channel)
        stub.AddMember(
            groups_pb2.AddMemberRequest(group_id=str(groupID.groupId),
                                        user_id=str(request.user.id)))
    return render(request, 'micro/settings.html')
def deleteGroup(request):
    #here i wanna call your method here
    groupName = request.POST.get('groupp')
    with grpc.insecure_channel('localhost:50052') as channel2:
        stub2 = groupDB_pb2_grpc.databaseStub(channel2)
        tempId = stub2.getGroupId(
            groupDB_pb2.getGroupRequest(userId=int(request.user.id),
                                        groupName=str(groupName))).groupId
        stub2.deleteGroup(
            groupDB_pb2.deleteGroupRequest(groupName=str(groupName),
                                           userId=int(request.user.id)))
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = groups_pb2_grpc.Groups_ManagerStub(channel)
        stub.DeleteGroup(
            groups_pb2.DeleteGroupRequest(group_id=str(tempId))).result
    return render(request, 'micro/settings.html')
def deleteMember(request):
    with grpc.insecure_channel('localhost:50052') as channel2:
        stub2 = groupDB_pb2_grpc.databaseStub(channel2)
        print("this is what i entered " + request.POST.get('group'))
        groupID = stub2.getGroupId(
            groupDB_pb2.getGroupRequest(groupName=request.POST.get('group'),
                                        userId=request.user.id)).groupId
        print(groupID)
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = groups_pb2_grpc.Groups_ManagerStub(channel)
        print("this is my member " + str(request.POST.get('user')))
        stub.RemoveMember(
            groups_pb2.RemoveMemberRequest(group_id=str(groupID),
                                           user_id=str(
                                               request.POST.get('user'))))
        print(request.user.id)
    return render(request, 'micro/settings.html')
def getMembers(request):
    #here i wanna call your method here
    with grpc.insecure_channel('localhost:50052') as channel2:
        stub2 = groupDB_pb2_grpc.databaseStub(channel2)
        print(request.POST.get('usersingroup'))
        groupID = stub2.getGroupId(
            groupDB_pb2.getGroupRequest(
                groupName=request.POST.get('usersingroup'),
                userId=request.user.id))
        print(str(groupID.groupId))
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = groups_pb2_grpc.Groups_ManagerStub(channel)
        members = stub.AllMembers(
            groups_pb2.AllMembersRequest(group_id=str(groupID.groupId)))
        members = members.result
        print(members)
    return render(request, 'micro/settings.html', {'members': members})
def addMemberToGroup(request):
    #get group id
    with grpc.insecure_channel('localhost:50052') as channel2:
        stub2 = groupDB_pb2_grpc.databaseStub(channel2)
        groupID = stub2.getGroupId(
            groupDB_pb2.getGroupRequest(groupName=str(
                request.POST.get('groupname1')),
                                        userId=int(request.user.id))).groupId

    with grpc.insecure_channel('localhost:50051') as channel:
        stub = groups_pb2_grpc.Groups_ManagerStub(channel)
        print(
            stub.AddMember(
                groups_pb2.AddMemberRequest(
                    group_id=str(groupID),
                    user_id=str(request.POST.get(
                        'username1')))).result)  # print to make sure it works
    return render(request, 'micro/settings.html')
from __future__ import print_function
import grpc
import groups_pb2
import groups_pb2_grpc

if __name__=='__main__':
	channel = grpc.insecure_channel('localhost:50051')
	stub = groups_pb2_grpc.Groups_ManagerStub(channel)

	print(stub.AddMember(groups_pb2.AddMemberRequest(group_id='152', user_id='3')).result)
	#print(stub.RemoveMember(groups_pb2.RemoveMemberRequest(group_id='152', user_id='2')).result)

	#print(stub.AddMember(groups_pb2.AddMemberRequest(group_id='152', user_id='Liran')).result)
	#print(stub.AllMembers(groups_pb2.AddMemberRequest(group_id='152')).result)
	#print(stub.Contains(groups_pb2.ContainsRequest(group_id='152', user_id='Liran')).result)
	#print(stub.DeleteGroup(groups_pb2.DeleteGroupRequest(group_id='152')).result)
	#print(stub.AddMember(groups_pb2.AddMemberRequest(group_id='152', user_id='Liran')).result)
	#print(stub.AddMember(groups_pb2.AddMemberRequest(group_id='152', user_id='Jason')).result)
	#print(stub.AllMembers(groups_pb2.AddMemberRequest(group_id='152')).result)
	#print(stub.Contains(groups_pb2.ContainsRequest(group_id='152', user_id='Liran')).result)