Skip to content

get participant list api (fixes#20) #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 26, 2019
2 changes: 2 additions & 0 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from backend.extensions import db, mail, migrate, jwt
from backend.blueprints import auth
from backend.blueprints.contact import contact
from backend.blueprints.participants import participants


def create_app():
Expand Down Expand Up @@ -35,3 +36,4 @@ def initialize_extensions(app):
def register_blueprints(app):
app.register_blueprint(auth.auth_blueprint)
app.register_blueprint(contact)
app.register_blueprint(participants)
16 changes: 16 additions & 0 deletions backend/blueprints/participants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from flask import Blueprint, jsonify, request
from flask_jwt_extended import jwt_required
from backend.models import Participant
from backend.serializers.participant_serializer import participants_schema

participants = Blueprint('participants', __name__)


@participants.route('/participants', methods=['GET'])
@jwt_required
def get_participants_list():
participants_list = Participant.query.all()
if participants_list:
participants = participants_schema.dump(participants_list)
return jsonify({"participants": participants}), 200
return jsonify({"message": "participants not found"}), 404
16 changes: 16 additions & 0 deletions backend/serializers/participant_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from marshmallow import Schema, fields, validate


class ParticipantSchema(Schema):
class Meta:
fields = ('name', 'lastname', 'email', 'github', 'phone')

name = fields.Str(required=True, validate=[validate.Length(max=50)])
lastname = fields.Str(validate=[validate.Length(max=50)])
email = fields.Email(validate=[validate.Length(max=200)])
github = fields.Str(validate=[validate.Length(max=200)])
phone = fields.Str(validate=[validate.Length(max=13)])


participant_schema = ParticipantSchema()
participants_schema = ParticipantSchema(many=True)