openapi: 3.0.0
info:
  title: ConFusion Ristorante
  description: API definition for the Con Fusion Ristorante (web & android) App
  version: 1.0.0
  license:
    name: GPL-2
tags:
  - name: dishes
  - name: comments
  - name: leaders
  - name: promotions
  - name: feedback
  - name: features
servers:
  - url: 'http://localhost:3001'
    description: Development server
paths:
  /dishes:
    post:
      operationId: postDish
      tags:
        - dishes
      summary: Create a dish of the ristorante
      responses:
        '201':
          description: Created dish
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Dish'
          x-draig-test-fixture:
            body: >-
              {name: "Hindi Onion Soup", image: "images/hindisoup.png",
              category: "mains", featured: false, description: "Hindi onion soup
              with Tandori croutons"}
      requestBody:
        required: true
        description: Dish to be created
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Dish'
    get:
      operationId: getDishes
      tags:
        - dishes
      summary: Get all (or one) dish/es of the ristorante
      parameters:
        - name: id
          in: query
          description: Id of the dish you want to retrieve
          schema:
            type: integer
      responses:
        '200':
          description: Almost one dish is found (or more)
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Dish'
          x-draig-test-fixture:
            id: 1
        '404':
          description: No data was found. Check your criteria for typos
          x-draig-test-fixture:
            id: 9999
  /dishes/findByCat:
    get:
      operationId: findDishByCategory
      tags:
        - dishes
      summary: Get dishes by categories
      parameters:
        - name: category
          in: query
          description: Category values that need to be considered for filter
          required: true
          schema:
            type: array
            items:
              type: string
              enum:
                - mains
                - appetizer
                - dessert
      responses:
        '200':
          description: Dishes from category loaded
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Dish'
          x-draig-test-fixture:
            category: '["mains"]'
        '400':
          description: category not provided or invalid category
          x-draig-validation-fixture:
            inquery:
              category: '["non-existent"]'
  '/dishes/{dishid}/comments':
    get:
      operationId: getDishComments
      tags:
        - comments
      summary: Get the comments of given dish
      parameters:
        - name: dishid
          in: path
          description: Id of the dish which related comments will be retrieved
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Comments of the dish with dishid are retrieved
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Comment'
          x-draig-test-fixture:
            dishid: 1
        '400':
          description: dishid is integer
          x-draig-validation-fixture:
            inpath:
              dishid: '"a"'
        '404':
          description: No data was found. Check your criteria for typos
          x-draig-test-fixture:
            dishid: 9999
  '/dishes/{id}':
    put:
      operationId: putDish
      tags:
        - dishes
      summary: Update dish data
      parameters:
        - name: id
          required: true
          in: path
          description: Id of the dish you want to partially update
          schema:
            type: integer
      requestBody:
        required: true
        description: Fields of the dish you wish to update
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Basedish'
      responses:
        '200':
          description: Updated dish
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Dish'
          x-draig-test-fixture:
            id: 1
            body: '{featured: true}'
        '400':
          description: id is integer
          x-draig-validation-fixture:
            inpath:
              id: '"a"'
            inbody: '{}'
        '404':
          description: No data found
          x-draig-test-fixture:
            id: 9999
            body: '{}'
      x-draig-model: Dish
  /comments:
    post:
      operationId: postComment
      tags:
        - comments
      summary: Create a comment of one dish from the ristorante
      responses:
        '201':
          description: Comment created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Comment'
          x-draig-test-fixture:
            body: '{ dishid:1, comment:"New comment", author:"Me" }'
        '400':
          description: invalid data or missing data provided
          x-draig-validation-fixture:
            inbody: '{}'
        '415':
          description: unsupported media type not_provided
          x-draig-validation-fixture:
            inbody: null
      requestBody:
        required: true
        description: Comment to be created
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Comment'
    get:
      operationId: getComments
      tags:
        - comments
      summary: Get all (or one) comment/s of the ristorante
      parameters:
        - name: id
          in: query
          description: Id of the comment to be retrieved
          schema:
            type: integer
      responses:
        '200':
          description: almost one comment (or more) retrieved
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Comment'
          x-draig-test-fixture:
            id: 1
        '404':
          description: No data was found. Check your criteria for typos
          x-draig-test-fixture:
            id: 9999
  '/comments/{id}':
    delete:
      operationId: delete
      tags:
        - comments
      summary: Delete one comment (for moderation?)
      x-draig-model: Comment
      parameters:
        - name: id
          in: path
          description: Id of the comment to be deleted
          required: true
          schema:
            type: integer
      responses:
        '204':
          description: Comment deleted
          x-draig-test-fixture:
            id: 2
        '404':
          description: No data found
          x-draig-test-fixture:
            id: 9999
  /leaders:
    post:
      operationId: postLeader
      tags:
        - leaders
      summary: Create a leader of the organization
      responses:
        '201':
          description: Leader created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Leader'
      requestBody:
        required: true
        description: Leader to be created
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Leader'
    get:
      operationId: getLeaders
      tags:
        - leaders
      summary: Get all leaders of the ristorante
      parameters:
        - name: id
          in: query
          description: Id of the leader to retrieve
          schema:
            type: integer
        - name: abbr
          in: query
          description: Abbr of the leader to retrieve
          schema:
            type: string
      responses:
        '200':
          description: leaders retrieved
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Leader'
        '404':
          description: No data was found. Check your criteria for typos
  '/leaders/{id}':
    put:
      operationId: putLeaders
      tags:
        - leaders
      summary: Update a leader information (typographic or other error?) by its id
      parameters:
        - name: id
          in: path
          required: true
          description: Id of the leader to modify
          schema:
            type: integer
      requestBody:
        required: true
        description: Data of the leader you wish to update
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Baseleader'
      responses:
        '200':
          description: Leader updated
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Leader'
        '404':
          description: No data was found. Check your criteria for typos
      x-draig-model: Leader
  /promotions:
    post:
      operationId: postPromotion
      tags:
        - promotions
      summary: Create a promotion of the Ristorante Con Fusion
      responses:
        '201':
          description: Promotion created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Promotion'
      requestBody:
        required: true
        description: Promotion to be created
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Promotion'
    get:
      operationId: getPromotions
      tags:
        - promotions
      summary: Get all promotions of the ristorante
      responses:
        '200':
          description: promotions loaded
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Promotion'
        '404':
          description: No data was found. Check your criteria for typos
  '/promotions/{id}':
    put:
      operationId: putPromotions
      tags:
        - promotions
      summary: Update a promotion (typographic or other error?) by its id
      parameters:
        - name: id
          in: path
          required: true
          description: Id of the promotion to modify
          schema:
            type: integer
      requestBody:
        required: true
        description: Promotion data to be updated
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Basepromotion'
      responses:
        '200':
          description: Promotion updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Promotion'
          x-draig-test-fixture:
            id: 1
            body: '{featured: false}'
        '404':
          description: No data was found. Check your criteria for typos
          x-draig-test-fixture:
            id: 9999
            body: '{featured: false}'
      x-draig-model: Promotion
  /feedback:
    post:
      operationId: postFeedback
      tags:
        - feedback
      summary: Create a feedback entry for the web site
      responses:
        '201':
          description: Feedback entry created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Feedback'
      requestBody:
        required: true
        description: Feedback entry to be created
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Feedback'
    get:
      operationId: getFeedback
      tags:
        - feedback
      summary: Get all feedback of the ristorante
      responses:
        '200':
          description: feedback loaded
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Feedback'
        '404':
          description: No data was found. Check your criteria for typos
  /features/starred:
    get:
      operationId: getStarred
      tags:
        - features
      summary: Get starred dish ranking based on users comment
      responses:
        '200':
          description: 'Ranking of dishes, ordered full query of the starred view'
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Starred'
        '404':
          description: No data was found. Check your criteria for typos
  /features/featured:
    get:
      operationId: getFeatured
      tags:
        - features
      summary: 'Get featured dishes, promotions and leaders in one call'
      x-draig-query: >-
        knex("dishes").select(knex.ref(knex.raw("'dish'")).as("object"), "name",
        "description", "image").where("featured",
        true).unionAll(knex("promotions").select(knex.raw("'promotion'"),
        "name", "description", "image").where("featured", true),
        knex("leaders").select(knex.raw("'leader'"), "name", "description",
        "image").where("featured", true))
      responses:
        '200':
          description: All three featured excerpts are found
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Featured'
        '404':
          description: No data was found. Check your criteria for typos
components:
  schemas:
    Starred:
      x-draig-tableName: starred
      x-draig-sch-raw:
        create: >-
          create view starred as select dishid, avg(rating) as avgrating,
          count(*) as comments from comments group by dishid order by 2 desc
        drop: drop view starred
        oracledb:
          create: >-
            create view "starred" as select "dishid", avg("rating") as
            "avgrating", count(*) as "comments" from "comments" group by
            "dishid" order by 2 desc
          drop: drop view "starred"
      type: object
      properties:
        dishid:
          type: integer
        avgrating:
          type: number
        comments:
          type: integer
    Featured:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
          description: 'Name of the dish, promotion or leader'
        description:
          type: string
        image:
          type: string
    Autoincrement:
      type: object
      properties:
        id:
          x-draig-sch-type-autokey: true
          description: Id generated and returned by the system - send 0 or ignore
          type: integer
    Basedish:
      description: 'Restaurant''s dish, updatable fields'
      type: object
      properties:
        name:
          type: string
          maxLength: 40
          description: Name of the dish
        image:
          type: string
          maxLength: 1024
          description: Image associated with the dish
        category:
          type: string
          description: Category of the dish for the menu
          enum:
            - mains
            - appetizer
            - dessert
        label:
          type: string
          maxLength: 20
          description: Marketing hint and convenience label
        price:
          type: string
          maxLength: 9
          description: Price as advertised
        featured:
          type: boolean
          description: 'If true, it will be shown in the home page'
          default: false
        description:
          type: string
    Dish:
      description: 'Restaurant dish, as stored in the database'
      x-draig-tableName: dishes
      required:
        - name
        - image
        - category
        - featured
        - description
      allOf:
        - $ref: '#/components/schemas/Autoincrement'
        - $ref: '#/components/schemas/Basedish'
    Comment:
      x-draig-tableName: comments
      type: object
      required:
        - dishid
        - comment
        - author
      properties:
        id:
          x-draig-sch-type-autokey: true
          type: integer
        dishid:
          type: integer
        rating:
          type: integer
          default: 5
        comment:
          type: string
        author:
          type: string
          maxLength: 120
        date:
          type: string
          format: date-time
          x-draig-sch-type-default: knex.fn.now()
    Basepromotion:
      type: object
      properties:
        name:
          type: string
          maxLength: 120
        image:
          type: string
          maxLength: 1024
        label:
          type: string
          maxLength: 20
        price:
          type: string
          maxLength: 9
        featured:
          type: boolean
          default: false
        description:
          type: string
    Promotion:
      x-draig-tableName: promotions
      required:
        - name
        - image
        - featured
        - description
      allOf:
        - $ref: '#/components/schemas/Autoincrement'
        - $ref: '#/components/schemas/Basepromotion'
    Baseleader:
      type: object
      properties:
        name:
          type: string
          maxLength: 120
        image:
          type: string
          maxLength: 1024
        designation:
          type: string
          maxLength: 40
          default: '"ConFusion Leader"'
        abbr:
          type: string
          maxLength: 4
        featured:
          type: boolean
          default: false
        description:
          type: string
    Leader:
      x-draig-tableName: leaders
      required:
        - name
        - designation
        - featured
        - description
      allOf:
        - $ref: '#/components/schemas/Autoincrement'
        - $ref: '#/components/schemas/Baseleader'
    Feedback:
      x-draig-tableName: feedback
      type: object
      required:
        - firstname
        - lastname
        - email
        - message
      properties:
        id:
          x-draig-sch-type-autokey: true
          type: integer
        firstname:
          type: string
          maxLength: 40
        lastname:
          type: string
          maxLength: 40
        telnum:
          type: string
          maxLength: 20
          default: '''Unspecified'''
        email:
          type: string
          maxLength: 320
          format: email
        agree:
          type: boolean
          default: true
        contactType:
          type: string
          enum:
            - Email
            - Tel.
          default: '''Email'''
        message:
          type: string
          maxLength: 1024
        date:
          type: string
          format: date-time
          x-draig-sch-type-default: knex.fn.now()
