예제 #1
0
    def post(self):
        try:
            self.parser.add_argument('request_id',
                                     required=True,
                                     help="Field request_id is mandatory")

            args = self.parser.parse_args()

            request_id = self._get_request_id(request)
            self._validate_request_id(request_id)
            self._validate_receiver(request_id)
            friend = self._accept_friend_request(request_id)
            print(friend)
            UserActivityModel.log_friend_activity(friend["user_id_rcv"],
                                                  friend["user_id_sender"],
                                                  "ADD")
            UserActivityModel.log_friend_activity(friend["user_id_sender"],
                                                  friend["user_id_rcv"], "ADD")

            return self._get_friends_requests_response(friend)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields request_id are mandatory", 400)
        except NoFriendRequestFoundException as e:
            return ErrorHandler.create_error_response(str(e), 400)
        except FriendshipAlreadyExistsException as e:
            return ErrorHandler.create_error_response(str(e), 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 post(self):
        try:
            self.parser.add_argument('message',
                                     required=True,
                                     help="Field message is mandatory")
            self.parser.add_argument('user_id',
                                     required=True,
                                     help="Field user_id is mandatory")
            self.parser.add_argument('storie_id',
                                     required=True,
                                     help="Field storie_id is mandatory")

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

            comment = CommentModel.create_comment(args)
            UserActivityModel.log_comment_activity(comment["user_id"],
                                                   comment["storie_id"], "ADD")

            return comment

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields message, user_id and storie_id are mandatory", 400)
        except NoUserDataFoundException as e:
            return ErrorHandler.create_error_response(str(e), 400)
        except NoStorieFoundException as e:
            return ErrorHandler.create_error_response(str(e), 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)
예제 #3
0
	def get(self, id):
		try:
			return self._get_storie_by_id(id)
		except NoUserDataFoundException as e:
			return ErrorHandler.create_error_response(str(e), 404)
		except DBConnectionError as e:
			return ErrorHandler.create_error_response(str(e), 500)
예제 #4
0
    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)
예제 #5
0
	def put(self, id):
		try:
			self.parser.add_argument('_id', required=True, help="Field id is mandatory")
			self.parser.add_argument('_rev', required=True, help="Field rev is mandatory")
			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")

			self._validate_author(id)
			args = self.parser.parse_args()
			
			body = json.loads(request.data.decode('utf-8'))

			storie = StorieModel.update_storie(id, body)
			UserActivityModel.log_storie_activity(storie["user_id"], storie["_id"], "EDIT")
			return ResponseBuilder.build_response(storie, 200)

		except BadRequest as ex:
			return ErrorHandler.create_error_response("Fields id, rev, title, location, user_id, visibility, multimedia and story_type are mandatory", 400)
		except NoStorieFoundException as e:
			return ErrorHandler.create_error_response(str(e), 404)
		except DataVersionException as e:
			return ErrorHandler.create_error_response(str(e), 409)
		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 post(self):
        try:
            self.parser.add_argument('reaction',
                                     required=True,
                                     help="Field reaction is mandatory")
            self.parser.add_argument('user_id',
                                     required=True,
                                     help="Field user_id is mandatory")
            self.parser.add_argument('storie_id',
                                     required=True,
                                     help="Field storie_id is mandatory")

            args = self.parser.parse_args()
            validate_sender(args.get('user_id'))
            reaction = ReactionModel.create_reaction(args)
            UserActivityModel.log_reaction_activity(reaction["user_id"],
                                                    reaction["storie_id"],
                                                    reaction["reaction"],
                                                    "ADD")
            return reaction

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields reaction, user_id and storie_id are mandatory", 400)
        except NoStorieFoundException as e:
            return ErrorHandler.create_error_response(str(e), 400)
        except UserMismatchException as e:
            return ErrorHandler.create_error_response(str(e), 409)
        except StorieReactionAlreadyFoundException as e:
            return ErrorHandler.create_error_response(str(e), 400)
        except DBConnectionError as e:
            return ErrorHandler.create_error_response(str(e), 500)
예제 #7
0
	def get_stories_by_user_id(self, user_id):
		try:
			stories = StorieModel.get_profile_stories_by_user_id(user_id)
			return self._create_get_stories_response(stories)
		except NoDataFoundException as e:
			return ErrorHandler.create_error_response(str(e), 404)
		except DBConnectionError as e:
			return ErrorHandler.create_error_response(str(e), 500)
예제 #8
0
 def get(self, storie_id):
     try:
         comments = CommentModel.get_storie_comments(storie_id)
         return comments
     except NoStorieFoundException as e:
         return ErrorHandler.create_error_response(str(e), 404)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
