Exemplo n.º 1
0
 def post(self, name):
     if AdminModel.find_by_name(name):
         return {'message': f'User with name <{name}> already exists'}
     parser = reqparse.RequestParser()
     parser.add_argument('password', type=str, required=True, help='Password is required')
     data = parser.parse_args()
     new_admin = AdminModel(name, data['password'])
     new_admin.create()
     return new_admin.json()
Exemplo n.º 2
0
    def put(self, admin_code, country_code):
        data = Admin.parser.parse_args()

        entry = AdminModel.find_by_code_and_country(admin_code, country_code)

        if entry:
            entry.description = data['description']
        else:
            entry = AdminModel(admin_code, country_code, data['description'])
        try:
            entry.save_to_db()
        except:
            {'message': 'Something went wrong inserting the admin.'}, 500
        return entry.json(), 201
Exemplo n.º 3
0
    def post(self, admin_code, country_code):
        data = Admin.parser.parse_args()

        if AdminModel.find_by_code_and_country(admin_code, country_code):
            return {
                'message':
                "A '{}' admin code already exists for country with code '{}'.".
                format(admin_code, country_code)
            }, 400

        entry = AdminModel(admin_code, country_code, data['description'])
        try:
            entry.save_to_db()
        except:
            {'message': 'Something went wrong inserting the admin.'}, 500
        return entry.json(), 201