def post(self, vid_id): args = postcmnt_parser.parse_args() uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) new_cmnt = CommentDAO.add_cmnt(vid_id, uuid=uuid, text=args['text'], time=args["vid_time"], tkn=args["x-access-token"]) self.logger.info(f"Posted new comment to video {vid_id}. Comment: {new_cmnt}. RESPONSECODE:201") return new_cmnt, 201
def delete(self, vid_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') args = parser.parse_args() uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) self.logger.debug(f"Deleting video {vid_id}") VideoDAO.delete(vid_id, uuid) self.logger.info(f"Deleted video with id {vid_id}. RESPONSECODE:200") return {"message":"OK"}, 200
def get(self, user_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') args = parser.parse_args() viewer_uuid = AuthSender.get_uuid_from_token(args['x-access-token']) vids = VideoDAO.get_videos_by(user_id, viewer_uuid, args["x-access-token"]) self.logger.info( f"{len(vids)} vids collected by user {user_id}. RESPONSECODE:200") return vids, 200
def get(self): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers', required=True, help='Missing user token!') args_dict = parser.parse_args() id = AuthSender.get_uuid_from_token(args_dict["x-access-token"]) self.logger.info( f"Returning push token for user {id}. RESPONSECODE:200") return {"push_token": UsersDAO.get_tkn(id)}, 200
def get(self, other_user_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers', required=True, help='Missing user token!') args = parser.parse_args() uuid1 = AuthSender.get_uuid_from_token(args['x-access-token']) UsersDAO.check_exists(uuid1) UsersDAO.check_exists(other_user_id) msgs = ChatsDAO.get_messages_between(uuid1, other_user_id) self.logger.info(f"Found {len(msgs)} messages between users {uuid1, other_user_id}. RESPONSECODE:200") return msgs, 200
def get(self): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') args = parser.parse_args() viewer_uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) reqs = UsersDAO.view_pending_reqs(viewer_uuid) self.logger.info( f"Found {len(reqs['pending_reqs'])} pending requests for user {viewer_uuid}. RESPONSECODE:200" ) return reqs, 200
def delete(self, user_id, friend_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') args = parser.parse_args() viewer_uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) if not AuthSender.has_permission(user_id, viewer_uuid): raise BadRequestError( f"You don't have permission to delete other users' friends") UsersDAO.delete_friendship(user_id, friend_id) return {"msg": "OK"}, 200
def post(self): args = post_parser.parse_args() uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) # add to local db new_vid_with_url = VideoDAO.add_vid(title=args['title'], description=args['description'], uuid=uuid, location=args['location'], is_private=args['is_private'], thumbnail_url=args['thumbnail_url']) # upload to mediasv new_vid_with_url['firebase_url'], new_vid_with_url['timestamp'] = MediaSender.send_url(new_vid_with_url['video_id'],args['firebase_url']) self.logger.info(f"New video uploaded, video info: {new_vid_with_url}. RESPONSECODE:201") return new_vid_with_url, 201
def get(self, vid_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') args = parser.parse_args() self.logger.debug("getting uuid from token, via authsv") uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) self.logger.debug("getting single vid from videoDAO") vid = VideoDAO.get(vid_id, uuid) vid["author"] = AuthSender.get_author_name(vid["uuid"], args["x-access-token"]) self.logger.info(f"Retrieved single video, id {vid_id}, info: {vid}. RESPONSECODE:200") return vid, 200
def patch(self, vid_id): edit_parser = reqparse.RequestParser() edit_parser.add_argument("x-access-token", location='headers') edit_parser.add_argument('description', type = str, location = 'json') edit_parser.add_argument('location', type = str, location = 'json') edit_parser.add_argument('title', type = str, location = 'json') edit_parser.add_argument('is_private', type = bool, location = 'json') args = edit_parser.parse_args() uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) self.logger.debug("editing single vid from videoDAO") vid = VideoDAO.edit(vid_id, args, uuid) self.logger.info(f"Edited video info, id {vid_id}, info: {vid}. RESPONSECODE:200") return vid, 200
def get(self): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') parser.add_argument("search", type=str, required=False, location='args', default=None) parser.add_argument("page", type=int, required=False, location='args', default=1) parser.add_argument("per_page", type=int, required=False, location='args', default=50) args = parser.parse_args() uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) if args["search"]: videos = VideoDAO.get_from_search(uuid, args["x-access-token"], args["search"], page=args["page"], per_page=args["per_page"]) else: videos = VideoDAO.get_recommendations(uuid, args["x-access-token"], page=args["page"], per_page=args["per_page"]) # videos = VideoDAO.get_all(uuid, args["x-access-token"]) self.logger.info(f"Executed /videos search, found {len(videos['videos'])} videos. RESPONSECODE:200") return videos, 200
def delete(self, user_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers', required=True, help='Missing user token!') args = parser.parse_args() viewer_uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) if not AuthSender.has_permission(user_id, viewer_uuid): self.logger.info( f"User {viewer_uuid} attempted to delete user's {user_id} account. Access Denied." ) raise BadRequestError(f"You can't delete other users profiles!") UsersDAO.delete_user(user_id, args["x-access-token"]) return {"message": "OK"}, 200
def get(self, user_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers', required=True, help='Missing user token!') args = parser.parse_args() msg, code = AuthSender.get_user_info(user_id, args['x-access-token']) if code == 200: viewer_id = AuthSender.get_uuid_from_token(args["x-access-token"]) msg["friendship_status"] = UsersDAO.get_friendship_status( user_id, viewer_id) self.logger.info( f"User {user_id} info collected: {msg}. RESPONSECODE:{code}") return msg, code
def post(self): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers', required=True, help='Missing user token!') parser.add_argument("push_token", location='json', type=str, required=True, help="Missing Expo Push Token") args_dict = parser.parse_args() id = AuthSender.get_uuid_from_token(args_dict["x-access-token"]) UsersDAO.set_tkn(id, args_dict["push_token"]) self.logger.info( f"Added new push token for user {id}. RESPONSECODE:200") return {"message": "OK"}, 200
def post(self, other_user_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers', required=True, help='Missing user token!') parser.add_argument("text", location='json', type=str, required=True, help='You must include the text to be sent!') args = parser.parse_args() if args["text"] == "": raise BadRequestError("Invalid message length") sender_uuid = AuthSender.get_uuid_from_token(args['x-access-token']) author_name = AuthSender.get_author_name(sender_uuid, args["x-access-token"]) if not UsersDAO.are_friends(sender_uuid, other_user_id): raise BadRequestError("You are not friends with this user") msg = ChatsDAO.send_message(sender_uuid, other_user_id, args["text"], author_name) self.logger.info(f"Succesfully sent message from user {sender_uuid} to {other_user_id}. RESPONSECODE:200") return msg, 201
def post(self, sender_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') parser.add_argument( "accept", location='json', type=bool, required=True, help='You must specify if you either accept or reject the request') args = parser.parse_args() viewer_uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) msg = UsersDAO.respond_request(viewer_uuid, sender_id, accept=args["accept"]) self.logger.info( f"User {viewer_uuid} responded request from {sender_id}. Accepted: {args['accept']}. RESPONSECODE:200" ) return msg, 200
def post(self): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') parser.add_argument( "to", type=int, required=True, help="You must specify who you are sending this request to", location='json') args = parser.parse_args() sender_uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) author_name = AuthSender.get_author_name(sender_uuid, args["x-access-token"]) msg = UsersDAO.send_request(sender_uuid, args["to"], author_name) self.logger.info( f"Succesfully sent request from user {sender_uuid} to {args['to']}. RESPONSECODE:201" ) return msg, 201