Пример #1
0
class StorieController(flask_restful.Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.shared_api_client = SharedApiClient()

    @login_required
    def post(self):
        try:

            self.parser.add_argument('title',
                                     required=True,
                                     help="Field title is mandatory")
            self.parser.add_argument('location',
                                     required=True,
                                     help="Field location is mandatory")
            self.parser.add_argument('visibility',
                                     required=True,
                                     help="Field visibility is mandatory")
            self.parser.add_argument('multimedia',
                                     required=True,
                                     help="Field multimedia is mandatory")
            self.parser.add_argument('story_type',
                                     required=True,
                                     help="Field story_type is mandatory")
            self.parser.add_argument('user_id',
                                     required=True,
                                     help="Field user_id is mandatory")

            args = self.parser.parse_args()
            validate_sender(args.get("user_id"))

            storie = self._create_user_storie_request(request)

            UserActivityModel.log_storie_activity(storie["user_id"],
                                                  storie["_id"], "ADD")
            self._create_multimedia_file(args.get('title'),
                                         args.get('multimedia'))
            return storie

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields title, location, visibility, multimedia, user_id and story_type are mandatory",
                400)
        except UserMismatchException as e:
            return ErrorHandler.create_error_response(str(e), 409)
        except DBConnectionError as e:
            return ErrorHandler.create_error_response(str(e), 500)

    def _create_user_storie_request(self, request):
        body = request.get_json()
        storie = StorieModel.create_user_storie(body)
        return storie

    def _create_multimedia_file(self, filename, multimedia):
        self.shared_api_client.fileCreate(filename, multimedia)
Пример #2
0
class LoginController(flask_restful.Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.shared_api_client = SharedApiClient()

    def post(self):
        try:
            self.parser.add_argument('username',
                                     required=True,
                                     help="username cannot be blank!")
            self.parser.add_argument('password',
                                     required=True,
                                     help="password cannot be blank!")
            args = self.parser.parse_args()
            response = self.shared_api_client.login(args["username"],
                                                    args["password"])
            if not response:
                return ErrorHandler.create_error_response("Invalid Login", 401)

            return ResponseBuilder.build_response(response, 201)

        except RequestException as e:
            return ErrorHandler.create_error_response(str(e), 500)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields username and password are mandatory", 400)

        except UserNotExistsException as e:
            return ErrorHandler.create_error_response(str(e), 409)
Пример #3
0
class UserController(flask_restful.Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.shared_api_client = SharedApiClient()

    def post(self):
        try:
            # save mandatory fields on app server
            self.parser.add_argument('id',
                                     required=True,
                                     help="Field id is mandatory")  # fb id
            self.parser.add_argument(
                'username', required=True,
                help="Field username is mandatory")  # fb email
            self.parser.add_argument('password',
                                     required=True,
                                     help="Field password is mandatory")

            args = self.parser.parse_args()

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields id, username and password are mandatory", 400)

        try:
            # save optionals fields on app server
            self.parser.add_argument('name', required=False)
            self.parser.add_argument('first_name', required=False)
            self.parser.add_argument('last_name', required=False)
            self.parser.add_argument('gender', required=False)
            self.parser.add_argument('picture', required=False)
            self.parser.add_argument('facebookAccount', required=False)

            response = self.shared_api_client.userCreate(
                args["id"], args["username"], args["password"])
            if not response:
                return ErrorHandler.create_error_response("Invalid Login", 401)

            user_id = response["user"]["id"]
            username = response["user"]["username"]
            UserDataModel.insert_user(user_id, username)
            return ResponseBuilder.build_response(response, 200)

        except RequestException as e:
            return ErrorHandler.create_error_response(str(e), 500)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(str(ex), 400)
class UserDetailController(Resource):
    def __init__(self):
        self.shared_api_client = SharedApiClient()

    def get(self, user_id):
        if not user_id:
            return ErrorHandler.create_error_response("Field id is mandatory",
                                                      400)

        try:
            response = self.shared_api_client.getUserById(user_id)
            if not response:
                return ErrorHandler.create_error_response(
                    "User doesn't exists", 404)

            return ResponseBuilder.build_response(response, 200)

        except RequestException as e:
            return ErrorHandler.create_error_response(str(e), 500)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(str(ex), 400)
 def __init__(self):
     self.shared_api_client = SharedApiClient()
Пример #6
0
 def __init__(self):
     self.parser = reqparse.RequestParser(bundle_errors=True)
     self.shared_api_client = SharedApiClient()
Пример #7
0
 def __init__(self):
     self.parser = reqparse.RequestParser()
     self.shared_api_client = SharedApiClient()