openapi: 3.0.1
info:
  title: Perk Store Rest Api
  description: Perk Store addon rest endpoints
  license:
    name: LGPL
    url: https://www.gnu.org/licenses/lgpl-3.0.en.html
  version: "1.0"
tags:
- name: /perkstore/api/order
  description: Manages perk store product orders
- name: /perkstore/api/product
  description: Manages perk store products
- name: /perkstore/api/settings
  description: Manages perk store application settings
paths:
  /perkstore/api/order/list:
    post:
      tags:
      - /perkstore/api/order
      summary: Retrieves the list of orders for current user using a filter
      description: Retrieves the list of orders for current user using a filter
      operationId: listOrders
      requestBody:
        description: OrderFilter object with search conditions
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderFilter'
        required: true
      responses:
        "200":
          description: Request fulfilled
        "400":
          description: Invalid query input
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/order/save:
    post:
      tags:
      - /perkstore/api/order
      summary: Creates a new order for current user on a selected product
      description: Creates a new order for current user on a selected product
      operationId: createOrder
      requestBody:
        description: ProductOrder object
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProductOrder'
        required: true
      responses:
        "200":
          description: Request fulfilled
        "400":
          description: Invalid query input
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/order/saveSimulate:
    post:
      tags:
      - /perkstore/api/order
      summary: Check that order can be saved with given attributes
      description: Check that order can be saved with given attributes
      operationId: saveOrderSimulate
      requestBody:
        description: ProductOrder object
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProductOrder'
        required: true
      responses:
        "204":
          description: Request fulfilled
        "400":
          description: Invalid query input
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/order/saveStatus:
    post:
      tags:
      - /perkstore/api/order
      summary: Modifies an existing order by specifying the type of modification
      description: Modifies an existing order by specifying the type of modification
        (order attribute to change)
      operationId: saveOrder
      parameters:
      - name: modificationType
        in: query
        description: ProductOrderModificationType enum name
        required: true
        schema:
          type: string
      requestBody:
        description: ProductOrder object
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProductOrder'
        required: true
      responses:
        "200":
          description: Request fulfilled
        "400":
          description: Invalid query input
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/product:
    get:
      tags:
      - /perkstore/api/product
      summary: Get the list of product accessible by current user
      description: returns list of products
      operationId: listProducts
      parameters:
      - name: available
        in: query
        description: Returning only the available products or all products
        schema:
          type: boolean
          default: false
      - name: returnSize
        in: query
        description: Returning the number of Products or not
        schema:
          type: boolean
          default: false
      responses:
        "200":
          description: Request fulfilled
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
    post:
      tags:
      - /perkstore/api/product
      summary: Creates or modifies a product
      description: Creates or modifies a product and returns the saved product
      operationId: saveProduct
      requestBody:
        description: Product object
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Product'
        required: true
      responses:
        "200":
          description: Request fulfilled
        "400":
          description: Invalid query input
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/product/delete/{productId}:
    put:
      tags:
      - /perkstore/api/product
      summary: Retrieves a product by its id
      description: returns selected product if exists
      operationId: deleteProduct
      parameters:
      - name: productId
        in: path
        description: Product technical id
        required: true
        schema:
          type: integer
          format: int64
      responses:
        "200":
          description: Request fulfilled
        "400":
          description: Invalid query input
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/product/{productId}:
    get:
      tags:
      - /perkstore/api/product
      summary: Retrieves a product by its id
      description: Retrieves a product by its id and returns the selected product
        if exists
      operationId: getProduct
      parameters:
      - name: productId
        in: path
        description: Product technical id
        required: true
        schema:
          type: integer
          format: int64
      responses:
        "200":
          description: Request fulfilled
        "400":
          description: Invalid query input
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/product/{productId}/image/{imageId}:
    get:
      tags:
      - /perkstore/api/product
      summary: Get product image by its id
      description: returns image content of a product by its id
      operationId: getProductImage
      parameters:
      - name: productId
        in: path
        description: Product technical id
        required: true
        schema:
          type: integer
          format: int64
      - name: imageId
        in: path
        description: Image file technical id
        required: true
        schema:
          type: integer
          format: int64
      responses:
        "200":
          description: Request fulfilled
        "304":
          description: Image not modified
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/settings:
    get:
      tags:
      - /perkstore/api/settings
      summary: Retrieves perk store settings with user settings
      description: returns global having user settings object
      operationId: getSettings
      responses:
        "200":
          description: Request fulfilled
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
  /perkstore/api/settings/save:
    post:
      tags:
      - /perkstore/api/settings
      summary: Saves perk store global settings
      description: Saves perk store global settings and returns an empty response
      operationId: saveSettings
      requestBody:
        description: Global settings to save
        content:
          '*/*':
            schema:
              $ref: '#/components/schemas/GlobalSettings'
        required: true
      responses:
        "204":
          description: Request fulfilled
        "400":
          description: Invalid query input
        "403":
          description: Unauthorized operation
        "500":
          description: Internal server error
