def job(): # { # "job_title": "full-stack Developer", # "job_skills": [ "React.js", "JavaScript" ] # } # curl -i -H "Content-Type: application/json" -X POST -d '{"job_title": "FrontEnd Engineer1", "job_skills": [ "HTML2", "C33SS", "JadevaScript", "Sfffass" ]}' http://localhost:5000/api/job data = request.json new_job = Job(title=data["job_title"]) for skill_name in data["job_skills"]: # Find skill in DB: skill = Skill.query.filter_by(name=skill_name).first() # check if skill already in DB: exists = skill is not None if not exists: skill = Skill(name=skill_name) # Create new skill row in DB db.session.add(skill) # store in DB: # add required skill to job opening new_job.skills.append(skill) db.session.add(new_job) db.session.commit() return job_schema.dump(new_job)
def index(): # Return list of skills skills = [{ 'id': skill.id, 'skill': skill.name } for skill in Skill.select()] return success_200(skills)
def candidate(): # { # "candidate_name": "Uriel Yair", # "candidate_skills": [ "Python", "Java", "React.js", "JavaScript" ] # } # curl -i -H "Content-Type: application/json" -X POST -d '{"candidate_name": "Uriel Yair", "candidate_skills": [ "Python", "Java", "React.js", "JavaScript" ]}' http://localhost:5000/candidate data = request.json new_candidate = Candidate(title=data["candidate_name"]) for skill_name in data["candidate_skills"]: # Find skill in DB: skill = Skill.query.filter_by(name=skill_name).first() # check if skill already in DB: exists = skill is not None if not exists: # Create new skill row in DB skill = Skill(name=skill_name) db.session.add(skill) # store in DB # add required skill to job opening new_candidate.skills.append(skill) db.session.add(new_candidate) db.session.commit() return candidate_schema.dump(new_candidate)
def create(): # Check for valid json if not request.is_json: return error_401("Reponse is not JSON") # Retrieve data from json data = request.get_json() skill = data['skill'] # Check for valid name and password if skill: new_skill = Skill(name=skill) if new_skill.save(): data = {"skill": skill} return success_201('Created skill successfully', data) else: return error_401('Create skill failed!') else: return error_401('Invalid input!')
def __init__(self, name, **kwargs): super().__init__() self.name = name # compute whose turn to attack self.atk_counter = 0 self.skill_list = [Skill()] self.init_attrs = self.remain_attrs = random.choice(ATTR_RANGE_POOL) for attr in self.INIT_ATTR_LIST: min_attr_val, max_attr_val = INIT_ATTR_RANGES.get(attr, (0, 9999)) if self.remain_attrs <= min_attr_val: extra_attr_val = 0 else: extra_attr_val = random.choice( range(min_attr_val, min([max_attr_val, self.remain_attrs]))) self.remain_attrs -= extra_attr_val self[attr] = (min_attr_val + extra_attr_val) * ATTR_FACTORS.get( attr, 1)
def add_new_job(): """ Request Example: { "job_title": "Software Engineer", "job_skills": [ "Python", "Flask", "Django", "AWS" ] } CURL example: curl -i -H "Content-Type: application/json" -X POST -d '{"job_title": "Software Engineer", "job_skills": ["Python", "Flask", "Django", "AWS"]}' http://localhost:5000/api/jobs Returns: JobSchema Object """ data = request.get_json(force=True) new_job = Job(title=data["job_title"]) # Add skills to job for skill_name in data["job_skills"]: # Find skill in DB: skill = Skill.query.filter_by(name=skill_name).first() # check if skill already in DB: skill_exist_in_table = skill is not None if not skill_exist_in_table: # Create new skill row in DB skill = Skill(name=skill_name) db.session.add(skill) # store in DB # add required skill to job opening new_job.skills.append(skill) db.session.add(new_job) db.session.commit() return job_schema.dump(new_job)
def create(): # Check for valid json if not request.is_json: return error_401("Reponse is not JSON") # Retrieve data from json data = request.get_json() name = data['userSignIn']['name'] password = data['userSignIn']['password'] latitude = data['latitude'] longtitude = data['longtitude'] # Check for valid name and password if name and password: user = User.get_or_none(User.name == name) if user and check_password_hash(user.password, password): query = User.update( latitude=latitude, longtitude=longtitude).where(User.id == user.id) if query.execute(): # Generate an access token(JWT) with identity as user's name access_token = create_access_token(identity=name) # Get user skills user_skills = Skill.select().join( Lesson, on=(Skill.id == Lesson.skill)).where( (Lesson.owner_id == user.id) and (Lesson.teach == True)) skills = [] for user_skill in user_skills: exist = False for skill in skills: if (user_skill.name == skill): exist = True break if exist: continue else: skills.append(user_skill.name) # Concatenate string for skills string = "" for index, skill in enumerate(skills): if index > 0: string += ", " string += str(skill) data = { "id": user.id, "profile_picture": user.profile_picture, "name": user.name, 'email': user.email, "access_token": access_token, "latitude": user.latitude, "longtitude": user.longtitude, "skills": string } return success_201( 'User credentials are verified for sign in!', data) else: return error_401('Error when updating location!') else: return error_401('Invalid username or password!') else: return error_401('Invalid input!')
from app import app, db from models.user import User, UserSchema from models.skill import Skill from models.event import Event, EventComment user_schema = UserSchema() with app.app_context(): db.drop_all() db.create_all() # SKILLS software_engineering = Skill(skill='Software Engineering') javascript = Skill(skill='JavaScript') react = Skill(skill='React') html = Skill(skill='HTML') css = Skill(skill='CSS') python = Skill(skill='Python') ruby = Skill(skill='Ruby') mentoring = Skill(skill='Mentoring') # USER PROFILES amy_wilson, errors = user_schema.load({ 'username': '******', 'email': 'amy@email', 'password': '******',