Changeset 041e464 for src/mapservice


Ignore:
Timestamp:
May 1, 2019, 3:55:35 PM (8 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
1e7f556
Parents:
be25db1
Message:

Adding waters is working

Location:
src/mapservice
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/mapservice/openapi.yaml

    rbe25db1 r041e464  
    168168          in: query
    169169          schema:
    170             $ref: '#/components/schemas/item_name'
     170            $ref: '#/components/schemas/itemName'
    171171          example: 'Missi'
    172172        - name: manager
    … …  
    202202            schema:
    203203              $ref: '#/components/schemas/WaterCreation'
    204             examples:
    205               Water:
    206                 $ref: '#/components/examples/WaterCreation'
     204            example:
     205              name: Rhein
     206              osmId: 1756854
     207              osmType: 'Relation'
    207208      responses:
    208209        '201':
    … …  
    232233          required: true
    233234          schema:
    234             $ref: '#/components/schemas/item_id'
     235            $ref: '#/components/schemas/itemId'
    235236      responses:
    236237        '200':
    … …  
    271272      title: Activation code for a User
    272273      type: string
    273     item_id:
     274    itemId:
    274275      title: Item ID
    275276      type: integer
    276277      format: int32
    277     item_name:
     278    itemName:
    278279      title: Item Name
    279280      type: string
    280281    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
    284288    User:
    285289      title: User
    … …  
    323327      properties:
    324328        waterId:
    325           $ref: '#/components/schemas/item_id'
     329          $ref: '#/components/schemas/itemId'
    326330        name:
    327           $ref: '#/components/schemas/item_name'
     331          $ref: '#/components/schemas/itemName'
    328332        manager:
    329333          $ref: '#/components/schemas/username'
    330334        osmId:
    331           $ref: '#/components/schemas/item_id'
     335          $ref: '#/components/schemas/itemId'
    332336        osmType:
    333           $ref: '#/components/schemas/osmType'
    334         osm_class:
    335337          $ref: '#/components/schemas/osmType'
    336338      required:
    … …  
    342344      properties:
    343345        name:
    344           $ref: '#/components/schemas/item_name'
     346          $ref: '#/components/schemas/itemName'
    345347        osmId:
    346           $ref: '#/components/schemas/item_id'
     348          $ref: '#/components/schemas/itemId'
    347349        osmType:
    348350          $ref: '#/components/schemas/osmType'
    … …  
    438440        osmId: 1756854
    439441        osmType: R
    440         link: 'http://gnuboat.engsas.com/mapservice/v1/waters/1'
    441442      summary: A water example object
    442443    WaterCreation:
    … …  
    444445        name: Mississippi
    445446        osmId: 1756854
    446         osmType: R
     447        osmType: 'Relation'
    447448      summary: A water example object for creation of a water
    448449    waters:
    449450      value:
    450451        - waterId: 1
    451           name: Mississippi
     452          name: 'Mississippi'
    452453          osmId: 1756854
    453           osmType: R
    454           link: 'http://gnuboat.engsas.com/mapservice/v1/waters/1'
     454          osmType: 'Relation'
    455455        - waterId: 2
    456           name: Bodensee
    457           link: 'http://gnuboat.engsas.com/mapservice/v1/waters/2'
     456          name: 'Bodensee'
    458457      summary: A sample list with waters
    459458    HttpError:
  • src/mapservice/src-gen/openapi_server/models/__init__.py

    rbe25db1 r041e464  
    66from openapi_server.models.http_error import HttpError
    77from openapi_server.models.order import Order
     8from openapi_server.models.osm_type import OsmType
    89from openapi_server.models.user import User
    910from openapi_server.models.user_creation import UserCreation
  • src/mapservice/src-gen/openapi_server/models/water.py

    rbe25db1 r041e464  
    99from openapi_server import util
    1010
     11from openapi_server.models.osm_type import OsmType  # noqa: E501
    1112
    1213class Water(Model):
    … …  
    1617    """
    1718
    18     def __init__(self, water_id=None, name=None, manager=None, osm_id=None, osm_type=None, osm_class=None):  # noqa: E501
     19    def __init__(self, water_id=None, name=None, manager=None, osm_id=None, osm_type=None):  # noqa: E501
    1920        """Water - a model defined in OpenAPI
    2021
    … …  
    2829        :type osm_id: int
    2930        :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
    3332        """
    3433        self.openapi_types = {
    … …  
    3736            'manager': str,
    3837            'osm_id': int,
    39             'osm_type': str,
    40             'osm_class': str
     38            'osm_type': OsmType
    4139        }
    4240
    … …  
    4644            'manager': 'manager',
    4745            'osm_id': 'osmId',
    48             'osm_type': 'osmType',
    49             'osm_class': 'osm_class'
     46            'osm_type': 'osmType'
    5047        }
    5148
    … …  
    5552        self._osm_id = osm_id
    5653        self._osm_type = osm_type
    57         self._osm_class = osm_class
    5854
    5955    @classmethod
    … …  
    162158
    163159        :return: The osm_type of this Water.
    164         :rtype: str
     160        :rtype: OsmType
    165161        """
    166162        return self._osm_type
    … …  
    172168
    173169        :param osm_type: The osm_type of this Water.
    174         :type osm_type: str
     170        :type osm_type: OsmType
    175171        """
    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: E501
    178         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: E501
    180172
    181173        self._osm_type = osm_type
    182 
    183     @property
    184     def osm_class(self):
    185         """Gets the osm_class of this Water.
    186 
    187 
    188         :return: The osm_class of this Water.
    189         :rtype: str
    190         """
    191         return self._osm_class
    192 
    193     @osm_class.setter
    194     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: str
    200         """
    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: E501
    203         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: E501
    205 
    206         self._osm_class = osm_class
  • src/mapservice/src-gen/openapi_server/models/water_creation.py

    rbe25db1 r041e464  
    99from openapi_server import util
    1010
     11from openapi_server.models.osm_type import OsmType  # noqa: E501
    1112
    1213class WaterCreation(Model):
    … …  
    2425        :type osm_id: int
    2526        :param osm_type: The osm_type of this WaterCreation.  # noqa: E501
    26         :type osm_type: str
     27        :type osm_type: OsmType
    2728        """
    2829        self.openapi_types = {
    2930            'name': str,
    3031            'osm_id': int,
    31             'osm_type': str
     32            'osm_type': OsmType
    3233        }
    3334
    … …  
    103104
    104105        :return: The osm_type of this WaterCreation.
    105         :rtype: str
     106        :rtype: OsmType
    106107        """
    107108        return self._osm_type
    … …  
    113114
    114115        :param osm_type: The osm_type of this WaterCreation.
    115         :type osm_type: str
     116        :type osm_type: OsmType
    116117        """
    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: E501
    119         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: E501
    121118
    122119        self._osm_type = osm_type
  • src/mapservice/src-gen/openapi_server/openapi/openapi.yaml

    rbe25db1 r041e464  
    235235        required: false
    236236        schema:
    237           $ref: '#/components/schemas/item_name'
     237          $ref: '#/components/schemas/itemName'
    238238        style: form
    239239      - example: jane
    … …  
    297297        content:
    298298          application/json:
    299             examples:
    300               Water:
    301                 $ref: '#/components/examples/WaterCreation'
     299            example:
     300              name: Rhein
     301              osmId: 1756854
     302              osmType: Relation
    302303            schema:
    303304              $ref: '#/components/schemas/WaterCreation'
    … …  
    348349        required: true
    349350        schema:
    350           $ref: '#/components/schemas/item_id'
     351          $ref: '#/components/schemas/itemId'
    351352        style: simple
    352353      responses:
    … …  
    398399        osmId: 1756854
    399400        osmType: R
    400         link: http://gnuboat.engsas.com/mapservice/v1/waters/1
    401401    WaterCreation:
    402402      summary: A water example object for creation of a water
    … …  
    404404        name: Mississippi
    405405        osmId: 1756854
    406         osmType: R
     406        osmType: Relation
    407407    waters:
    408408      summary: A sample list with waters
    … …  
    411411        name: Mississippi
    412412        osmId: 1756854
    413         osmType: R
    414         link: http://gnuboat.engsas.com/mapservice/v1/waters/1
     413        osmType: Relation
    415414      - waterId: 2
    416415        name: Bodensee
    417         link: http://gnuboat.engsas.com/mapservice/v1/waters/2
    418416    HttpError:
    419417      value:
    … …  
    508506      title: Activation code for a User
    509507      type: string
    510     item_id:
     508    itemId:
    511509      format: int32
    512510      title: Item ID
    513511      type: integer
    514     item_name:
     512    itemName:
    515513      title: Item Name
    516514      type: string
    517515    osmType:
    518       maxLength: 1
    519       minLength: 1
     516      enum:
     517      - Node
     518      - Way
     519      - Relation
     520      title: OSM type of item (N|W|R)
    520521      type: string
    521522    User:
    … …  
    580581        osmId: 6
    581582        name: name
    582         osmType: osmType
    583         osm_class: osm_class
    584583        waterId: 0
    585584      properties:
    … …  
    599598          type: integer
    600599        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'
    608601      required:
    609602      - name
    … …  
    615608        osmId: 0
    616609        name: name
    617         osmType: osmType
    618610      properties:
    619611        name:
    … …  
    625617          type: integer
    626618        osmType:
    627           maxLength: 1
    628           minLength: 1
    629           type: string
     619          $ref: '#/components/schemas/osmType'
    630620      required:
    631621      - name
  • src/mapservice/src/server_impl/controllers/WatersController.py

    rbe25db1 r041e464  
    1717import connexion
    1818
    19 from ..database.Model import User, Water
     19from ..database.Model import User, Water, db
    2020from ..HttpErrors import BadRequest, Unauthorized, NotFound
     21from .UsersController import loggedin_user
    2122
    2223def waters_get(name=None, manager=None, order_by=None, offset=None, limit=None):
    … …  
    3940       
    4041        if query is None:
    41                 print("5")
    4242                query = Water.query
    4343       
    … …  
    4848
    4949def 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()
    5454
    55 def waters_post(water):
    56         print(connexion.context['user'])
    57         return water
     55def 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  
    1717import flask
    1818from flask_sqlalchemy import SQLAlchemy
    19 from sqlalchemy import inspect, text
     19from sqlalchemy import inspect, text, Enum
    2020import hashlib
    2121import datetime
     22import enum
    2223
    2324db = SQLAlchemy()
     25
     26class OsmType(enum.Enum):
     27        Node = 1
     28        Way = 2
     29        Relation = 3
    2430
    2531class User(db.Model):
    … …  
    8187        name = db.Column(db.String(255), nullable=False)
    8288        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))
    8691        manager = db.relationship("User", backref=db.backref("waters", uselist=False), lazy=True)
    8792       
    … …  
    9398                        result['osmId'] = obj.osm_id
    9499                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
    98101                return result
    99102
    … …  
    136139                                db.session.add(test_key)
    137140                        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)
    139142                                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)
    140146                        db.session.commit()
    141147
  • src/mapservice/src/server_impl/tests/test_waters.py

    rbe25db1 r041e464  
    3939                assert "name" in data[0]
    4040                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
    4348        def get_by_name(self):
    4449                headers = {}
    … …  
    6166                assert "name" in data[0]
    6267                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"
    6574               
    6675        def get_by_manager(self):
    … …  
    8493                assert "name" in data[0]
    8594                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"
    88101               
    89102        def get_by_name_manager(self):
    … …  
    113126                assert "name" in data[0]
    114127                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"
    117134       
    118135if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.