openapi: "3.0.0"
info:
  version: 0.0.1-20210926
  title: SIL ERP BACK
  description: Interface API between the SIL ERP services and the BACK component.
#  termsOfService: https://git.unistra.fr/erp-sil/back
  contact:
    name: Antoine Beauvais
    email: antoine.beauvais@etu.unistra.fr
    url: https://git.unistra.fr/antoine.beauvais
  license:
    name: CeCILL-B
    url: https://cecill.info/licences/Licence_CeCILL-B_V1-en.html
paths:
  /product:
    get:
      description: |
        Returns the list of all available items.
        
        It is also possible to filter items by category.
      operationId: retrieveItems
      parameters:
        - name: category
          in: query
          description: category ID to filter results by
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: List of items.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Item'
        '204':
          description: No Content (no items in the given category)
        '400':
          description: Bad Request (invalid category parameter)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
  /category:
    get:
      description: |
        Returns the list of all existing categories.
      operationId: retrieveCategories
      responses:
        '200':
          description: List of categories.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Category'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
  /stock:
    get:
      description: |
        Returns the stocks for each item (their quantity).
      operationId: retrieveStocks
      responses:
        '200':
          description: List of stock entries.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Stock'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
  /transaction:
    post:
      description: Submits a new transaction into the system.
      operationId: submitTransaction
      requestBody:
        description: Transaction to process.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Transaction'
      responses:
        '201':
          description: Created transaction.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Transaction'
        '400':
          description: Bad Request (invalid JSON)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
components:
  schemas:
    Category:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          example: 1
        name:
          type: string
          example: "Boissons"
    Item:
      type: object
      required:
        - id
        - name
        - price
        - subscriberPrice
      properties:
        id:
          type: integer
          example: 1
        name:
          type: string
          example: "Jus d'orange"
        price:
          type: number
          example: 1.5
        subscriberPrice:
          type: number
          example: 0.8
    Stock:
      type: object
      required:
        - id
        - itemId
        - itemName
        - quantity
      properties:
        id:
          type: integer
          example: 1
        itemId:
          type: integer
          example: 1
        itemName:
          type: string
          example: "Jus d'orange"
        quantity:
          type: integer
          example: 25
    Transaction:
      type: object
      required:
        - item
        - type
        - quantity
      properties:
        item:
          type: integer
          example: 1
        type:
          type: integer
          description: ACHAT, REGLEMENT, VENTE, ENCAISSEMENT
          enum: [1, 2, 3, 4]
          example: 1
        quantity:
          type: integer
          example: 5
    ErrorMessage:
      type: object
      required:
        - message
      properties:
        message:
          type: string
          example: "Database failure."