예제 #1
0
    def post(self):
        if 'name' not in request.json:
            return { 'message' : "missed required name field"}, 400

        community_name = request.json['name']
        if is_not_valid_entity_name(community_name):
            return { 'message' : "invalid name" }

        q = Community.query.filter_by(name=community_name)

        if q.count() != 0:
            return { 'message' : "name already used" }

        db.session.add(Community(name=community_name, owner=User.query.first()))
        db.session.commit()
        return ""
예제 #2
0
    def post(self, community):
        if 'name' not in request.json:
            return { "message" : "missing required field: name"}

        name = request.json['name'].lower()
        if is_not_valid_entity_name(name):
            return { "message" : "invalid name"}

        q = Player.query.filter_by(username=name)
        if q.count() != 0:
            return { "message" : "player with this name already exists" }, 400

        player = Player(community=community, username=name)
        db.session.add(player)
        db.session.commit()

        return {"username": player.username}
예제 #3
0
    def post(self, community):
        """Method to create new team in the community.

        Required data:
        - team name ('name')
        - forward username ('forward')
        - goalkeeper username ('goalkeeper')

        If one of those fields is missed error will be returned.
        """
        if 'name' not in request.json:
            return { "message": "missing required field: name" }

        name = request.json['name'].lower()
        if is_not_valid_entity_name(name):
            return { "message": "invalid name" }

        q = Team.query.filter_by(community_id=community.id, name=name)
        if q.count() != 0:
            return { "message": "team with this name already exists" }, 400

        if 'forward' not in request.json:
            return { "message" : "missing required field: forward" }

        forward = PlayerService.find_by_username(community, request.json['forward'])
        if forward is None:
            return { "message": "forward not found" }

        if 'goalkeeper' not in request.json:
            return { "message" : "missing required field: forward" }

        goalkeeper = PlayerService.find_by_username(community, request.json['goalkeeper'])
        if goalkeeper is None:
            return { "message": "goalkeeper not found" }

        team = TeamService.create(community, name, goalkeeper, forward)

        return team.serialize