|
| 1 | +from flask_restplus import Namespace, Resource, fields |
| 2 | + |
| 3 | +ns = Namespace('technologies', description='API for technologies used') |
| 4 | + |
| 5 | +# Technology Model |
| 6 | +technology = ns.model('Technology', { |
| 7 | + 'id': fields.String( |
| 8 | + readOnly=True, |
| 9 | + required=True, |
| 10 | + title='Identifier', |
| 11 | + description='The unique id of the technology' |
| 12 | + ), |
| 13 | + 'tenant_id': fields.String( |
| 14 | + required=True, |
| 15 | + title='Tenant', |
| 16 | + max_length=64, |
| 17 | + description='The tenant this technology belongs to' |
| 18 | + ), |
| 19 | + 'name': fields.String( |
| 20 | + required=True, |
| 21 | + title='Name', |
| 22 | + max_length=50, |
| 23 | + description='Name of the technology' |
| 24 | + ), |
| 25 | + 'created_at': fields.Date( |
| 26 | + title='Date', |
| 27 | + description='Date of creation' |
| 28 | + ), |
| 29 | + 'created_by': fields.String( |
| 30 | + required=True, |
| 31 | + title='Type', |
| 32 | + max_length=30, |
| 33 | + description='Id of user who first added this technology', |
| 34 | + ), |
| 35 | +}) |
| 36 | + |
| 37 | + |
| 38 | +@ns.route('') |
| 39 | +class Technologies(Resource): |
| 40 | + @ns.doc('list_technologies') |
| 41 | + @ns.marshal_list_with(technology, code=200) |
| 42 | + def get(self): |
| 43 | + """List all technologies""" |
| 44 | + return [], 200 |
| 45 | + |
| 46 | + @ns.doc('create_technology') |
| 47 | + @ns.expect(technology) |
| 48 | + @ns.marshal_with(technology, code=201) |
| 49 | + def post(self): |
| 50 | + """Create a technology""" |
| 51 | + return ns.payload, 201 |
| 52 | + |
| 53 | + |
| 54 | +@ns.route('/<string:uid>') |
| 55 | +@ns.response(404, 'Technology not found') |
| 56 | +@ns.param('uid', 'The technology identifier') |
| 57 | +class Technology(Resource): |
| 58 | + @ns.doc('get_technology') |
| 59 | + @ns.marshal_with(technology) |
| 60 | + def get(self, uid): |
| 61 | + """Retrieve a technology""" |
| 62 | + return {} |
| 63 | + |
| 64 | + @ns.doc('update_technology_status') |
| 65 | + @ns.param('uid', 'The technology identifier') |
| 66 | + @ns.expect(technology) |
| 67 | + @ns.response(204, 'State of the technology successfully updated') |
| 68 | + def post(self, uid): |
| 69 | + """Updates a technology using form data""" |
| 70 | + return ns.payload() |
| 71 | + |
| 72 | + @ns.doc('put_technology') |
| 73 | + @ns.expect(technology) |
| 74 | + @ns.marshal_with(technology) |
| 75 | + def put(self, uid): |
| 76 | + """Create or replace a technology""" |
| 77 | + return ns.payload() |
| 78 | + |
| 79 | + @ns.doc('delete_technology') |
| 80 | + @ns.response(204, 'Technology deleted successfully') |
| 81 | + def delete(self, uid): |
| 82 | + """Deletes a technology""" |
| 83 | + return None, 204 |
0 commit comments