def topics(id=None): if request.method == 'GET': if id is not None: topic = Topic.query.get(id) if topic: return jsonify(topic.serialize()), 200 else: return jsonify({"msg": "topic not found"}), 404 else: topics = Topic.query.all() topics = list(map(lambda topic: topic.serialize(), topics)) return jsonify(topics), 200 if request.method == 'POST': title = request.json.get('title', None) priority = request.json.get('priority', None) notes = request.json.get('notes', None) care = request.json.get('care', None) tracking = request.json.get('tracking', None) duration = request.json.get('duration', None) meeting_id = request.json.get('meeting_id', None) if not title: return jsonify({"msg": "title is required"}), 422 if not priority: return jsonify({"msg": "priority is required"}), 422 topic = Topic() topic.title = title topic.priority = priority topic.notes = notes topic.care = care topic.tracking = tracking topic.duration = duration topic.meeting_id = meeting_id db.session.add(topic) db.session.commit() return jsonify(topic.serialize()), 201 if request.method == 'PUT': title = request.json.get('title', None) priority = request.json.get('priority', None) notes = request.json.get('notes', None) care = request.json.get('care', None) tracking = request.json.get('tracking', None) duration = request.json.get('duration', None) meeting_id = request.json.get('meeting_id', None) if not title: return jsonify({"msg": "title is required"}), 422 if not priority: return jsonify({"msg": "priority is required"}), 422 topic = Topic.query.get(id) if not topic: return jsonify({"msg": "topic not found"}), 404 topic.title = title topic.priority = priority topic.notes = notes topic.care = care topic.tracking = tracking topic.duration = duration topic.meeting_id = meeting_id db.session.commit() return jsonify(topic.serialize()), 200 if request.method == 'DELETE': topic = Topic.query.get(id) if not topic: return jsonify({"msg": "topic not found"}), 404 db.session.delete(topic) db.session.commit() return jsonify({"msg": "topic deleted"}), 200
def meetings(id=None): if request.method == 'GET': if id is not None: meeting = Meeting.query.get(id) if meeting: return jsonify(meeting.serialize()), 200 else: return jsonify({"msg": "meeting not found"}), 404 else: meetings = Meeting.query.all() meetings = list(map(lambda meeting: meeting.serialize(), meetings)) return jsonify(meetings), 200 if request.method == 'POST': #create_date = request.json.get('create_date', None) meeting_date = request.json.get('meeting_date', None) meeting_hour = request.json.get('meeting_hour', None) project_name = request.json.get('project_name', None) title = request.json.get('title', None) topics = request.json.get('topics', None) guests = request.json.get('guests', None) place = request.json.get('place', None) description = request.json.get('description', None) target = request.json.get('target', None) done = request.json.get('done', None) user_id = request.json.get('user_id', None) if not meeting_date: return jsonify({"msg": "date is required"}), 422 if not meeting_hour: return jsonify({"msg": "hour is required"}), 422 if not project_name: return jsonify({"msg": "project name is required"}), 422 if not title: return jsonify({"msg": "title is required"}), 422 if not place: return jsonify({"msg": "place is required"}), 422 meeting = Meeting() #meeting.create_date = create_date meeting.meeting_date = meeting_date meeting.meeting_hour = meeting_hour meeting.project_name = project_name meeting.title = title meeting.place = place meeting.description = description meeting.target = target meeting.done = done meeting.user_id = user_id db.session.add(meeting) db.session.commit() if topics: if len(topics) > 1: for x in range(len(topics)): top = Topic() top.title = topics[x]["title"] top.priority = topics[x]["priority"] top.notes = topics[x]["notes"] top.care = topics[x]["care"] top.tracking = topics[x]["tracking"] top.duration = topics[x]["duration"] top.meeting_id = meeting.id db.session.add(top) else: top = Topic() top.title = topics[0]["title"] top.priority = topics[0]["priority"] top.notes = topics[0]["notes"] top.care = topics[0]["care"] top.tracking = topics[0]["tracking"] top.duration = topics[0]["duration"] top.meeting_id = meeting.id db.session.add(top) db.session.commit() if guests: if len(guests) > 1: for x in range(len(guests)): gue = Guest() gue.fullname = guests[x]["fullname"] gue.email = guests[x]["email"] gue.rol = guests[x]["rol"] gue.meeting_id = meeting.id db.session.add(gue) else: gue = Guest() gue.fullname = guests[0]["fullname"] gue.email = guests[0]["email"] gue.rol = guests[0]["rol"] gue.meeting_id = meeting.id db.session.add(gue) db.session.commit() return jsonify(meeting.serialize()), 201 if request.method == 'PUT': #create_date = request.json.get('create_date', None) meeting_date = request.json.get('meeting_date', None) meeting_hour = request.json.get('meeting_hour', None) project_name = request.json.get('project_name', None) title = request.json.get('title', None) topics = request.json.get('topics', None) guests = request.json.get('guests', None) place = request.json.get('place', None) description = request.json.get('description', None) target = request.json.get('target', None) done = request.json.get('done', None) user_id = request.json.get('user_id', None) # if not meeting_date: # return jsonify({"msg": "date is required"}), 422 # if not meeting_hour: # return jsonify({"msg": "hour is required"}), 422 # if not project_name: # return jsonify({"msg": "project name is required"}), 422 # if not title: # return jsonify({"msg": "title is required"}), 422 # if not place: # return jsonify({"msg": "place is required"}), 422 meeting = Meeting.query.get(id) if not meeting: return jsonify({"msg": "meeting not found"}), 404 #meeting.create_date = create_date meeting.meeting_date = meeting_date meeting.meeting_hour = meeting_hour meeting.project_name = project_name meeting.title = title meeting.place = place meeting.description = description meeting.target = target meeting.done = done meeting.user_id = user_id db.session.commit() if topics: if len(topics) > 0: for x in range(len(topics)): if topics[x]["id"] == 0: top = Topic() top.title = topics[x]["title"] top.priority = topics[x]["priority"] top.notes = topics[x]["notes"] top.care = topics[x]["care"] top.tracking = topics[x]["tracking"] top.duration = topics[x]["duration"] top.meeting_id = meeting.id db.session.add(top) else: top = Topic.query.get(topics[x]["id"]) top.title = topics[x]["title"] top.priority = topics[x]["priority"] top.notes = topics[x]["notes"] top.care = topics[x]["care"] top.tracking = topics[x]["tracking"] top.duration = topics[x]["duration"] top.meeting_id = meeting.id db.session.commit() if guests: if len(guests) > 0: for x in range(len(guests)): if guests[x]["id"] == 0: gue = Guest() gue.fullname = guests[x]["fullname"] gue.email = guests[x]["email"] gue.rol = guests[x]["rol"] gue.meeting_id = meeting.id db.session.add(gue) else: gue = Guest.query.get(guests[x]["id"]) gue.fullname = guests[x]["fullname"] gue.email = guests[x]["email"] gue.rol = guests[x]["rol"] gue.meeting_id = meeting.id db.session.commit() return jsonify(meeting.serialize()), 200 if request.method == 'DELETE': Topic.query.filter_by(meeting_id=id).delete() Guest.query.filter_by(meeting_id=id).delete() meeting = Meeting.query.get(id) if not meeting: return jsonify({"msg": "meeting not found"}), 404 db.session.delete(meeting) db.session.commit() return jsonify({"msg": "meeting deleted"}), 200