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)
Esempio n. 2
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 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)
    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)
Esempio n. 5
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)
Esempio n. 6
0
	def _validate_author(self, reaction_id):
		reaction = ReactionModel.get_reaction_with_id(reaction_id)
		author_id = reaction.get('user_id')
		validate_sender(author_id)
Esempio n. 7
0
	def _validate_author(self, storie_id):
		storie = StorieModel.get_storie(storie_id)
		author_id = storie.get('user_id')
		validate_sender(author_id)
Esempio n. 8
0
 def _validate_receiver(self, request_id):
     friend_request = FriendRequestModel.get_friend_request(request_id)
     receiver_id = friend_request.get('user_id_rcv')
     validate_sender(receiver_id)
 def _validate_author(self, comment_id):
     comment = CommentModel.get_comment_with_id(comment_id)
     author_id = comment.get('user_id')
     validate_sender(author_id)