components:
  schemas:
    FileDetail:
      type: object
      properties:
        data:
          type: array
          items:
            type: string
            format: byte
        id:
          type: integer
          format: int64
        lastUpdated:
          type: integer
          format: int64
        name:
          type: string
        size:
          type: integer
          format: int64
        src:
          type: string
        uploadId:
          type: string
    GlobalSettings:
      type: object
      properties:
        accessPermissions:
          type: array
          items:
            type: integer
            format: int64
        accessPermissionsProfiles:
          type: array
          items:
            $ref: '#/components/schemas/Profile'
        managers:
          type: array
          items:
            type: integer
            format: int64
        managersProfiles:
          type: array
          items:
            $ref: '#/components/schemas/Profile'
        productCreationPermissions:
          type: array
          items:
            type: integer
            format: int64
        productCreationPermissionsProfiles:
          type: array
          items:
            $ref: '#/components/schemas/Profile'
        symbol:
          type: string
        userSettings:
          $ref: '#/components/schemas/UserSettings'
    OrderFilter:
      type: object
      properties:
        canceled:
          type: boolean
        delivered:
          type: boolean
        error:
          type: boolean
        fraud:
          type: boolean
        limit:
          type: integer
          format: int32
        notProcessed:
          type: boolean
        ordered:
          type: boolean
        ordersType:
          type: string
          enum:
          - ALL
          - SENT
          - RECEIVED
        paid:
          type: boolean
        partial:
          type: boolean
        productId:
          type: integer
          format: int64
        refunded:
          type: boolean
        searchInDates:
          type: boolean
        selectedDate:
          type: integer
          format: int64
        selectedOrderId:
          type: integer
          format: int64
    Product:
      type: object
      properties:
        accessPermissions:
          type: array
          items:
            $ref: '#/components/schemas/Profile'
        allowFraction:
          type: boolean
        createdDate:
          type: integer
          format: int64
        creator:
          $ref: '#/components/schemas/Profile'
        deleted:
          type: boolean
        description:
          type: string
        enabled:
          type: boolean
        id:
          type: integer
          format: int64
        illustrationURL:
          type: string
        imageFiles:
          uniqueItems: true
          type: array
          items:
            $ref: '#/components/schemas/FileDetail'
        lastModifiedDate:
          type: integer
          format: int64
        lastModifier:
          $ref: '#/components/schemas/Profile'
        marchands:
          type: array
          items:
            $ref: '#/components/schemas/Profile'
        maxOrdersPerUser:
          type: number
          format: double
        notProcessedOrders:
          type: integer
          format: int64
        orderPeriodicity:
          type: string
        orderPeriodicityLabel:
          type: string
        price:
          type: number
          format: double
        purchased:
          type: number
          format: double
        receiverMarchand:
          $ref: '#/components/schemas/Profile'
        title:
          type: string
        totalSupply:
          type: number
          format: double
        unlimited:
          type: boolean
        userData:
          $ref: '#/components/schemas/UserProductData'
    ProductOrder:
      type: object
      properties:
        amount:
          type: number
          format: double
        createdDate:
          type: integer
          format: int64
        deliveredDate:
          type: integer
          format: int64
        deliveredQuantity:
          type: number
          format: double
        error:
          type: string
          enum:
          - GLOBAL_SETTINGS_ACCESS_DENIED
          - GLOBAL_SETTINGS_MODIFICATION_DENIED
          - PRODUCT_CREATION_DENIED
          - PRODUCT_MODIFICATION_DENIED
          - PRODUCT_NOT_EXISTS
          - ORDER_CREATION_DENIED
          - ORDER_CREATION_STATUS_DENIED
          - ORDER_CREATION_EMPTY_TX
          - ORDER_CREATION_EMPTY_QUANTITY
          - ORDER_CREATION_EMPTY_AMOUNT
          - ORDER_CREATION_EMPTY_RECEIVER
          - ORDER_CREATION_EMPTY_SENDER
          - ORDER_CREATION_QUANTITY_EXCEEDS_SUPPLY
          - ORDER_CREATION_QUANTITY_EXCEEDS_ALLOWED
          - ORDER_MODIFICATION_DENIED
          - ORDER_MODIFICATION_QUANTITY_INVALID_REMAINING
          - ORDER_NOT_EXISTS
          - ORDER_CREATION_EMPTY_PRODUCT
          - PRODUCT_IS_DISABLED
          - PRODUCT_ACCESS_DENIED
          - ORDER_ACCESS_DENIED
          - ORDER_FRAUD_NOT_TOKEN_TRANSACTION
          - ORDER_FRAUD_WRONG_TOKEN_TRANSFER_METHOD
          - ORDER_FRAUD_WRONG_AMOUNT
          - ORDER_FRAUD_WRONG_SENDER
          - ORDER_FRAUD_WRONG_RECEIVER
        id:
          type: integer
          format: int64
        productId:
          type: integer
          format: int64
        productTitle:
          type: string
        quantity:
          type: number
          format: double
        receiver:
          $ref: '#/components/schemas/Profile'
        refundTransactionHash:
          type: string
        refundTransactionStatus:
          type: string
        refundedAmount:
          type: number
          format: double
        refundedDate:
          type: integer
          format: int64
        refundedQuantity:
          type: number
          format: double
        remainingQuantityToProcess:
          type: number
          format: double
        sender:
          $ref: '#/components/schemas/Profile'
        status:
          type: string
        transactionHash:
          type: string
        transactionStatus:
          type: string
    Profile:
      type: object
      properties:
        displayName:
          type: string
        id:
          type: string
        spaceId:
          type: integer
          format: int64
        spaceURLId:
          type: string
        technicalId:
          type: integer
          format: int64
        type:
          type: string
    UserProductData:
      type: object
      properties:
        canEdit:
          type: boolean
        canOrder:
          type: boolean
        notProcessedOrders:
          type: number
          format: double
        purchasedInCurrentPeriod:
          type: number
          format: double
        totalPurchased:
          type: number
          format: double
        username:
          type: string
    UserSettings:
      type: object
      properties:
        administrator:
          type: boolean
        canAddProduct:
          type: boolean
        cometdChannel:
          type: string
        cometdContext:
          type: string
        cometdToken:
          type: string
