Changeset ec8d5d0
- Timestamp:
- Oct 20, 2019, 5:46:41 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 1cd45dd
- Parents:
- 5446f28
- git-author:
- Joachim Langenbach <joachim.langenbach@…> (10/20/19 16:25:04)
- git-committer:
- Joachim Langenbach <joachim.langenbach@…> (10/20/19 17:46:41)
- Location:
- src/mapservice
- Files:
-
- 1 added
- 2 edited
-
openapi.yaml (modified) (11 diffs)
-
src/server_impl/controllers/DevicesController.py (added)
-
src/server_impl/database/Model.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/mapservice/openapi.yaml
r5446f28 rec8d5d0 23 23 default: v1 24 24 paths: 25 '/user':25 /user: 26 26 get: 27 27 description: Returns information of current/authorized user … … 82 82 content: 83 83 application/json: {} 84 '/user/apikey_create':84 /user/apikey_create: 85 85 get: 86 86 description: Generates and returns a new API key for current user … … 157 157 type: string 158 158 description: 'URL to the website, showing the result of the activation' 159 '/waters':159 /waters: 160 160 get: 161 161 description: Returns all waters … … 375 375 '400': 376 376 $ref: '#/components/responses/BadRequest' 377 '404': 378 $ref: '#/components/responses/NotFound' 379 '/devices': 380 get: 381 description: Returns all devices of user 382 tags: 383 - devices 384 summary: Find devices by id 385 operationId: devicesGet 386 security: 387 - basicAuth: [] 388 - apiKeyAuth: [] 389 parameters: 390 - name: name 391 in: query 392 schema: 393 $ref: '#/components/schemas/itemName' 394 example: Love 395 - $ref: '#/components/parameters/orderBy' 396 - $ref: '#/components/parameters/offset' 397 - $ref: '#/components/parameters/limit' 398 responses: 399 '200': 400 description: OK 401 content: 402 application/json: 403 schema: 404 $ref: '#/components/schemas/devices' 405 examples: 406 Devices: 407 $ref: '#/components/examples/devices' 408 '404': 409 $ref: '#/components/responses/NotFound' 410 post: 411 description: Adds a new device to the database 412 tags: 413 - devices 414 summary: Add a new device 415 operationId: devicesCreate 416 security: 417 - basicAuth: [] 418 - apiKeyAuth: [] 419 parameters: 420 - name: user_id 421 in: path 422 description: User ID 423 required: true 424 schema: 425 $ref: '#/components/schemas/itemId' 426 requestBody: 427 content: 428 application/json: 429 schema: 430 $ref: '#/components/schemas/DeviceCreation' 431 example: 432 name: "Lovely Boat" 433 sensorDepth: 2 434 responses: 435 '201': 436 description: Device created 437 content: 438 application/json: 439 schema: 440 $ref: '#/components/schemas/Device' 441 examples: 442 Device: 443 $ref: '#/components/examples/Device' 444 '400': 445 $ref: '#/components/responses/BadRequest' 446 '401': 447 $ref: '#/components/responses/Unauthorized' 448 '/devices/{id}': 449 get: 450 description: Returns the device identified by id 451 tags: 452 - devices 453 summary: Represents a device 454 operationId: devicesGetById 455 security: 456 - basicAuth: [] 457 - apiKeyAuth: [] 458 parameters: 459 - name: id 460 in: path 461 description: Item ID 462 required: true 463 schema: 464 $ref: '#/components/schemas/itemId' 465 responses: 466 '200': 467 description: OK 468 content: 469 application/json: 470 schema: 471 $ref: '#/components/schemas/Device' 472 examples: 473 Water: 474 $ref: '#/components/examples/Device' 377 475 '404': 378 476 $ref: '#/components/responses/NotFound' … … 455 553 coordinates: 456 554 $ref: '#/components/schemas/point' 555 sensorDepth: 556 type: number 557 title: 'Depth of sensor beneath water level in cm (positive means below water)' 558 minimum: 0 457 559 User: 458 560 title: User … … 511 613 - name 512 614 WaterCreation: 513 title: Water 615 title: Water for Creation 514 616 type: object 515 617 properties: … … 591 693 items: 592 694 $ref: '#/components/schemas/GaugeGeoJson' 695 Device: 696 title: Device 697 type: object 698 properties: 699 deviceId: 700 $ref: '#/components/schemas/itemId' 701 name: 702 $ref: '#/components/schemas/itemName' 703 sensorDepth: 704 $ref: '#/components/schemas/sensorDepth' 705 comment: 706 $ref: '#/components/schemas/comment' 707 required: 708 - deviceId 709 - name 710 - sensorDepth 711 DeviceCreation: 712 title: Device for Creation 713 type: object 714 properties: 715 name: 716 $ref: '#/components/schemas/itemName' 717 sensorDepth: 718 $ref: '#/components/schemas/sensorDepth' 719 comment: 720 $ref: '#/components/schemas/comment' 721 required: 722 - name 723 - sensorDepth 724 devices: 725 title: Devices 726 type: array 727 items: 728 $ref: '#/components/schemas/Device' 593 729 HttpError: 594 730 title: HTTP Error Response Object … … 704 840 coordinates: 705 841 - 90.136111 706 - 29.934722 842 - 29.934722 707 843 properties: 708 844 name: New Orleans … … 716 852 coordinates: 717 853 - 90.136111 718 - 29.934722 854 - 29.934722 719 855 properties: 720 856 name: New Orleans … … 722 858 comment: Gauge for Mississippi in New Orleans 723 859 summary: A sample list of gauges in GeoJson format 860 Device: 861 value: 862 deviceId: 1 863 name: Lovely Boat 864 sensorDepth: 0.2 865 comment: Really a pleasure to measure 866 summary: A sample device 867 devices: 868 value: 869 - deviceId: 1 870 name: Lovely Boat 871 sensorDepth: 0.2 872 comment: Really a pleasure to measure 724 873 HttpError: 725 874 value: … … 761 910 - name: users 762 911 description: All actions used to manage users and api keys 912 - name: devices 913 description: All actions used to manage devices of an user -
src/mapservice/src/server_impl/database/Model.py
r5446f28 rec8d5d0 79 79 @staticmethod 80 80 def loggedin_username(): 81 if not 'user' in connexion.context: 82 return None 81 83 return connexion.context['user'] 82 84 … … 84 86 def loggedin_user(): 85 87 username = User.loggedin_username() 88 if username is None: 89 return None 86 90 user = User.query.filter_by(username=username).all() 87 91 if len(user) != 1: … … 168 172 point = to_shape(wkbelement) 169 173 return {'longitude': point.x, 'latitude': point.y} 174 175 class Device(db.Model): 176 __tablename__ = "devices" 177 178 id = db.Column(db.Integer, primary_key=True, autoincrement=True) 179 name = db.Column(db.String(255), nullable=False) 180 owner_id = db.Column(db.Integer, db.ForeignKey('users.id')) 181 sensor_depth = db.Column(db.Float, nullable=False) 182 comment = db.Column(db.String(255)) 183 184 owner = db.relationship("User", backref=db.backref("devices"), lazy=True) 185 186 def to_dict(obj): 187 result = { 'deviceId': obj.id, 'name': obj.name, 'sensorDepth': obj.sensor_depth } 188 if obj.comment: 189 result['comment'] = obj.comment 190 return result 170 191 171 192 def db_setup(): … … 227 248 new_orleans = Gauge(name='New Orleans', manager=test_user_jane, water=mississippi, location='SRID=4326;POINT(-90.136111 29.934722)') 228 249 db.session.add(new_orleans) 250 251 252 if len(Device.query.filter_by(name='GnuBoat 1').all()) < 1: 253 gnuboat_one = Device(name='GnuBoat 1', owner=test_user_jane, sensor_depth=0.2, comment='SUP attachment') 254 db.session.add(gnuboat_one) 229 255 db.session.commit() 230 256
Note:
See TracChangeset
for help on using the changeset viewer.
