Beispiel #1
0
def communitiesInscription():
    response = Response("", status=204, mimetype='application/json')

    if request.method == "GET":
        members = []
        for member in membersMemory:
            members.append(member.toDict())

        response = Response(json.dumps(members),
                            status=200,
                            mimetype='application/json')

    elif request.method == "POST":

        form = request.get_json()

        if "memberId" in form and "derLatitude" in form and "derLongitude" in form and "surname" in form and "name" in form and "derName" in form:
            if form["memberId"] != "":

                if validateFloat(form["derLatitude"]):
                    derLatitude = float(form["derLatitude"])

                if validateFloat(form["derLongitude"]):
                    derLongitude = float(form["derLongitude"])

                for community in communitiesMemory:
                    if haversineMeasure(community.coords[0],
                                        community.coords[1], derLatitude,
                                        derLongitude) <= 500:
                        member = Member(form["memberId"], form["name"],
                                        form["surname"], form["derLatitude"],
                                        form["derLongitude"], form["derName"],
                                        community.name)
                        print(isInMembersMemory(member))
                        if not isInMembersMemory(member):
                            membersMemory.append(member)
                            response = Response(json.dumps(member.toDict()),
                                                status=200,
                                                mimetype='application/json')
            else:
                response = Response(error400Message,
                                    status=400,
                                    mimetype='application/json')
        else:
            response = Response(error400Message,
                                status=400,
                                mimetype='application/json')

    return response