Esempio n. 1
0
def create_contact():
    full_name = request.json.get('full_name')
    email = request.json.get('email')
    agenda_slug = request.json.get('agenda_slug')
    address = request.json.get('address')
    phone = request.json.get('phone')

    contact = Contact.query.filter_by(agenda_slug=agenda_slug).first()
    if contact:
        return jsonify({"msg": "agenda already exists"})
    else:
        if not full_name:
            return jsonify({"msg": "Full name is required"}), 400
        if not email:
            return jsonify({"msg": "Email required"}), 400
        if not agenda_slug:
            return jsonify({"msg": "Agenda slug is required"}), 400
        if not address:
            return jsonify({"msg": "Address is required"}), 400
        if not phone:
            return jsonify({"msg": "Phone is required"}), 400

        contact = Contact()
        contact.full_name = full_name
        contact.email = email
        contact.agenda_slug = agenda_slug
        contact.address = address
        contact.phone = phone
        contact.save()

        return jsonify(contact.serialize()), 201
Esempio n. 2
0
def create_contact():
    full_name = request.json.get("full_name", None)
    email = request.json.get("email", None)
    agenda_slug = request.json.get("agenda_slug", None)
    address = request.json.get("address", "")
    phone = request.json.get("phone", "")

    if not full_name:
        return jsonify({"msg": "full_name is required"}), 400

    contact = Contact()
    contact.full_name = full_name
    contact.email = email
    contact.agenda_slug = agenda_slug
    contact.address = address
    contact.phone = phone

    contact.save()

    return jsonify(contact.serialize()), 201