예제 #1
0
파일: mail.py 프로젝트: SangminOut/But
    def post(self):
        """
        연서 보내기
        """
        user = UserModel.objects(uuid=request.headers['Authorization']).first()
        if not user:
            abort(401)

        receiver = UserModel.objects(uuid=request.json['receiver_id']).first()
        if not receiver:
            return Response('', 204)

        friends = FriendModel.objects(user=user).first()
        if receiver not in friends.friend:
            friends.friend.append(receiver)
            friends.save()

        friends = FriendModel.objects(user=receiver).first()
        if user not in friends.friend:
            friends.friend.append(user)
            friends.save()

        MailModel(sender=user, receiver=receiver,
                  image=request.json['mail']).save()

        return Response('', 201)
예제 #2
0
def block_friend(owner, user_id):
    if not UserModel.get_user_data_by_user_id(user_id):
        abort(404, "User Not Found")

    if not FriendModel.get_friend_state(owner, user_id):
        abort(409, "Not Friend")

    FriendModel.switching_blocking_state(owner, user_id)

    return {"message": "Switching Blocking State"}
예제 #3
0
def create_new_friend(owner_user, other_user):

    if owner_user == other_user:
        abort(400, "I can’t make yourself a friend")

    if not UserModel.get_user_data_by_user_id(other_user):
        abort(404, "This user can't find user data")

    if FriendModel.get_friend_state(owner_user, other_user):
        abort(409, "Already friend!")

    FriendModel.insert_friend(owner_user, other_user)

    return {"message": "Successfully add friend"}
예제 #4
0
def get_profile(owner_user_id, other_user_id):
    if not UserModel.get_user_data_by_user_id(other_user_id):
        abort(404, "This user not found")

    if owner_user_id == other_user_id:
        abort(409, "Please use 'GET /profile' api")

    user_data = UserModel.get_user_data_by_user_id(other_user_id)
    friend_state = FriendModel.get_friend_state(owner_user_id, other_user_id)
    room_id = MemberModel.get_room_id_by_member(owner_user_id, other_user_id)
    return {
        "profileData": {
            "id": other_user_id,
            "img": user_data.img,
            "name": user_data.name,
            "statusMessage": user_data.introduction
        },
        "state": {
            "friend": True if friend_state else False,
            "block": False if not friend_state else friend_state.blocking_state
        },
        "roomData": {
            "roomId": room_id if room_id else None
        }
    }
예제 #5
0
    def post(self):
        """
        정보 등록
        """
        payload = request.json
        uuid = str(uuid4())

        user = UserModel(uuid=uuid, **payload).save()
        FriendModel(user=user).save()
        return self.unicode_safe_json_dumps({'user_id': uuid}, 201)
예제 #6
0
def get_friends(owner_user):

    friendships = FriendModel.get_friendship_data(owner_user)
    friends = []
    for friendship in friendships:
        if friendship.blocking_state:
            continue
        friends.append(
            UserModel.get_user_data_by_user_id(friendship.friend_user_id))

    return {
        "friends": [{
            "id": friend.id,
            "img": friend.img,
            "name": friend.name
        } for friend in friends]
    }
예제 #7
0
    def get(self):
        user = UserModel.objects(uuid=request.headers['Authorization']).first()
        if not user:
            abort(401)

        friend = FriendModel.objects(user=user).first()
        if not friend:
            return Response('', 204)

        result = [{
            'id': friend.uuid,
            'name': friend.name,
            'profile_image': friend.profile_image,
            'region': friend.region,
            'age': friend.age
        }for friend in friend.friend]

        return self.unicode_safe_json_dumps(result)