def post(self, team_id): if TeamModel.find_by_id(team_id): return {"msg": "Team already exist"}, 400 data = self.parser.parse_args() new_team = TeamModel(team_id, **data) new_team.save_to_db() return new_team.json(), 201
def post(self, business_name): if TeamModel.find_by_business_name(business_name): return {'message': "That team already exists!"} data = Team.parser.parse_args() print(data['location']) new_team = TeamModel(business_name, data['location']) new_team.save_to_db() return new_team.json(), 201 # 201 status code means created
def put(self, name): data = Team.parser.parse_args() team = TeamModel.find_by_name(name) if team is None: team = TeamModel(name, data['division']) else: team.division = data['division'] team.save_to_db() return team.json()
def post(self, name): if TeamModel.lookup(name): return { 'message': "A team with name '{}' already exists.".format(name) }, 400 team = TeamModel(name) try: team.save() except: return {"message": "An error occurred creating the team."}, 500 return team.json(), 201
def put(self, team_id): data = self.parser.parse_args() team = TeamModel.find_by_id(team_id) if team is None: team = TeamModel(team_id, **data) else: team.team_name = data["team_name"] team.save_to_db() return team.json()
def post(self, name, division=None): data = Team.parser.parse_args() if TeamModel.find_by_name(name): return {"message": "{} already exists".format(name)} team = TeamModel(name, data['division']) try: team.save_to_db() except: return { "message": "An error occured while creating the team." }, 500 return team.json()
def put(self, business_name): data = Team.parser.parse_args() team = TeamModel.find_by_business_name(business_name) if team is None: # team = TeamModel(name, data['price'], data['storebusiness_name']) team = TeamModel(**data) else: team.business_name = business_name team.location = data['location'] team.save_to_db() return team.json()