Example #1
0
    def get(self, id=None, name=None):
        if id:
            keyword = KeywordModel.find_by_id(id)
        else:
            keyword = KeywordModel.find_by_name(name)

        if keyword:
            return keyword.json()
        return {'message': 'Item not found'}, 404
Example #2
0
    def delete(self, id=None, name=None):
        if id:
            keyword = KeywordModel.find_by_id(id)
        else:
            keyword = KeywordModel.find_by_name(name)

        if keyword:
            keyword.delete_from_db()

        return {'message': 'Keyword deleted'}
Example #3
0
    def post(self):
        data = Keyword.parser.parse_args()
        keyword = data['keyword']

        if KeywordModel.find_by_keyword(data['keyword']):
            return {'message': "Keyword already exist!"}, 400

        keyword = KeywordModel(**data)

        try:
            keyword.save_to_db()
        except IOError:
            return {"message": "An error occurred creating the keyword"}, 500

        return {'message':'Keyword created successfully'}, 201
Example #4
0
    def post(self):
        data = CreateKeyword.parser.parse_args()
        keyword = KeywordModel(name=data['name'], person_id=data['person_id'])

        if KeywordModel.find_by_name(data['name']):
            return {
                'message':
                "A keyword with name '{}' already exists.".format(data['name'])
            }, 400

        keyword.save_to_db()
        return keyword.json(), 201
Example #5
0
    def put(self, id):
        data = Keyword.parser1.parse_args()
        keyword = KeywordModel.find_by_id(id)

        if keyword:
            keyword.name = data['name']
        else:
            keyword = KeywordModel(name=data['name'],
                                   person_id=data['person_id'])

        keyword.save_to_db()
        return keyword.json()
Example #6
0
    def post(self, name):
        if KeywordModel.find_by_name(name):
            return {
                'message':
                "An keyword with name '{}' already exists.".format(name)
            }, 400

        data = Keyword.parser.parse_args()
        keyword = KeywordModel(name=name, **data)

        try:
            keyword.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}, 500

        return keyword.json(), 201
Example #7
0
    def post(self):
        data = Results.parser.parse_args()
        keyword = data['keyword']
        number = data['number']

        if len(str(number)) != 3:
            return {'message': "Please enter a 3 digit number"}, 400

        elif KeywordModel.find_by_keyword(data['keyword']) is None:
            return {'message': "You are Not a winner try again!!!!"}, 201

        elif number % 11 == 0 and ResultModel.find_results(keyword,
                                                           number) is None:
            keyword = ResultModel(**data)
            try:
                keyword.save_to_db()
                return {'message': "You are a winner"}, 201
            except IOError:
                return {"message": "An error occurred saving the results"}, 500

        else:
            return {'message': "We already have a winner!!"}, 201

        return {'message': "You are Not a winner try again later!!"}, 201
Example #8
0
 def delete(self):
     data = Keyword.parser.parse_args()
     keyword = KeywordModel.find_by_keyword(data['keyword'])
     if keyword:
         keyword.delete_from_db()
     return {'message': 'Deleted keyword'}