def post(self): email = request.form.get('email', default=None) phone = request.form.get('phone', default=None) code = request.form.get('code', type=int) if email: if CertifyModel.objects(identity=email, code=code): CertifyModel.objects(identity=email, code=code).first().delete() return { 'id': AccountModel.objects(email=email).first().id }, 201 else: return '', 204 elif phone: if CertifyModel.objects(identity=phone, code=code): CertifyModel.objects(identity=phone, code=code).first().delete() return { 'id': AccountModel.objects(phone=phone).first().id }, 201 else: return '', 204
def post(self): # 친구 수락 requester_id = request.form.get('requester_id') FriendRequestsModel.objects(requester_id=requester_id, receiver_id=current_identity).first().delete() friends = AccountModel.objects(id=current_identity).first().friends friends.append(requester_id) AccountModel.objects(id=current_identity).first().update(friends=friends) return '', 201
def delete(self): friend_id = request.form.get('friend_id') friends = AccountModel.objects(id=current_identity).first().friends try: del friends[friends.index(friend_id)] except ValueError: pass AccountModel.objects(id=current_identity).first().update(friends=friends) return '', 200
def delete(self): content_id = request.form.get('content_id', type=int) wish_list = list( set( list( AccountModel.objects( id=current_identity).first().wish_list))) del wish_list[wish_list.index(content_id)] AccountModel.objects(id=current_identity).first().update( wish_list=wish_list) return '', 200
def delete(self): topic = request.form.get('topic') chat_rooms = AccountModel.objects( id=current_identity).first().chat_rooms for idx, chat_room in enumerate(chat_rooms): if chat_room.topic == topic: del chat_rooms[idx] AccountModel.objects(id=current_identity).first().update( chat_rooms=chat_rooms) return '', 200
def get(self): email = request.args.get('email', default=None) phone = request.args.get('phone', default=None) code = get_certify_code() if email and AccountModel.objects(email=email): CertifyModel(identity=email, code=code).save() send_certify_mail(email, code) return '', 200 elif phone and AccountModel.objects(phone=phone): pass else: return '', 204
def post(self): """ 구글 로그인 """ token = request.form.get('token') email = request.form.get('email') name = request.form.get('name') if not AccountModel.objects(id=token): AccountModel(id=token, email=email, name=name).save() return { 'access_token': create_access_token(identity=token) }, 201
def post(self): title = request.form.get('title') topic = str(u.uuid4()) chat_rooms = list( AccountModel.objects(id=current_identity).first().chat_rooms) # Get existing chat rooms chat_rooms.append(ChatModel(topic=topic, title=title)) # Append new chat room AccountModel.objects(id=current_identity).first().update( chat_rooms=chat_rooms) # Update return {'topic': topic}, 201
def post(self): """ 회원가입 """ id = request.form.get('id') pw = request.form.get('pw') email = request.form.get('email') name = request.form.get('name') if AccountModel.objects(id=id): return Response('', 204) AccountModel(id=id, pw=pw, email=email, name=name).save() return Response('', 201)
def post(self): content_id = request.form.get('content_id', type=int) if not TourTopModel.objects(content_id=content_id)\ or content_id in AccountModel.objects(id=current_identity).first().wish_list: # Content id does not exist, or Already in wish list return '', 200 else: wish_list = list( AccountModel.objects(id=current_identity).first().wish_list) wish_list.append(content_id) AccountModel.objects(id=current_identity).first().update( wish_list=wish_list) return '', 201
def post(self): """ 서비스 자체 로그인 """ id = request.form.get('id', None) pw = request.form.get('pw', None) if not id: return { 'msg': 'Missing id parameter' }, 400 if not pw: return { 'msg': 'Missing pw parameter' }, 400 elif id and pw and AccountModel.objects(id=id, pw=pw): return { 'access_token': create_access_token(identity=id) }, 201 else: return { 'msg': 'Incorrect id or password' }, 401
def detect(tour_list, sort_type, x=0.0, y=0.0): client_wish_list = AccountModel.objects( id=current_identity).first().wish_list if sort_type == 1: # 조회순 tour_list = sorted(tour_list, key=lambda k: k.views, reverse=True) elif sort_type == 2: # 위시리스트 많은 순 tour_list = sorted(tour_list, key=lambda k: k.wish_count, reverse=True) elif sort_type == 3: # 거리순 for tour in tour_list: tour.distance = math.sqrt( math.pow(tour.x - x, 2) + math.pow(tour.y - y, 2)) tour_list = sorted(tour_list, key=lambda k: k.distance) return [{ 'content_id': tour.content_id, 'content_type_id': tour.content_type_id, 'title': tour.title, 'address': tour.address, 'category': tour.small_category, 'image': tour.image, 'wish_count': tour.wish_count, 'wished': tour.id in client_wish_list, 'x': tour.x, 'y': tour.y } for tour in tour_list]
def post(self): """ 댓글 업로드 """ news_id = request.form.get('id') content = request.form.get('content') user = AccountModel.objects(id=get_jwt_identity()).first() user.update(comment_count=user.comment_count + 1) CommentModel( news=NewsModel.objects(id=news_id).first(), writer=AccountModel.objects(id=get_jwt_identity()).first(), content=content).save() return Response('', 201)
def get(self): friends = AccountModel.objects(id=current_identity).first().friends if friends: return friends, 200 else: return '', 204
def get(self): """ 내 정보 """ user = AccountModel.objects(id=get_jwt_identity()).first() return {'email': user.email, 'name': user.name}, 200
def post(self): """ 댓글 좋아요 """ comment_id = request.form.get('id') comment = CommentModel.objects(id=comment_id).first() liked_users = list(comment.liked_users) if get_jwt_identity() in liked_users: return Response('', 204) liked_users.append(get_jwt_identity()) comment.update(liked_users=liked_users) comment_writer = comment.writer comment_writer.update( received_like_count=comment_writer.received_like_count + 1) notification_queue = list(comment_writer.notification_queue) notification_queue.append( NotificationModel( target=str(comment.news.id), content='{0}님이 회원님의 댓글을 좋아합니다'.format( AccountModel.objects(id=get_jwt_identity()).first().name))) comment_writer.update(notification_queue=notification_queue) return Response('', 201)
def post(self): topic = request.form.get('topic') target_id = request.form.get('target_id') chat_rooms = AccountModel.objects( id=current_identity).first().chat_rooms try: for chat_room in chat_rooms: if chat_room.topic == topic: target_rooms = AccountModel.objects( id=target_id).first().chat_rooms target_rooms.append(chat_room) AccountModel.objects( id=target_id).first().update(target_rooms) return '', 201 except AttributeError: return '', 204
def get(self): chat_rooms = [{ 'topic': chat_room.topic, 'title': chat_room.title } for chat_room in AccountModel.objects( id=current_identity).first().chat_rooms] if chat_rooms: return chat_rooms, 200 else: return '', 204
def post(self): id = request.form.get('id') pw = request.form.get('pw') registration_id = request.form.get('registration_id') email = request.form.get('email', default=None) phone = request.form.get('phone', default=None) name = request.form.get('name') if AccountModel.objects(id=id): return '', 204 else: AccountModel.objects(registration_id=registration_id).delete() AccountModel(id=id, pw=pw, registration_id=registration_id, email=email, phone=phone, name=name).save() return '', 201
def post(self): """ ID 중복체크 """ id = request.form.get('id') if AccountModel.objects(id=id): # Exist return Response('', 204) else: # Not Exist return Response('', 201)
def post(self): """ 이메일 중복체크 """ email = request.form.get('email') if AccountModel.objects(email=email): # Exist return Response('', 204) else: # Not Exist return Response('', 201)
def get(self): """ 알림 """ return sorted( [{ 'target_news': str(notification.target_news), 'content': notification.content, 'notification_time': str(notification.notification_time.date()) } for notification in AccountModel.objects( id=get_jwt_identity()).first().notification_queue], key=lambda k: k['notification_time'], reverse=True), 200
def get(self): content_id = request.args.get('content_id', type=int) tour = mongo_to_dict( TourTopModel.objects(content_id=content_id).first(), ['views', '_cls']) if not tour: return '', 204 tour['wished'] = tour['content_id'] in AccountModel.objects( id=current_identity).first().wish_list tour['category'] = tour.pop('small_category') return tour
def get(self): id = request.args.get('id') user_data = AccountModel.objects(id=id).first() friend_requested = True if FriendRequestsModel.objects( requester_id=current_identity, receiver_id=id) else None if not user_data: return '', 204 else: return { 'id': id, 'email': user_data.email, 'phone': user_data.phone, 'name': user_data.name, 'friend_requested': friend_requested }
def get(self): """ 활동 기록 """ user = AccountModel.objects(id=get_jwt_identity()).first() after_signup = date.today() - user.signup_date.date() return { 'after_signup': after_signup, 'contribution_score': user.comment_count * 5 + user.received_like_count * 2, 'comment_count': user.comment_count, 'received_like_count': user.received_like_count, 'comment_avg': user.comment_count / after_signup, 'received_like_avg': user.received_like_count / after_signup }, 200
def authenticate(id, pw): if id and pw and AccountModel.objects(id=id, pw=pw): return User(id=id)
def get(self): return list( AccountModel.objects(id=current_identity).first().wish_list), 200
def post(self): if AccountModel.objects(email=request.form.get('email')): return '', 204 else: return '', 201
def post(self): if AccountModel.objects(phone=request.form.get('phone')): return '', 204 else: return '', 201