Example #1
0
 def get(self, name):
     claims = get_jwt_claims()
     if not claims['is_admin']:
         return {'message': 'Owner privilege required'}, 403
     ship = ShipModel.find_by_name(name)
     if ship:
         return ship.json()
Example #2
0
    def delete(self, name):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Owner privilege required'}, 403
        ship = ShipModel.find_by_name(name)
        if ship:
            ship.delete_from_db()
            return {'message': 'ship deleted'}

        return {'message': 'Ship not found.'}, 400
Example #3
0
    def post(self, id):
        if ShipModel.find_by_id(id):
            return {'message': "An ship with id '{}' already exists.".format(id)}, 400

        data = Ship.parser.parse_args()

        ship = ShipModel(id, **data)

        try:
            ship.save_to_db()
        except:
            return {"message": "An error occurred inserting the ship."}, 500

        return ship.json(), 201
Example #4
0
    def put(self, name):
        data = Ship.parser.parse_args()

        ship = ShipModel.find_by_name(name)

        if ship:
            ship.type = data['type']
            ship.length = data['length']
            ship.shipSelf = "data['shipSelf']"
        else:
            ship = ShipModel(name, **data)

        ship.save_to_db()

        return ship.json()
Example #5
0
    def put(self, id):
        data = Ship.parser.parse_args()

        ship = ShipModel.find_by_id(id)

        if ship:
            ship.name = data['name']
            ship.type = data['type']
            ship.length = data['length']
            ship.self_ship = data['self_ship']
            ship.save_to_db()
            return ship.json(), 303
        else:
            ship = ShipModel(id, **data)
            ship.save_to_db()
            return ship.json(), 201
Example #6
0
    def post(self):
        data = Ship.parser.parse_args()
        name = data['name']
        if ShipModel.find_by_name(name):
            return {
                'message': "A ship with name '{}' already exists.".format(name)
            }, 400

        data = Ship.parser.parse_args()

        ship = ShipModel(name, data['type'], data['length'], data['shipSelf'])
        try:
            ship.save_to_db()
        except:
            return {"message": "An error occurred creating the ship."}, 500

        return ship.json(), 201
Example #7
0
    def post(self):
        data = Ship.parser.parse_args()
        name = data['name']
        str1 = "https://ship-user-login.herokuapp.com/"
        str2 = str1 + name
        user_id = get_jwt_identity()
        # user = UserModel(find_by_username())
        if ShipModel.find_by_name(name):
            return {
                'message': "A ship with name '{}' already exists.".format(name)
            }, 400

        # data = Ship.parser.parse_args()

        ship = ShipModel(name, data['type'], data['length'], data['owner'],
                         str2)
        try:
            ship.save_to_db()
        except:
            return {"message": "An error occurred creating the ship."}, 500

        return ship.json(), 201
Example #8
0
    def delete(self, name):
        ship = ShipModel.find_by_name(name)
        if ship:
            ship.delete_from_db()

        return {'message': 'Ship not found.'}, 400
Example #9
0
 def get(self, name):
     ship = ShipModel.find_by_name(name)
     if ship:
         return ship.html()
Example #10
0
 def get(self, name):
     ship = ShipModel.find_by_name(name)
     if ship:
         return ship.json()
     return {'message': 'Ship not found'}, 404
Example #11
0
 def delete(self, id):
     ship = ShipModel.find_by_id(id)
     if ship:
         ship.delete_from_db()
         return {'message': 'Ship deleted.'}, 204
     return {'message': 'Ship not found.'}, 405
Example #12
0
 def get(self, id):
     ship = ShipModel.find_by_id(id)
     if ship:
         return ship.html()
     return {'message': 'Ship not found - no content'}, 204