Changeset ec8d5d0


Ignore:
Timestamp:
Oct 20, 2019, 5:46:41 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
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)
Message:

Added devices to service

Location:
src/mapservice
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/mapservice/openapi.yaml

    r5446f28 rec8d5d0  
    2323        default: v1
    2424paths:
    25   '/user':
     25  /user:
    2626    get:
    2727      description: Returns information of current/authorized user
    … …  
    8282          content:
    8383            application/json: {}
    84   '/user/apikey_create':
     84  /user/apikey_create:
    8585    get:
    8686      description: Generates and returns a new API key for current user
    … …  
    157157                type: string
    158158              description: 'URL to the website, showing the result of the activation'
    159   '/waters':
     159  /waters:
    160160    get:
    161161      description: Returns all waters
    … …  
    375375        '400':
    376376          $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'
    377475        '404':
    378476          $ref: '#/components/responses/NotFound'
    … …  
    455553        coordinates:
    456554          $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
    457559    User:
    458560      title: User
    … …  
    511613        - name
    512614    WaterCreation:
    513       title: Water
     615      title: Water for Creation
    514616      type: object
    515617      properties:
    … …  
    591693      items:
    592694        $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'
    593729    HttpError:
    594730      title: HTTP Error Response Object
    … …  
    704840          coordinates:
    705841            - 90.136111
    706             - 29.934722 
     842            - 29.934722
    707843          properties:
    708844            name: New Orleans
    … …  
    716852            coordinates:
    717853              - 90.136111
    718               - 29.934722 
     854              - 29.934722
    719855            properties:
    720856              name: New Orleans
    … …  
    722858              comment: Gauge for Mississippi in New Orleans
    723859      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
    724873    HttpError:
    725874      value:
    … …  
    761910  - name: users
    762911    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  
    7979        @staticmethod
    8080        def loggedin_username():
     81                if not 'user' in connexion.context:
     82                        return None
    8183                return connexion.context['user']
    8284
    … …  
    8486        def loggedin_user():
    8587                username = User.loggedin_username()
     88                if username is None:
     89                        return None
    8690                user = User.query.filter_by(username=username).all()
    8791                if len(user) != 1:
    … …  
    168172                point = to_shape(wkbelement)
    169173                return {'longitude': point.x, 'latitude': point.y}
     174       
     175class 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
    170191
    171192def db_setup():
    … …  
    227248                        new_orleans = Gauge(name='New Orleans', manager=test_user_jane, water=mississippi, location='SRID=4326;POINT(-90.136111 29.934722)')
    228249                        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)
    229255                db.session.commit()
    230256
Note: See TracChangeset for help on using the changeset viewer.