def get(self, id): try: # Check user was like current_user_id = get_jwt_identity() like = Like.objects.get(post=id) for i in like.user_like: if str(i["user"]) == current_user_id: raise response.AlreadyLiked # get userEmbed user = resCon.convert_user_object_to_user_embed(current_user_id) like.update(push__user_like=user) # increase like post = Post.objects.get(id=id) post.update(inc__like=1) noti = NotificationController() noti.like(owner=str(post.owner.user), user_id=current_user_id,username=user["username"] ,post_id=post.id) self.res = resCon.like_convert(post) except response.AlreadyLiked: self.res = response.user_was_like_post() except DoesNotExist: self.res = response.post_is_not_exit() except Exception: raise Exception self.res = response.internal_server() return jsonify(self.res)
def get(self, id): try: user = User.objects.get(id=id) avatar = user.avatar.read() content_type = user.avatar.content_type return Response(avatar, content_type=content_type) except DoesNotExist: self.res = response.user_is_invalid() except Exception: self.res = response.internal_server() return jsonify(self.res)
def get(self, noti_id): res = {} try: body = request.get_json() noti = Notification.objects.get(id=noti_id) noti.read_notification(index=body["index"]) noti.save() except DoesNotExist: res = response.post_is_not_exit() except Exception: raise Exception res = response.internal_server() return jsonify(res)
def get(self): result = [] try: user_id = get_jwt_identity() search = Search.objects.get(owner=user_id) result = search.history_search len_result = len(result) if len_result >= 10: result = result[len_result - 10:len_result] except DoesNotExist: print("not search") except Exception: self.res = response.internal_server() return jsonify(result[::-1])
def post(self): res = {} try: current_user_id = get_jwt_identity() body = request.get_json() noti = Notification.objects.get(owner=current_user_id) noti.read_notification(index=body["index"]) noti.save() except DoesNotExist: res = response.post_is_not_exit() except Exception: raise Exception res = response.internal_server() return jsonify(res)
def get(self): try: body = request.get_json() user = User.objects.get(phonenumber=body.get('phonenumber')) if user.verify: raise response.HaveDoneVerify self.res = response.sucess() except response.HaveDoneVerify: self.res = response.action_done_previously() except DoesNotExist: self.res = response.user_is_not_validated() except Exception: self.res = response.internal_server() return jsonify(self.res)
def put(self): res = {} try: current_user_id = get_jwt_identity() user = User.objects.get(id=current_user_id) body = request.get_json() if "firstname" in body: body["username"] = body["firstname"] + " " + user.lastname if "lastname" in body: body["username"] = user.firstname + " " + body["lastname"] user.update(**body) res = response.sucess() except DoesNotExist: res = response.user_is_invalid() except Exception: raise Exception res = response.internal_server() return jsonify(res)
def post(self): try: body = request.get_json() user = User.objects.get(phonenumber=body.get('phonenumber')) if user.verify: raise response.HaveDoneVerify if body.get('code_verify') != CODE_VERIFY: raise response.ParameterValueInvalid user.verify = True user.save() self.res = response.sucess() except response.HaveDoneVerify: self.res = response.user_existed() except response.ParameterValueInvalid: self.res = response.parameter_value_invalid() except DoesNotExist: self.res = response.user_is_not_validated() except Exception: self.res = response.internal_server() return jsonify(self.res)
def get(self, user_id): try: current_user_id = get_jwt_identity() user = User.objects.get(id=user_id).to_json() user = json.loads(user) del user["password"] del user["blocks"] del user["uuid"] del user["verify"] if str(current_user_id) == str(user_id): pass user["is_friend"] = False current_friend = Friend.objects.get(owner=current_user_id) if current_friend.is_friend(user_id): user["is_friend"] = True self.res = user except DoesNotExist: self.res = response.user_is_invalid() except Exception: raise Exception self.res = response.internal_server() return jsonify(self.res)
def get(self, id): try: user_id = get_jwt_identity() like = Like.objects.get(post=id) for userEmbed in like.user_like: if str(userEmbed["user"]) == user_id: self.check_user = True like.update(pull__user_like=userEmbed) if not self.check_user: raise Exception post = Post.objects(id=id).first() if post.like < 0: raise Exception post.update(dec__like=1) self.res = resCon.like_convert(post) except DoesNotExist: self.res = response.post_is_not_exit() except Exception: self.res = response.internal_server() return jsonify(self.res)