openapi: 3.0.3
info:
  title: cx-note-service
  version: v1
  description: Note service provides a set of operations to be performed to notes
  contact:
    email: cadi@carlsberggroup.com
    name: CADI Team
servers:
  - url: http://localhost:3000
    description: Notes API server url
security:
  - X-API-KEY: []
tags:
  - name: notes
    description: Notes Management API endpoints
  - name: reportingNotes
    description: Notes Reporting API endpoints
paths:
  /v2/notes:
    get:
      tags:
        - notes
      summary: Fetch Notes by id
      responses:
        '200':
          $ref: '#/components/responses/NotePage'
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      operationId: fetchNotes
      description: |-
        Retrieve pages of Notes for a specific outlet or prospect.

            Can occur the following errors:
            - NTE-001 - SalesOrg is not available
            - NTE-003 - Invalid parameter value
      parameters:
        - $ref: '#/components/parameters/outletId'
        - $ref: '#/components/parameters/salesOrgCode'
        - $ref: '#/components/parameters/prospectId'
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/size'
  /notes/housekeeping:
    get:
      tags:
        - notes
      summary: Notes Housekeeping
      responses:
        '204':
          description: No Content
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      operationId: housekeeping
      description: Delete notes that haven't been modified over the last years of data retention
  /notes:
    get:
      tags:
        - notes
      deprecated: true
      summary: List of fetched notes
      responses:
        '200':
          description: Notes list
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Note-v1'
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      operationId: fetchNotesOld
      parameters:
        - $ref: '#/components/parameters/outletId'
        - $ref: '#/components/parameters/salesOrgCode'
        - $ref: '#/components/parameters/prospectId'
      description: |-
        Retrieve a list of Notes for a specific outlet or prospect

            Can occour the following errors:
            - NTE-001 - SalesOrg is not available
            - NTE-003 - Invalid parameter value
    post:
      tags:
        - notes
      summary: Creates a Note
      responses:
        '201':
          $ref: '#/components/responses/Note'
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      operationId: createNote
      description: |-
        Creates a new note with the provided information.

            Can occour the following errors:
            - NTE-001 - SalesOrg is not available
            - NTE-002 - Mandatory fields not present on the request body
      requestBody:
        $ref: '#/components/requestBodies/Note'
    delete:
      tags:
        - notes
      summary: Remove a Note by id
      responses:
        '204':
          description: No Content
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      operationId: removeNotes
      parameters:
        - $ref: '#/components/parameters/outletId'
        - $ref: '#/components/parameters/salesOrgCode'
        - $ref: '#/components/parameters/prospectId'
      description: |-
        Deletes Notes with the provided information.

            Can occur the following errors:
            - NTE-001 - SalesOrg is not available
            - NTE-003 - Invalid parameter value
            - NTE-004 - Entity not found
  /notes/{noteEid}:
    get:
      tags:
        - notes
      summary: Retrieve a Note by id
      responses:
        '200':
          $ref: '#/components/responses/Note'
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      operationId: fetchNote
      description: |-
        Fetches a Note with the provided unique identifier.

            Can occur the following errors:
            - NTE-003 - Invalid parameter value
            - NTE-004 - Entity not found
    put:
      tags:
        - notes
      summary: Update Note by id
      responses:
        '200':
          $ref: '#/components/responses/Note'
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      operationId: updateNote
      description: |-
        Updates a Note with the provided information.

            Can occur the following errors:
            - NTE-001 - SalesOrg is not available
            - NTE-002 - Mandatory fields not present on the request body
            - NTE-003 - Invalid parameter value
            - NTE-004 - Entity not found
      requestBody:
        $ref: '#/components/requestBodies/Note'
    delete:
      tags:
        - notes
      summary: Remove Note by id
      responses:
        '204':
          description: No Content
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      operationId: removeNote
      description: |-
        Removes a Note with the provided unique identifier.

            Can occur the following errors:
            - NTE-003 - Invalid parameter value
            - NTE-004 - Entity not found
    parameters:
      - $ref: '#/components/parameters/noteEid'
  /notes/reporting:
    get:
      summary: Retrieve Notes for reporting
      operationId: reportOnNotes
      parameters:
        - $ref: '#/components/parameters/startDate'
        - $ref: '#/components/parameters/endDate'
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/size'
      responses:
        '200':
          $ref: '#/components/responses/NotePage'
        '400':
          $ref: '#/components/responses/BadRequestResponse'
      description: |
        Retrieve Pages of Notes for reporting purposes based on a date range.

            Can occur the following errors:
            - NTE-003 - Invalid parameter value
      tags:
        - reportingNotes
