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): 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): 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): code = req.get_param('code') if not code or code == '': resp.json = resp_error() raise falcon.HTTPBadRequest() group_id = group_id_from_code(code) group = req.session.query(Group).filter( Group.id == int(group_id)).first() user = req.session.query(User).filter(User.id == user_id).first() if not user or not group: resp.json = resp_error() raise falcon.HTTPBadRequest() if user not in group.users: group.users.append(user) req.session.commit() resp.json = {'status': 0, 'group': group.to_dict()}
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_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
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): 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): 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() 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_get(self, req, resp, user_id): code = req.get_param('code') if not code or code == "": resp.json = resp_error() raise falcon.HTTPBadRequest() group_id = group_id_from_code(code) if not group_id: resp.json = resp_error('Bad group code') raise falcon.HTTPBadRequest() user = req.session.query(User).filter(User.id == user_id).first() group = req.session.query(Group).filter(Group.id == group_id).first() if group: if not user: resp.set_header('Access-Control-Allow-Origin', '*') resp.json = { 'status': 0, 'group_name': group.name, 'member_count': group.memberships.count(), 'group_id': group.id, 'code': group_code_from_id(group.id), } return last_seen = None for m in user.memberships: if m.group.id == group.id: last_seen = m.last_seen resp.json = { 'status': 0, 'group_name': group.name, 'member_count': group.memberships.count(), 'group_id': group.id, 'code': group_code_from_id(group.id), 'last_seen': last_seen } else: resp.json = resp_error() raise falcon.HTTPBadRequest()
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_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 id error') raise falcon.HTTPBadRequest() def get_group_recent_timestamp(group): most_recent_clip = group.clips.order_by( Clip.timestamp.desc()).first() print(group.name) if most_recent_clip is None: print(group.timestamp) return group.timestamp else: print(most_recent_clip.timestamp) return most_recent_clip.timestamp groups = sorted(user.groups, key=lambda x: get_group_recent_timestamp(x), reverse=True) for g in groups: print(g.name) group_arr = [] for g in groups: g_dict = g.to_dict() last_seen = None for m in user.memberships: if m.group.id == g.id: last_seen = m.last_seen break g_dict['last_seen'] = last_seen # determine if vlog nudge should be shown # nudge_test = req.session.query(Clip).limit(5).all() nudges = [] g_dict['vlog_nudge_clips'] = [c.to_dict(user) for c in nudges] group_arr.append(g_dict) resp.json = {'status': 0, 'groups': group_arr}