Changeset 041e464 for src/mapservice
- Timestamp:
- May 1, 2019, 3:55:35 PM (8 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 1e7f556
- Parents:
- be25db1
- Location:
- src/mapservice
- Files:
-
- 1 deleted
- 8 edited
-
openapi.yaml (modified) (8 diffs)
-
src-gen/openapi_server/models/__init__.py (modified) (1 diff)
-
src-gen/openapi_server/models/water.py (modified) (8 diffs)
-
src-gen/openapi_server/models/water_creation.py (modified) (4 diffs)
-
src-gen/openapi_server/openapi/openapi.yaml (modified) (11 diffs)
-
src-gen/openapi_server/test/test_default_controller.py (deleted)
-
src/server_impl/controllers/WatersController.py (modified) (3 diffs)
-
src/server_impl/database/Model.py (modified) (4 diffs)
-
src/server_impl/tests/test_waters.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/mapservice/openapi.yaml
rbe25db1 r041e464 168 168 in: query 169 169 schema: 170 $ref: '#/components/schemas/item _name'170 $ref: '#/components/schemas/itemName' 171 171 example: 'Missi' 172 172 - name: manager … … 202 202 schema: 203 203 $ref: '#/components/schemas/WaterCreation' 204 examples: 205 Water: 206 $ref: '#/components/examples/WaterCreation' 204 example: 205 name: Rhein 206 osmId: 1756854 207 osmType: 'Relation' 207 208 responses: 208 209 '201': … … 232 233 required: true 233 234 schema: 234 $ref: '#/components/schemas/item _id'235 $ref: '#/components/schemas/itemId' 235 236 responses: 236 237 '200': … … 271 272 title: Activation code for a User 272 273 type: string 273 item _id:274 itemId: 274 275 title: Item ID 275 276 type: integer 276 277 format: int32 277 item _name:278 itemName: 278 279 title: Item Name 279 280 type: string 280 281 osmType: 281 maxLength: 1 282 minLength: 1 283 type: string 282 title: OSM type of item (N|W|R) 283 type: string 284 enum: 285 - Node 286 - Way 287 - Relation 284 288 User: 285 289 title: User … … 323 327 properties: 324 328 waterId: 325 $ref: '#/components/schemas/item _id'329 $ref: '#/components/schemas/itemId' 326 330 name: 327 $ref: '#/components/schemas/item _name'331 $ref: '#/components/schemas/itemName' 328 332 manager: 329 333 $ref: '#/components/schemas/username' 330 334 osmId: 331 $ref: '#/components/schemas/item _id'335 $ref: '#/components/schemas/itemId' 332 336 osmType: 333 $ref: '#/components/schemas/osmType'334 osm_class:335 337 $ref: '#/components/schemas/osmType' 336 338 required: … … 342 344 properties: 343 345 name: 344 $ref: '#/components/schemas/item _name'346 $ref: '#/components/schemas/itemName' 345 347 osmId: 346 $ref: '#/components/schemas/item _id'348 $ref: '#/components/schemas/itemId' 347 349 osmType: 348 350 $ref: '#/components/schemas/osmType' … … 438 440 osmId: 1756854 439 441 osmType: R 440 link: 'http://gnuboat.engsas.com/mapservice/v1/waters/1'441 442 summary: A water example object 442 443 WaterCreation: … … 444 445 name: Mississippi 445 446 osmId: 1756854 446 osmType: R447 osmType: 'Relation' 447 448 summary: A water example object for creation of a water 448 449 waters: 449 450 value: 450 451 - waterId: 1 451 name: Mississippi452 name: 'Mississippi' 452 453 osmId: 1756854 453 osmType: R 454 link: 'http://gnuboat.engsas.com/mapservice/v1/waters/1' 454 osmType: 'Relation' 455 455 - waterId: 2 456 name: Bodensee 457 link: 'http://gnuboat.engsas.com/mapservice/v1/waters/2' 456 name: 'Bodensee' 458 457 summary: A sample list with waters 459 458 HttpError: -
src/mapservice/src-gen/openapi_server/models/__init__.py
rbe25db1 r041e464 6 6 from openapi_server.models.http_error import HttpError 7 7 from openapi_server.models.order import Order 8 from openapi_server.models.osm_type import OsmType 8 9 from openapi_server.models.user import User 9 10 from openapi_server.models.user_creation import UserCreation -
src/mapservice/src-gen/openapi_server/models/water.py
rbe25db1 r041e464 9 9 from openapi_server import util 10 10 11 from openapi_server.models.osm_type import OsmType # noqa: E501 11 12 12 13 class Water(Model): … … 16 17 """ 17 18 18 def __init__(self, water_id=None, name=None, manager=None, osm_id=None, osm_type=None , osm_class=None): # noqa: E50119 def __init__(self, water_id=None, name=None, manager=None, osm_id=None, osm_type=None): # noqa: E501 19 20 """Water - a model defined in OpenAPI 20 21 … … 28 29 :type osm_id: int 29 30 :param osm_type: The osm_type of this Water. # noqa: E501 30 :type osm_type: str 31 :param osm_class: The osm_class of this Water. # noqa: E501 32 :type osm_class: str 31 :type osm_type: OsmType 33 32 """ 34 33 self.openapi_types = { … … 37 36 'manager': str, 38 37 'osm_id': int, 39 'osm_type': str, 40 'osm_class': str 38 'osm_type': OsmType 41 39 } 42 40 … … 46 44 'manager': 'manager', 47 45 'osm_id': 'osmId', 48 'osm_type': 'osmType', 49 'osm_class': 'osm_class' 46 'osm_type': 'osmType' 50 47 } 51 48 … … 55 52 self._osm_id = osm_id 56 53 self._osm_type = osm_type 57 self._osm_class = osm_class58 54 59 55 @classmethod … … 162 158 163 159 :return: The osm_type of this Water. 164 :rtype: str160 :rtype: OsmType 165 161 """ 166 162 return self._osm_type … … 172 168 173 169 :param osm_type: The osm_type of this Water. 174 :type osm_type: str170 :type osm_type: OsmType 175 171 """ 176 if osm_type is not None and len(osm_type) > 1:177 raise ValueError("Invalid value for `osm_type`, length must be less than or equal to `1`") # noqa: E501178 if osm_type is not None and len(osm_type) < 1:179 raise ValueError("Invalid value for `osm_type`, length must be greater than or equal to `1`") # noqa: E501180 172 181 173 self._osm_type = osm_type 182 183 @property184 def osm_class(self):185 """Gets the osm_class of this Water.186 187 188 :return: The osm_class of this Water.189 :rtype: str190 """191 return self._osm_class192 193 @osm_class.setter194 def osm_class(self, osm_class):195 """Sets the osm_class of this Water.196 197 198 :param osm_class: The osm_class of this Water.199 :type osm_class: str200 """201 if osm_class is not None and len(osm_class) > 1:202 raise ValueError("Invalid value for `osm_class`, length must be less than or equal to `1`") # noqa: E501203 if osm_class is not None and len(osm_class) < 1:204 raise ValueError("Invalid value for `osm_class`, length must be greater than or equal to `1`") # noqa: E501205 206 self._osm_class = osm_class -
src/mapservice/src-gen/openapi_server/models/water_creation.py
rbe25db1 r041e464 9 9 from openapi_server import util 10 10 11 from openapi_server.models.osm_type import OsmType # noqa: E501 11 12 12 13 class WaterCreation(Model): … … 24 25 :type osm_id: int 25 26 :param osm_type: The osm_type of this WaterCreation. # noqa: E501 26 :type osm_type: str27 :type osm_type: OsmType 27 28 """ 28 29 self.openapi_types = { 29 30 'name': str, 30 31 'osm_id': int, 31 'osm_type': str32 'osm_type': OsmType 32 33 } 33 34 … … 103 104 104 105 :return: The osm_type of this WaterCreation. 105 :rtype: str106 :rtype: OsmType 106 107 """ 107 108 return self._osm_type … … 113 114 114 115 :param osm_type: The osm_type of this WaterCreation. 115 :type osm_type: str116 :type osm_type: OsmType 116 117 """ 117 if osm_type is not None and len(osm_type) > 1:118 raise ValueError("Invalid value for `osm_type`, length must be less than or equal to `1`") # noqa: E501119 if osm_type is not None and len(osm_type) < 1:120 raise ValueError("Invalid value for `osm_type`, length must be greater than or equal to `1`") # noqa: E501121 118 122 119 self._osm_type = osm_type -
src/mapservice/src-gen/openapi_server/openapi/openapi.yaml
rbe25db1 r041e464 235 235 required: false 236 236 schema: 237 $ref: '#/components/schemas/item _name'237 $ref: '#/components/schemas/itemName' 238 238 style: form 239 239 - example: jane … … 297 297 content: 298 298 application/json: 299 examples: 300 Water: 301 $ref: '#/components/examples/WaterCreation' 299 example: 300 name: Rhein 301 osmId: 1756854 302 osmType: Relation 302 303 schema: 303 304 $ref: '#/components/schemas/WaterCreation' … … 348 349 required: true 349 350 schema: 350 $ref: '#/components/schemas/item _id'351 $ref: '#/components/schemas/itemId' 351 352 style: simple 352 353 responses: … … 398 399 osmId: 1756854 399 400 osmType: R 400 link: http://gnuboat.engsas.com/mapservice/v1/waters/1401 401 WaterCreation: 402 402 summary: A water example object for creation of a water … … 404 404 name: Mississippi 405 405 osmId: 1756854 406 osmType: R 406 osmType: Relation 407 407 waters: 408 408 summary: A sample list with waters … … 411 411 name: Mississippi 412 412 osmId: 1756854 413 osmType: R 414 link: http://gnuboat.engsas.com/mapservice/v1/waters/1 413 osmType: Relation 415 414 - waterId: 2 416 415 name: Bodensee 417 link: http://gnuboat.engsas.com/mapservice/v1/waters/2418 416 HttpError: 419 417 value: … … 508 506 title: Activation code for a User 509 507 type: string 510 item _id:508 itemId: 511 509 format: int32 512 510 title: Item ID 513 511 type: integer 514 item _name:512 itemName: 515 513 title: Item Name 516 514 type: string 517 515 osmType: 518 maxLength: 1 519 minLength: 1 516 enum: 517 - Node 518 - Way 519 - Relation 520 title: OSM type of item (N|W|R) 520 521 type: string 521 522 User: … … 580 581 osmId: 6 581 582 name: name 582 osmType: osmType583 osm_class: osm_class584 583 waterId: 0 585 584 properties: … … 599 598 type: integer 600 599 osmType: 601 maxLength: 1 602 minLength: 1 603 type: string 604 osm_class: 605 maxLength: 1 606 minLength: 1 607 type: string 600 $ref: '#/components/schemas/osmType' 608 601 required: 609 602 - name … … 615 608 osmId: 0 616 609 name: name 617 osmType: osmType618 610 properties: 619 611 name: … … 625 617 type: integer 626 618 osmType: 627 maxLength: 1 628 minLength: 1 629 type: string 619 $ref: '#/components/schemas/osmType' 630 620 required: 631 621 - name -
src/mapservice/src/server_impl/controllers/WatersController.py
rbe25db1 r041e464 17 17 import connexion 18 18 19 from ..database.Model import User, Water 19 from ..database.Model import User, Water, db 20 20 from ..HttpErrors import BadRequest, Unauthorized, NotFound 21 from .UsersController import loggedin_user 21 22 22 23 def waters_get(name=None, manager=None, order_by=None, offset=None, limit=None): … … 39 40 40 41 if query is None: 41 print("5")42 42 query = Water.query 43 43 … … 48 48 49 49 def water_get_by_id(id): 50 return {51 'water_id': id,52 'name': 'Mississippi'53 }50 water = Water.query.filter_by(id=id).all() 51 if len(water) != 1: 52 return NotFound 53 return water[0].to_dict() 54 54 55 def waters_post(water): 56 print(connexion.context['user']) 57 return water 55 def waters_create(water_creation): 56 user = loggedin_user() 57 if user is None: 58 return Unauthorized 59 60 water = Water(name=water_creation.name, manager=user, osm_id=water_creation.osm_id, osm_type=water_creation.osm_type) 61 db.session.add(water) 62 db.session.commit() 63 return water.to_dict() -
src/mapservice/src/server_impl/database/Model.py
rbe25db1 r041e464 17 17 import flask 18 18 from flask_sqlalchemy import SQLAlchemy 19 from sqlalchemy import inspect, text 19 from sqlalchemy import inspect, text, Enum 20 20 import hashlib 21 21 import datetime 22 import enum 22 23 23 24 db = SQLAlchemy() 25 26 class OsmType(enum.Enum): 27 Node = 1 28 Way = 2 29 Relation = 3 24 30 25 31 class User(db.Model): … … 81 87 name = db.Column(db.String(255), nullable=False) 82 88 manager_id = db.Column(db.Integer, db.ForeignKey('users.id')) 83 osm_id = db.Column(db.BigInteger) 84 osm_type = db.Column(db.String(255)) 85 osm_class = db.Column(db.String(255)) 89 osm_id = db.Column(db.Integer) 90 osm_type = db.Column(Enum(OsmType)) 86 91 manager = db.relationship("User", backref=db.backref("waters", uselist=False), lazy=True) 87 92 … … 93 98 result['osmId'] = obj.osm_id 94 99 if obj.osm_type: 95 result['osmType'] = obj.osm_type 96 if obj.osm_class: 97 result['osmClass'] = obj.osm_class 100 result['osmType'] = obj.osm_type.name 98 101 return result 99 102 … … 136 139 db.session.add(test_key) 137 140 if len(Water.query.filter_by(name='Mississippi').all()) < 1: 138 mississippi = Water(name='Mississippi', manager=test_user_jane )141 mississippi = Water(name='Mississippi', manager=test_user_jane, osm_id=1756854, osm_type=OsmType.Relation) 139 142 db.session.add(mississippi) 143 if len(Water.query.filter_by(name='Forggensee').all()) < 1: 144 mississippi = Water(name='Forggensee', manager=test_user_john, osm_id=897899, osm_type=OsmType.Relation) 145 db.session.add(mississippi) 140 146 db.session.commit() 141 147 -
src/mapservice/src/server_impl/tests/test_waters.py
rbe25db1 r041e464 39 39 assert "name" in data[0] 40 40 assert data[0]["name"] == "Mississippi" 41 assert "water_id" in data[0] 42 assert data[0]["waterId"] == "1" 41 assert "waterId" in data[0] 42 assert data[0]["waterId"] == 1 43 assert "osmId" in data[0] 44 assert data[0]["osmId"] == 1756854 45 assert "osmType" in data[0] 46 assert data[0]["osmType"] == "Relation" 47 43 48 def get_by_name(self): 44 49 headers = {} … … 61 66 assert "name" in data[0] 62 67 assert data[0]["name"] == "Mississippi" 63 assert "water_id" in data[0] 64 assert data[0]["waterId"] == "1" 68 assert "waterId" in data[0] 69 assert data[0]["waterId"] == 1 70 assert "osmId" in data[0] 71 assert data[0]["osmId"] == 1756854 72 assert "osmType" in data[0] 73 assert data[0]["osmType"] == "Relation" 65 74 66 75 def get_by_manager(self): … … 84 93 assert "name" in data[0] 85 94 assert data[0]["name"] == "Mississippi" 86 assert "water_id" in data[0] 87 assert data[0]["waterId"] == "1" 95 assert "waterId" in data[0] 96 assert data[0]["waterId"] == 1 97 assert "osmId" in data[0] 98 assert data[0]["osmId"] == 1756854 99 assert "osmType" in data[0] 100 assert data[0]["osmType"] == "Relation" 88 101 89 102 def get_by_name_manager(self): … … 113 126 assert "name" in data[0] 114 127 assert data[0]["name"] == "Mississippi" 115 assert "water_id" in data[0] 116 assert data[0]["waterId"] == "1" 128 assert "waterId" in data[0] 129 assert data[0]["waterId"] == 1 130 assert "osmId" in data[0] 131 assert data[0]["osmId"] == 1756854 132 assert "osmType" in data[0] 133 assert data[0]["osmType"] == "Relation" 117 134 118 135 if __name__ == '__main__':
Note:
See TracChangeset
for help on using the changeset viewer.