components:
  parameters:
    noteEid:
      description: This is a unique external identifier for a note
      name: noteEid
      in: path
      required: true
      schema:
        type: string
        format: uuid
        example: 61864654-6e6b-4152-a62f-795fdd606bc2
    salesOrgCode:
      name: salesOrgCode
      in: query
      schema:
        type: string
        example: A001
        minLength: 4
        maxLength: 5
        pattern: ^[A-Za-z0-9]*$
      description: Sales Organisation Code
      required: true
    outletId:
      name: outletId
      in: query
      required: false
      schema:
        type: string
        example: '1234567'
        minLength: 7
        maxLength: 7
        pattern: \d{7}
      description: The Outlet unique identifier
    prospectId:
      name: prospectId
      in: query
      schema:
        type: string
        example: f7ad5bbd-e2b1-4f8e-acb3-2ddd0b40952d
        minLength: 36
        maxLength: 36
        pattern: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
      description: The Prospect unique identifier
    page:
      name: page
      in: query
      required: false
      schema:
        type: integer
        default: 0
        format: int32
        example: 1
        minimum: 0
      description: The requested Page number
    size:
      name: size
      in: query
      required: false
      schema:
        type: integer
        default: 100
        format: int32
        example: 25
        minimum: 1
      description: The requested page size
    startDate:
      name: startDate
      in: query
      required: true
      schema:
        type: string
        format: date-time
        example: '2021-10-12 17:42:12'
      description: The requested start date
    endDate:
      name: endDate
      in: query
      required: true
      schema:
        type: string
        format: date-time
        example: '2021-10-12 17:42:12'
      description: The requested end date
  responses:
    BadRequestResponse:
      description: |-
        Error 400 response
        - NTE-001 - SalesOrg is not available
        - NTE-002 - Mandatory fields not present on the request body
        - NTE-003 - Invalid parameter value
        - NTE-004 - Entity not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error-v1'
          examples:
            Example 1:
              value:
                title: Bad Request
                status: 400
                detail: SalesOrg is not available
                errorCode: NTE-001
                errorMessage: SalesOrg is not available
                errorMetadata:
                  validationErrors:
                    - field: salesOrg
                      message: SalesOrg is not available
            Example 2:
              value:
                title: Bad Request
                status: 400
                detail: Mandatory fields not present on the request body
                errorCode: NTE-002
                errorMessage: Mandatory fields not present on the request body
                errorMetadata:
                  validationErrors:
                    - field: title
                      message: Note title is required
                    - field: salesOrgCode
                      message: salesOrgCode must be greater than 0
            Example 3:
              value:
                title: Bad Request
                status: 400
                detail: Invalid parameter value
                errorCode: NTE-003
                errorMessage: Invalid parameter value
                errorMetadata:
                  validationErrors:
                    - field: noteId
                      message: noteId is required
            Example 4:
              value:
                title: Bad Request
                status: 400
                detail: Entity not found
                errorCode: NTE-004
                errorMessage: Entity not found
                errorMetadata: {}
    NotePage:
      description: Pages containing notes and all pagination details
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NotePage-v1'
          examples:
            Example 1:
              value:
                content:
                  - eid: 110c9a31-71d6-4b55-b88c-65a39248043a
                    title: Note title
                    content: This is a note
                    creationDateTime: '2019-08-24T14:15:22Z'
                    lastUpdateDateTime: '2019-08-24T14:15:22Z'
                    outletId: '1723681'
                    prospectId: f7ad5bbd-e2b1-4f8e-acb3-2ddd0b40952d
                    salesOrgCode: A001
                    userIdEmail: user@email.com
                    createdAt: '2019-08-24T14:15:22Z'
                    createdBy: user@email.com
                    modifiedAt: '2019-08-24T14:15:22Z'
                    modifiedBy: user@email.com
                    createdByApp: CADI
                    modifiedByApp: CADI
                    deletedAt: '2019-08-24T14:15:22Z'
                pagination:
                  page: 0
                  totalPages: 5
                  totalElements: 50
                  numberOfElements: 10
                  size: 10
    Note:
      description: Note example response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Note-v1'
          examples:
            Example 1:
              value:
                eid: 110c9a31-71d6-4b55-b88c-65a39248043a
                title: Note title
                content: Note content
                creationDateTime: '2019-08-24T14:15:22Z'
                lastUpdateDateTime: '2019-08-24T14:15:22Z'
                outletId: '1234234'
                prospectId: f7ad5bbd-e2b1-4f8e-acb3-2ddd0b40952d
                salesOrgCode: A001
                userIdEmail: user@email.com
                createdAt: '2019-08-24T14:15:22Z'
                createdBy: user@email.com
                modifiedAt: '2019-08-24T14:15:22Z'
                modifiedBy: user@email.com
                createdByApp: CADI
                modifiedByApp: CADI
                deletedAt: '2019-08-24T14:15:22Z'
  securitySchemes:
    X-API-KEY:
      type: apiKey
      in: header
      name: X-API-KEY
      description: basic auth that resolves the application
  schemas:
    NotePage-v1:
      title: notePage-v1
      x-stoplight:
        id: dnt7o2qjc00s3
      type: object
      description: Represents Pages of Notes
      example:
        content:
          - eid: 110c9a31-71d6-4b55-b88c-65a39248043a
            title: Note title
            content: This is a note
            creationDateTime: '2019-08-24T14:15:22Z'
            lastUpdateDateTime: '2019-08-24T14:15:22Z'
            outletId: '1723681'
            prospectId: f7ad5bbd-e2b1-4f8e-acb3-2ddd0b40952d
            salesOrgCode: A001
            userIdEmail: user@email.com
            createdAt: '2019-08-24T14:15:22Z'
            createdBy: user@email.com
            modifiedAt: '2019-08-24T14:15:22Z'
            modifiedBy: user@email.com
            createdByApp: CADI
            modifiedByApp: CADI
            deletedAt: '2019-08-24T14:15:22Z'
        pagination:
          page: 0
          totalPages: 5
          totalElements: 50
          numberOfElements: 10
          size: 10
      properties:
        content:
          type: array
          x-stoplight:
            id: wudjdldqsfcu2
          items:
            $ref: '#/components/schemas/Note-v1'
          example:
            - eid: 110c9a31-71d6-4b55-b88c-65a39248043a
              title: Note title
              content: Note content
              creationDateTime: '2019-08-24T14:15:22Z'
              lastUpdateDateTime: '2019-08-24T14:15:22Z'
              outletId: '1234234'
              prospectId: f7ad5bbd-e2b1-4f8e-acb3-2ddd0b40952d
              salesOrgCode: A001
              userIdEmail: user@email.com
              createdAt: '2019-08-24T14:15:22Z'
              createdBy: user@email.com
              modifiedAt: '2019-08-24T14:15:22Z'
              modifiedBy: user@email.com
              createdByApp: CADI
              modifiedByApp: CADI
              deletedAt: '2019-08-24T14:15:22Z'
        pagination:
          $ref: '#/components/schemas/Pagination-v1'
    Note-v1:
      title: Note-v1
      x-stoplight:
        id: zn75q5qzm0wak
      type: object
      example:
        eid: 110c9a31-71d6-4b55-b88c-65a39248043a
        title: Note title
        content: Note content
        creationDateTime: '2019-08-24T14:15:22Z'
        lastUpdateDateTime: '2019-08-24T14:15:22Z'
        outletId: '1234234'
        prospectId: f7ad5bbd-e2b1-4f8e-acb3-2ddd0b40952d
        salesOrgCode: A001
        userIdEmail: user@email.com
        createdAt: '2019-08-24T14:15:22Z'
        createdBy: user@email.com
        modifiedAt: '2019-08-24T14:15:22Z'
        modifiedBy: user@email.com
        createdByApp: CADI
        modifiedByApp: CADI
        deletedAt: '2019-08-24T14:15:22Z'
      description: Represents a Note model
      properties:
        eid:
          type: string
          format: uuid
          description: Unique external id
          example: 110c9a31-71d6-4b55-b88c-65a39248043a
          x-stoplight:
            id: 233nbgr2vtfbo
        title:
          type: string
          minLength: 1
          maxLength: 255
          description: The note title
          example: Note title
          x-stoplight:
            id: qrf6jcbfqle0p
        content:
          type: string
          maxLength: 2500
          description: The note content with whatever text
          example: Note content
          x-stoplight:
            id: 2yy95u1lhginb
        creationDateTime:
          type: string
          format: date-time
          description: The creation date for the note
          example: '2019-08-24T14:15:22Z'
          x-stoplight:
            id: stieomsoi7iss
        lastUpdateDateTime:
          type: string
          format: date-time
          example: '2019-08-24T14:15:22Z'
          description: The last time the note was updated
          x-stoplight:
            id: xb34kqjzyt9vf
        outletId:
          type: string
          description: The outlet ID associated to this note
          example: '1234234'
          x-stoplight:
            id: gwywa1c2yfiad
        prospectId:
          type: string
          description: The prospect ID associated to this note
          example: f7ad5bbd-e2b1-4f8e-acb3-2ddd0b40952d
          x-stoplight:
            id: kvslxp36l3gk1
          maxLength: 36
          minLength: 36
        salesOrgCode:
          type: string
          description: User's sales organization code
          example: A001
          x-stoplight:
            id: 7e9texggif7z8
        userIdEmail:
          type: string
          minLength: 1
          description: User's mail who created this note
          example: user@email.com
          x-stoplight:
            id: 20bz1n2s8d0fh
        createdAt:
          type: string
          format: date-time
          example: '2019-08-24T14:15:22Z'
          description: Creation date of this note
          x-stoplight:
            id: polf9dvg75964
        createdBy:
          type: string
          minLength: 1
          description: User who created this note object
          example: user@email.com
          x-stoplight:
            id: vajqk8ohew29j
        modifiedAt:
          type: string
          format: date-time
          example: '2019-08-24T14:15:22Z'
          description: Date and time of which this note object was modified
          x-stoplight:
            id: q4qxh6ftn2r81
        modifiedBy:
          type: string
          minLength: 1
          description: User who modified this note object
          example: user@email.com
          x-stoplight:
            id: x6ukfd990rk4x
        createdByApp:
          type: string
          minLength: 1
          description: Application which created this note
          example: CADI
          x-stoplight:
            id: b12j9kd9ubhzh
        modifiedByApp:
          type: string
          minLength: 1
          description: Application which modified this note
          example: CADI
          x-stoplight:
            id: 6q3r9czd57m8a
        deletedAt:
          type: string
          format: date-time
          example: '2019-08-24T14:15:22Z'
          description: Date and time of which this note was deleted REMOVE AFTER MIGRATION
          x-stoplight:
            id: beifqn07nwyq0
      required:
        - eid
        - title
        - salesOrgCode
        - userIdEmail
        - createdBy
        - modifiedBy
        - createdByApp
        - modifiedByApp
    Error-v1:
      title: Error-v1
      x-stoplight:
        id: jbjg8y4fvu0bm
      type: object
      properties:
        title:
          type: string
          description: A short summary of the problem type. Written in English and readable for engineers, usually not suited for non technical stakeholders and not localized.
          example: Bad Request
          x-stoplight:
            id: o85lbp8un33b2
        status:
          type: integer
          format: int32
          description: The HTTP status code generated by the origin server for this occurrence of the problem.
          minimum: 100
          example: 400
          x-stoplight:
            id: be7apog2kn31z
        detail:
          type: string
          description: A human readable explanation specific to this occurrence of the problem that is helpful to locate the problem and give advice on how to proceed. Written in English and readable for engineers, usually not suited for non technical stakeholders and not localized.
          example: Invalid place order request
          x-stoplight:
            id: tj3y1rvk4rpqn
        errorCode:
          type: string
          description: The error code of this problem
          example: ORD-001
          x-stoplight:
            id: qwpqg1r77ew6k
        errorMessage:
          type: string
          description: Brief message about the error. It is usually key message beside errorCode for client to identify the problem.
          example: Invalid input parameters for order
          x-stoplight:
            id: afoj3z5cu5a93
        errorMetadata:
          type: object
          description: Specific metadata for the error code
          example:
            validationErrors:
              - field: beerType
                message: Beer type is required
              - field: quantity
                message: Quantity must be greater than 0
              - field: deliveryDate
                message: Delivery date is required
          x-stoplight:
            id: 81rtycwl3m728
      required:
        - title
        - status
        - detail
        - errorCode
      description: Represents a standardized format for describing errors in an API
    Pagination-v1:
      title: Pagination-v1
      x-stoplight:
        id: bqvn0a658hwmv
      type: object
      description: Pagination metadata for page method
      example:
        page: 0
        totalPages: 5
        totalElements: 50
        numberOfElements: 10
        size: 10
      properties:
        page:
          type: integer
          description: The current page number of the information in the response
          minimum: 0
          example: 1
          x-stoplight:
            id: n42wd8ff97km1
          format: int32
        totalPages:
          type: integer
          description: The total number of pages containing the requested information
          minimum: 1
          example: 5
          x-stoplight:
            id: jkkq6ufhkvxw2
          format: int32
        totalElements:
          type: integer
          description: The total number of elements containing the requested information
          minimum: 0
          example: 50
          x-stoplight:
            id: gy0smgiq1xp0z
          format: int32
        numberOfElements:
          type: integer
          description: The number of elements containing the requested information displayed in the current response page
          minimum: 0
          example: 10
          x-stoplight:
            id: m63fzaximn081
          format: int32
        size:
          type: integer
          description: The size (number of elements) displayed per page
          minimum: 1
          example: 10
          x-stoplight:
            id: lbctyk11wujn4
          format: int32
  requestBodies:
    Note:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Note-v1'
      description: Note Body Model
  examples: {}
