def delete(cls, user_id, score_name): score = ScoreModel.find_by_name(user_id, score_name) if score: score.remove_from_db() return { 'message': f'Successfully removed score \"{score_name}\" from the database.' } return cls.fail_response(score_name)
def post(self, type_risk): if ScoreModel.find_by_name(type_risk): return { 'message': "A score with type_risk '{}' \ already exists.".format(type_risk) }, 400 score = ScoreModel(type_risk) try: score.save_to_db() except: return {"message": "An error occurred creating the score."}, 500 return score.json(), 201
def patch(cls, user_id, score_name): data = cls.parser.parse_args() names = (score.name for score in ScoreModel.find_by_user_id(user_id)) if data['name'] in names: return { 'message': 'This name is already used. Try a different one.' }, 409 score = ScoreModel.find_by_name(user_id, score_name) if score: for key, val in data.items(): if val is not None: setattr(score, key, val) score.last_edit = datetime.datetime.now() score.save_to_db() return { 'message': f'Successfully updated score \"{score_name}\".', 'content': score.json(), } return cls.fail_response(score_name)
def get(self, type_risk): score = ScoreModel.find_by_name(type_risk) if score: return score.json() return {'message': 'Score not found'}, 404
def delete(self, type_risk): score = ScoreModel.find_by_name(type_risk) if score: score.delete_from_db() return {'message': 'Score deleted'}
def get(cls, user_id, score_name): score = ScoreModel.find_by_name(user_id, score_name) if score: return {'message': 'success', 'content': score.json()} return cls.fail_response(score_name)