def delete_client(client_id): client = ClientService.remove(client_id) if client == None: abort(404) client_schema = ClientSchema() return client_schema.jsonify(client)
def update_partial_client(client_id): username = request.json['username'] if ClientService.get_by_username(username): return jsonify({'error': 'This username already exists!'}) client = ClientService.update_username(client_id, username) if client == None: abort(404) client_schema = ClientSchema() return client_schema.jsonify(client)
def create_client(): username = request.json['username'] email = request.json['email'] if ClientService.get_by_username(username): return jsonify({'error': 'This username already exists!'}) if ClientService.get_by_email(email): return jsonify({'error': 'This email already exists!'}) client = ClientService.add(username, email) client_schema = ClientSchema() return client_schema.jsonify(client)
def pag_clients(page_num): clients = ClientService.paginate(per_page=20, page=page_num).items clients_schema = ClientSchema(many=True) return clients_schema.jsonify(clients)
def get_client(client_id): client = ClientService.get_by_id(client_id) if client == None: abort(404) client_schema = ClientSchema() return client_schema.jsonify(client)
def get_clients(): clients = ClientService.get_all() clients_schema = ClientSchema(many=True) return clients_schema.jsonify(clients)