category: Tutorial
name: getEmployment
uri: /tutorials/employments
additional_paths:
  - '/tutorials/employments/{entryNumber}'
method: GET
routing_auto_generation_mode: true
spec:
  response:
    normal:
      codes:
        - 200
  request:
    params:
      type: object
      properties:
        entryNumber:
          type: array
          items:
            type: string
        firstName:
          type: array
          items:
            type: string
            pattern: '[a-zA-Z]'
        lastName:
          type: array
          items:
            type: string
            pattern: '[a-zA-Z]'
        email:
          type: array
          items:
            type: string
            format: email
        salaryRequirements:
          type: array
          items:
            type: integer
            minimum: 0
            maximum: 99999999
    resources:
      type: object
      properties:
        entryNumber:
          type: string
commands:
  - command: script
    kwargs:
      code: |-
        async with model.aiodb() as conn:
            if context.request.resources.entryNumber:
                cursor = await conn.execute(model.Employment.select().where(model.Employment.c.entryNumber==context.request.resources.entryNumber))
                if cursor.rowcount == 0:
                    raise Error(404, reason="Could not found employment")

                employment = await cursor.fetchone()
                context.session.finish(rowtodict(employment))
                return
            logger.info(context.request.params.dictionary)
            cursor = await conn.execute(model.Employment.select().where(where_statement(model.Employment, context.request.params.dictionary)))
            employments = await cursor.fetchall()
            context.session.finish([rowtodict(employment) for employment in employments])
request_timeout: 60
connect_timeout: 60