def on_get(self, req, resp, user_id): query = req.get_param('query') if len(query) > 0: res_raw = req.session.query(Group).filter( Group.name.ilike('%' + query + '%')).all() results = [] for r in res_raw: results.append(r.to_dict()) resp.json = resp_success({'results': results}) else: resp.json = resp_success({'results': []})
def on_get(self, req, resp, user_id): user = req.session.query(User).filter(User.id == user_id).first() group_ids = [] for group in user.groups: group_ids.append(group.id) if len(group_ids) > 0: after_id = req.get_param('after_id') if after_id: vlogs = req.session.query(Vlog).filter(and_(Vlog.group_id.in_(group_ids), Vlog.id < after_id))\ .order_by(Vlog.timestamp.desc()).limit(VLOG_PAGE_SIZE) else: vlogs = req.session.query(Vlog).filter(Vlog.group_id.in_(group_ids)).order_by(Vlog.timestamp.desc())\ .limit(VLOG_PAGE_SIZE) resp.json = resp_success({'content': [v.to_dict() for v in vlogs]}) else: resp.json = resp_success({'content': []})
def on_get(self, req, resp, user_id): trending = req.session.query(Group).filter( Group.id.in_(trending_marbles)).all() results = [] for g in trending: results.append(g.to_dict()) resp.json = resp_success({'results': results})
def on_post(self, req, resp, user_id): clip_id = req.get_param('clip_id') clip = req.session.query(Clip).filter(Clip.id == int(clip_id)).first() if not clip: resp.json = resp_error() return new_flag = Flag(clip_id=clip.id) req.session.add(new_flag) resp.json = resp_success() return
def on_post(self, req, resp, user_id): vlog_id = req.get_param('vlog_id') if not vlog_id: resp.json = resp_error('No vlog id') raise falcon.HTTPBadRequest() vlog = req.session.query(Vlog).filter(Vlog.id == int(vlog_id)).first() if not vlog: resp.json = resp_error('Vlog does not exist') raise falcon.HTTPBadRequest() resp.json = resp_success( {'comments': [c.to_dict() for c in vlog.comments]})
def on_post(self, req, resp, user_id): name = req.get_param('name') if not name or name == '': resp.json = resp_error() return user = req.session.query(User).filter(User.id == user_id).first() group = Group(name=name) group.users.append(user) req.session.add(group) req.session.commit() resp.json = resp_success({'group': group.to_dict()})
def on_post(self, req, resp, user_id): clip_id = req.get_param('clip_id') user = req.session.query(User).filter(User.id == user_id).first() clip = req.session.query(Clip).filter(Clip.id == int(clip_id)).first() if not clip or not user: resp.json = resp_error() return if user in clip.likers: return clip.likers.append(user) clip.is_memory = 1 resp.json = resp_success()
def on_post(self, req, resp, user_id): vlog_id = req.get_param('vlog_id') if not vlog_id: resp.json = resp_error('No vlog id') raise falcon.HTTPBadRequest() vlog = req.session.query(Vlog).filter(Vlog.id == vlog_id).first() if not vlog: resp.json = resp_error('Bad vlog id') raise falcon.HTTPBadRequest() if not vlog.views: vlog.views = 0 vlog.views = vlog.views + 1 resp.json = resp_success()
def on_post(self, req, resp, user_id): clip_id = req.get_param('clip_id') user = req.session.query(User).filter(User.id == user_id).first() clip = req.session.query(Clip).filter(Clip.id == int(clip_id)).first() if not clip or not user: resp.json = resp_error() return try: req.session.query(ClipLike)\ .filter(and_(ClipLike.user_id == user_id, ClipLike.clip_id == int(clip_id))).delete() except ValueError: print("Used has not liked clip") resp.json = resp_success()
def on_post(self, req, resp, user_id): user = req.session.query(User).filter(User.id == user_id).first() if not user: resp.json = resp_error('User does not exist') return clip_id = req.get_param('clip_id') clip = req.session.query(Clip).filter(Clip.id == int(clip_id)).first() if user not in clip.group.users: resp.json = resp_error('User not apart of this marble') return clip.is_memory = 0 resp.json = resp_success() return
def on_post(self, req, resp, user_id): user = req.session.query(User).filter(User.id == user_id).first() group_id = req.get_param('group_id') group = req.session.query(Group).filter( Group.id == int(group_id)).first() if not group: resp.json = resp_error() return for m in user.memberships: if m.group.id == group.id: m.last_seen = time.time() * 1000 break resp.json = resp_success() return
def on_post(self, req, resp, user_id): user = req.session.query(User).filter(User.id == user_id).first() vlog_id = req.get_param('vlog_id') comment_content = req.get_param('comment_content') if not comment_content or not user or not vlog_id: resp.json = resp_error('Invalid parameters') raise falcon.HTTPBadRequest() vlog = req.session.query(Vlog).filter(Vlog.id == vlog_id).first() if not vlog: resp.json = resp_error('Vlog does not exist') raise falcon.HTTPBadRequest() new_comment = Comment(vlog_id=vlog.id, user_id=user.id, content=comment_content) vlog.comments.append(new_comment) req.session.commit() resp.json = resp_success({'comment': new_comment.to_dict()})
def on_get(self, req, resp, user_id): user = req.session.query(User).filter(User.id == user_id).first() if not user: resp.json = resp_error('User does not exist') return json = [] for group in user.groups: user_blocks = [u.id for u in user.blocks] if len(user_blocks): memories = group.clips.filter((Clip.is_memory == 1) & ( Clip.user_id.notin_(user_blocks))).all() else: memories = group.clips.filter(Clip.is_memory == 1).all() memories_dict = [clip.to_dict(user) for clip in memories] json.append({'group_id': group.id, 'clips': memories_dict}) resp.json = resp_success({'content': json}) return
def on_post(self, req, resp, user_id): user = req.session.query(User).filter(User.id == user_id).first() if not user: resp.json = resp_error() return group_id = req.get_param('group_id') video = req.get_param('video') descr = req.get_param('description') clip_ids_str = req.get_param('clip_ids') clip_ids = [] print(clip_ids_str) for c_str in clip_ids_str.split(','): try: clip_ids.append(int(c_str)) except ValueError: resp.json = resp_error('Invalid clip ids format') raise falcon.HTTPBadRequest() group = req.session.query(Group).filter(Group.id == group_id).first() if group is None or video is None: raise falcon.HTTPBadReqest() s3 = boto_session.resource('s3') rand_str = str(uuid.uuid4()) s3.Bucket(S3_BUCKET_NAME).put_object(Body=video.file, Key="media/" + rand_str, ContentType='video/mp4') print("VLOG UPLOAD: " + rand_str) new_vlog = Vlog(media_id=rand_str, group_id=group_id, editor_id=user_id, description=descr) req.session.add(new_vlog) req.session.commit() # send_posted_notifications(user, group) resp.json = resp_success({'media_id': rand_str}) return