category: Tutorial
name: deleteEmployment
uri: '/tutorials/employments/{entryNumber}'
method: DELETE
routing_auto_generation_mode: true
spec:
  response:
    normal:
      codes:
        - 200
  request:
    resources:
      type: object
      properties:
        entryNumber:
          type: string
      required:
        - entryNumber
commands:
  - command: script
    kwargs:
      code: |-
        async with model.aiodb() as conn:
            if not context.request.resources.entryNumber:
                raise Error(400, reason="entryNumber is not specified")

            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")

            await conn.execute(model.Employment.delete().where(model.Employment.c.entryNumber==context.request.resources.entryNumber))
            context.session.set_status(204)
            context.session.finish()
request_timeout: 60
connect_timeout: 60