예제 #9
0
	def get(self, user_id):
		try:
			user_data_response = UserDataModel.get_all_users_except(user_id)
			return self._create_get_response(user_data_response)
		except NoUserDataFoundException as e:
			return ErrorHandler.create_error_response(str(e), 404)
		except DBConnectionError as e:
			return ErrorHandler.create_error_response(str(e), 500)
예제 #10
0
 def decorated_function(*args, **kwargs):
     try:
         if (not is_authenticated()):
             return ErrorHandler.create_error_response('invalid_token', 401)
         return f(*args, **kwargs)
     except DecodeError:
         return ErrorHandler.create_error_response('invalid_token', 401)
     except ExpiredSignatureError:
         return ErrorHandler.create_error_response('token-expired', 401)
 def get(self, request_id):
     try:
         self._validate_request_id(request_id)
         friend_request = FriendRequestModel.get_friend_request(request_id)
         self._validate_request_participant(friend_request)
         return self._get_friends_requests_response(friend_request)
     except NoFriendRequestFoundException as e:
         return ErrorHandler.create_error_response(str(e), 404)
     except UserMismatchException as e:
         return ErrorHandler.create_error_response(str(e), 409)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
예제 #12
0
	def delete(self, reaction_id):
		try:
			self._validate_author(reaction_id)
			reaction = ReactionModel.remove_reaction(reaction_id)
			UserActivityModel.log_reaction_activity(reaction["user_id"], reaction["storie_id"], reaction["reaction"], "DELETE")
			return self._get_reactions_response(reaction)
		except NoReactionFoundException as e:
			return ErrorHandler.create_error_response(str(e), 404)
		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 delete(self, comment_id):
     try:
         self._validate_author(comment_id)
         comment = CommentModel.remove_comment(comment_id)
         UserActivityModel.log_comment_activity(comment["user_id"],
                                                comment["storie_id"],
                                                "DELETE")
         return self._get_comments_response(comment)
     except NoCommentFoundException as e:
         return ErrorHandler.create_error_response(str(e), 404)
     except UserMismatchException as e:
         return ErrorHandler.create_error_response(str(e), 409)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
예제 #14
0
	def delete(self, id):
		try:
			self._validate_author(id)
			body = json.loads(request.data.decode('utf-8'))
			storie_user_id = body['user_id']
			storie = StorieModel.delete_storie(id, storie_user_id)
			UserActivityModel.log_storie_activity(storie["user_id"], storie["_id"], "DELETE")
			return ResponseBuilder.build_response(storie, 204)
		except NoStorieFoundException as e:
			return ErrorHandler.create_error_response(str(e), 404)
		except UserMismatchException as e:
			return ErrorHandler.create_error_response(str(e), 409)
		except DBConnectionError as e:
			return ErrorHandler.create_error_response(str(e), 500)
예제 #15
0
    def put(self, user_id):
        try:

            self.parser.add_argument('_id',
                                     required=True,
                                     help="Field id is mandatory")
            self.parser.add_argument('_rev',
                                     required=True,
                                     help="Field rev is mandatory")
            self.parser.add_argument('last_name',
                                     required=True,
                                     help="Field last_name is mandatory")
            self.parser.add_argument('name',
                                     required=True,
                                     help="Field name is mandatory")
            self.parser.add_argument('email',
                                     required=True,
                                     help="Field email is mandatory")
            self.parser.add_argument('birthday',
                                     required=True,
                                     help="Field birthday is mandatory")
            self.parser.add_argument('gender',
                                     required=True,
                                     help="Field gender is mandatory")

            validate_sender(user_id)

            args = self.parser.parse_args()

            body = json.loads(request.data.decode('utf-8'))
            user_data_response = UserDataModel.update_user_data_by_user_id(
                user_id, body)
            return self.__create_put_response(user_data_response)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields id, rev, last_name, name, birthday, gender, and email are mandatory",
                400)
        except NoUserDataFoundException as e:
            return ErrorHandler.create_error_response(str(e), 404)
        except DataVersionException as e:
            return ErrorHandler.create_error_response(str(e), 409)
        except UserMismatchException as e:
            return ErrorHandler.create_error_response(str(e), 409)
        except DBConnectionError as e:
            return ErrorHandler.create_error_response(str(e), 500)
예제 #16
0
 def delete(self, id):
     try:
         self._validate_friendship(id)
         friend = FriendModel.delete_friend(id)
         UserActivityModel.log_friend_activity(friend["user_id_rcv"],
                                               friend["user_id_sender"],
                                               "DELETE")
         UserActivityModel.log_friend_activity(friend["user_id_sender"],
                                               friend["user_id_rcv"],
                                               "DELETE")
         return ResponseBuilder.build_response(friend, 204)
     except NoFriendFoundException as e:
         return ErrorHandler.create_error_response(str(e), 404)
     except UserMismatchException as e:
         return ErrorHandler.create_error_response(str(e), 409)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
