def delete(self, user_uuid): user = UserModel.get_user_by_uuid(user_uuid) if user is None: return {"clips": [], "response": 404}, 201 user_id = user_uuid [clip.delete_from_db() for clip in ClipboardModel.get_clips_by_sender_id(user_id).all()] return {"message": "clip data deleted for user {}".format(user_uuid), "response": 201}, 201
def post(self): data = _parse.parse_args() unique_str = data['unique_str'] if data['isPc']: mac = unique_str username = data['username'] A = mac[randint(0, 14)] B = mac[randint(0, 14)] C = mac[randint(0, 14)] e1 = int(mac[randint(0, 14)]) e2 = int(mac[randint(0, 14)]) e3 = int(mac[randint(0, 14)]) D = username[floor(e1 / 2)] E = username[ceil(e2 / 2)] F = username[floor(e3 / 2)] key = A + C + E + B + D + F try: user = UserModel(username=username, uuid=key, isPc=False) user.save_into_db() return {"UUID": key, "response": 201}, 201 except IntegrityError as e: return {"UUID": "", "response": 400}, 201 else: userid = unique_str limit = len(userid) - 2 username = data['username'] A = userid[randint(0, limit)] B = userid[randint(0, limit)] C = userid[randint(0, limit)] D = userid[randint(0, limit)] E = userid[randint(0, limit)] F = userid[randint(0, limit)] key = A + C + E + B + D + F try: user = UserModel(username=username, uuid=key, isPc=False) user.save_into_db() return {"UUID": key, "response": 201}, 201 except IntegrityError as e: # return {"message": "Username already exists"}, 400 return {"UUID": "", "response": 400}, 201
def get(self, user_uuid, n): user = UserModel.get_user_by_uuid(user_uuid) if user is None: # return {"message": "No user found with UID : {}".format(user_id)}, 404 return {"clips": [], "response": 404}, 201 user_id = user_uuid clips = [] return {"clips": [clip.json() for clip in ClipboardModel.get_clips_by_sender_id(user_id).limit(n).all()], "response": 201}, 201
def post(self): data = _parse.parse_args() id_sender = UserModel.get_id_by_uuid(data['uuid_sender']).id id_reciever = UserModel.get_id_by_uuid(data['uuid_reciever']).id if id_sender == id_reciever: return {"message": "UUIDs can not be same", "response": 400}, 201 if id_sender is None or id_reciever is None: return { "message": "Check the UUIDs once again", "response": 400 }, 201 sender = ConnectionModel.get_connections_by_id(id_sender).all() if sender: for conn in sender: if id_reciever == conn.id_reciever: return { "message": "Connection already present", "response": 400 }, 201 # reciever_id = sender.id_reciever # if id_reciever == reciever_id: # return {"message": "Connection already present", "response": 400}, 400 # return {"id sender": id_sender, "id reciever": id_reciever, "reciever_id ": reciever_id} connection = ConnectionModel(id_sender=id_sender, id_reciever=id_reciever) connection.save_to_database() connection = ConnectionModel(id_sender=id_reciever, id_reciever=id_sender) connection.save_to_database() return {"message": "connection established", "response": 201}, 201
def get(self, uuid): uid = ConnectionModel.get_id_by_uuid(uuid) if uid is None: return {"connections": [], "response": 404}, 201 users = ConnectionModel.get_connections_by_id(uid.id).all() connections = [] for user in users: id = user.id_reciever print(id) connections.append(UserModel.get_user_by_id(id).json()) return {"connections": connections, "response": 201}, 201
def put(self, user_uuid, n): user = UserModel.get_user_by_uuid(user_uuid) if user is None: # return {"message": "No user found with UID : {}".format(user_id)}, 404 return {"clip": {}, "response": 404}, 201 elif n is not 1: # return {"message": "Post can not be applied on bulk query"}, 400 return {"clip": {}, "response": 400}, 201 else: user_id = user_uuid clip = ClipboardModel.get_clips_by_reciever_id(user_id).first() clip.update_db() return {"clip": clip.json(), "response": 201}, 201
def get(self, name): user = UserModel.get_uuid_by_name(name) if user is None: return {"UUID": "", "response": 404}, 201 return {"UUID": user.uuid, "response": 201}, 201