def SetSkills(self, request: skillitor_pb2.SkillAssociation, context): print("Received a call to SetSkills") try: user_table = self.db['user'] user_table.upsert(dict(email=str(request.user_email).lower()), ['email']) # Get the user that we just inserted or updated user = user_table.find_one(email=request.user_email.lower()) skill_associations = self.db['skill_associations'] for skill in request.skills: skill_associations.upsert(dict(user_id=user['id'], skill_name=skill.skill_name.lower(), skill_level=skill.skill_level), ['user_id', 'skill_name']) except Exception as e: print("Caught an exception") return skillitor_pb2.Acknowledgement(success=False, error_msg=str(e)) return skillitor_pb2.Acknowledgement(success=True)
def UnsetSkills(self, request: skillitor_pb2.SkillAssociation, context): print("Received a call to UnsetSkills") try: user_table = self.db['user'] user_table.find_one(email=str(request.user_email).lower()) # Get the user that we just inserted or updated user = user_table.find_one(email=request.user_email.lower()) if user is None: print('Not removing skills for non-existing user ' + request.user_email.lower()) else: print("Found user ID {} for {}".format(user['id'], request.user_email.lower())) skill_associations = self.db['skill_associations'] skills_to_remove = tuple(skill.skill_name.lower() for skill in request.skills) print("skills_to_remove type:{}, value{}".format( type(skills_to_remove), skills_to_remove )) skill_associations.delete(skill_name=skills_to_remove, user_id=user['id']) except Exception as e: print("Caught an exception: " + str(e)) return skillitor_pb2.Acknowledgement(success=False, error_msg=str(e)) return skillitor_pb2.Acknowledgement(success=True)
def SetSkills(self, request, context): print("Got a request to SetSkills. Request type: {}. " "String representation: {}".format(type(request), request)) return skillitor_pb2.Acknowledgement(success=True)