예제 #17
0
	def post(self):
		try:
			self.parser.add_argument('user_id', required=True, help="Field user_id is mandatory")
			self.parser.add_argument('rcv_user_id', required=True, help="Field rcv_user_id is mandatory")
			self.parser.add_argument('message', help="Message of the request")
			self.parser.add_argument('picture', help="Profile picture firebase id")

			args = self.parser.parse_args()
			user_sender_id, user_rcv_id, msg, picture = self._get_friend_request_data(args)
			self._validate_user_id(user_sender_id)
			validate_sender(user_sender_id)
			self._validate_user_id(user_rcv_id)

			be_friend_request = self._create_be_friend_request(user_sender_id, user_rcv_id, msg, picture)
			return self._get_be_friend_request_response(be_friend_request)

		except BadRequest as ex:
			return ErrorHandler.create_error_response("Fields user_id and rcv_user_id are mandatory", 400)
		except DataAlreadyExistsException as e:
			return ErrorHandler.create_error_response(str(e), 400)
		except FriendRequestAlreadyExistsException as e:
			return ErrorHandler.create_error_response(str(e), 400)
		except FriendshipAlreadyExistsException as e:
			return ErrorHandler.create_error_response(str(e), 400)
		except NoUserDataFoundException as e:
			return ErrorHandler.create_error_response(str(e), 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 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)
예제 #19
0
 def get(self):
     try:
         fromHour = request.args.get('from')
         toHour = request.args.get('to')
         requests = RequestCounterModel.get_requests(fromHour=fromHour,
                                                     toHour=toHour)
         return ResponseBuilder.build_response(requests, 200)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
예제 #20
0
    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)
예제 #21
0
    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)
예제 #22
0
 def get(self, user_id):
     try:
         user_data_response = UserDataModel.get_user_data_by_user_id(
             user_id)
         storie_detail_controller = StorieDetailController()
         stories_response = storie_detail_controller.get_stories_by_user_id(
             user_id)
         friend_controller = FriendController()
         friends_response = friend_controller.get_friends_by_user_id(
             user_id)
         be_friend_detail_controller = BeFriendDetailController()
         friends_requests_rcv = be_friend_detail_controller.get_friends_requests_rcv_by_user_id(
             user_id)
         friends_requests_sent = be_friend_detail_controller.get_friends_requests_sent_by_user_id(
             user_id)
         return self._create_get_response(user_data_response,
                                          stories_response,
                                          friends_response,
                                          friends_requests_rcv,
                                          friends_requests_sent)
     except NoUserDataFoundException as e:
         return ErrorHandler.create_error_response(str(e), 404)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
    def put(self, comment_id):
        try:
            self.parser.add_argument('_id',
                                     required=True,
                                     help="Field id is mandatory")
            self.parser.add_argument('_rev',
                                     required=True,
                                     help="Field rev is mandatory")
            self.parser.add_argument('storie_id',
                                     required=True,
                                     help="Field storie_id is mandatory")
            self.parser.add_argument('user_id',
                                     required=True,
                                     help="Field user_id is mandatory")
            self.parser.add_argument('message',
                                     required=True,
                                     help="Field message is mandatory")

            self._validate_author(comment_id)
            args = self.parser.parse_args()

            body = json.loads(request.data.decode('utf-8'))
            comment = CommentModel.update_comment(comment_id, body)
            UserActivityModel.log_comment_activity(comment["user_id"],
                                                   comment["storie_id"],
                                                   "EDIT")

            return ResponseBuilder.build_response(comment, 200)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields id, rev, storie_id, user_id and message are mandatory",
                400)
        except NoUserDataFoundException as e:
            return ErrorHandler.create_error_response(str(e), 400)
        except NoCommentFoundException as e:
            return ErrorHandler.create_error_response(str(e), 404)
        except DataVersionException as e:
            return ErrorHandler.create_error_response(str(e), 409)
        except UserMismatchException as e:
            return ErrorHandler.create_error_response(str(e), 409)
        except DBConnectionError as e:
            return ErrorHandler.create_error_response(str(e), 500)
예제 #24
0
 def get(self):
     try:
         return self._get_appserver_stats_response()
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
예제 #25
0
 def get_friends_by_user_id(self, user_id):
     try:
         friends = FriendModel.get_friends_by_user_id(user_id)
         return self._create_get_friends_response(friends)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)