openapi: 3.0.3

info:
  version: 0.1.0
  title: CF Online
  description: CF Online
  license:
    name: Artistic License 2.0
    url: https://www.perlfoundation.org/artistic-license-20.html
  contact:
    name: Andrej Ramašeuski
    email: andrej.ramaseuski@pirati.cz
    url: https://pardubicky.pirati.cz/lide/andrej-ramaseuski/

servers:
    - url: http://127.0.0.1:3000/api
      description: Developement server
    - url: https://cf2021.pirati.cz/api
      description: Production server

components:
  securitySchemes:
    Bearer:
     name: Authorization
     in: header
     type: apiKey
  parameters:
    offset:
      name: offset
      in: query
      description: The number of items to skip before starting to collect the result set
      required: false
      schema:
        type: integer
        default: 0
        minimum: 0
    limit:
      name: limit
      in: query
      description: The numbers of items to return
      required: false
      schema:
        type: integer
        default: 100
        minimum: 1
  schemas:
    ConfigEntry:
      type: object
      properties:
        id:
          type: string
          readOnly: true
        is_readonly:
          type: boolean
          readOnly: true
        value:
          type: string
    ProgramScheduleEntry:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        number:
          type: string
          nullable: true
        is_live:
          type: boolean
        discussion_opened:
          type: boolean
        title:
          type: string
        proposer:
          type: string
          nullable: true
        description:
          type: string
          nullable: true
        expected_start_at:
          type: string
        expected_finish_at:
          type: string
          nullable: true
    Ranking:
      type: object
      properties:
        score:
          type: integer
        likes:
          type: integer
        dislikes:
          type: integer
        my_vote:
          type: integer
    PostHistoryItem:
      type: object
      properties:
        attribute:
          type: string
        value:
          type: string
        datetime:
          type: string
        originator:
          type: string
    User:
      type: object
      properties:
        id:
            type: integer
        name:
            type: string
        group:
            type: string
        username:
            type: string
        secret:
            type: string
        is_banned:
            type: boolean
    Announcement:
      type: object
      description: Notifikace
      properties:
        id:
          type: integer
          readOnly: true
        datetime:
          type: string
          readOnly: true
        type:
          type: integer
          enum: [0, 1, 2, 3, 4, 5]
        content:
          type: string
        link:
          type: string
        related_post_id:
          type: integer
    Post:
      type: object
      description: Prispevek
      properties:
        id:
          type: integer
          readOnly: true
        datetime:
          type: string
        type:
          type: integer
          enum: [0, 1]
        state:
          type: integer
          enum: [0, 1, 2, 3, 4]
        content:
          type: string
        is_changed:
          type: boolean
        is_archived:
          type: boolean
        author:
            $ref: '#/components/schemas/User'
        ranking:
            $ref: '#/components/schemas/Ranking'
        history_log:
           type: array
           items:
              $ref: '#/components/schemas/PostHistoryItem'

paths:
  /config:
    get:
      x-mojo-to: config#entries
      tags:
        - config
      summary: "Konfigurace systemu"
      operationId: getConfig
      responses:
        200:
          description: Konfigurace systemu
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ConfigEntry'
  /config/{id}:
    put:
      x-mojo-to: config#update
      security:
        - Bearer: ['chairman']
      tags:
        - config
      summary: "Upravit polozku konfigu"
      operationId: updateConfigEntry
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ConfigEntry'
      responses:
        204:
          description: Program entry updated

  /program:
    get:
      x-mojo-to: program#entries
      tags:
        - programm
      summary: "Program zasedani"
      operationId: getProgram
      responses:
        200:
          description: Program zasedani
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ProgramScheduleEntry'

  /program/{id}:
    put:
      x-mojo-to: program#update
      security:
        - Bearer: ['chairman']
      tags:
        - programm
      summary: "Upravit bod programu"
      operationId: updateProgramEntry
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProgramScheduleEntry'
      responses:
        204:
          description: Program entry updated

  /announcements:
    post:
      x-mojo-to: announcements#create
      security:
        - Bearer: ['chairman']
      tags:
        - announcements
      summary: "Pridat notifikaci"
      operationId: createAnnouncement
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                type:
                  type: integer
                  enum: [3, 4]
                content:
                  type: string
                link:
                  type: string
              required:
                - content
      responses:
        201:
          description: Announcement created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                    description: Announcement id
    get:
      x-mojo-to: announcements#list
      tags:
        - announcements
      summary: "Seznam notifikaci"
      operationId: getAnnouncements
      parameters:
      - $ref: '#/components/parameters/offset'
      - $ref: '#/components/parameters/limit'
      - name: sort
        description: "Razeni"
        in: query
        style: form
        schema:
          type: array
          uniqueItems: true
          items:
            type: string
            enum: [ datetime, -datetime]
          default: [ -datetime ]
      responses:
        200:
          description: Seznam motifikaci
          content:
            application/json:
              schema:
                type: object
                properties:
                  count:
                    type: integer
                    description: Celkovy pocet
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Announcement'

  /announcements/{id}:
    put:
      x-mojo-to: announcements#update
      security:
        - Bearer: ['chairman']
      tags:
        - announcements
      summary: "Upravit notifikaci"
      operationId: updateAnnouncement
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Announcement'
      responses:
        204:
          description: Announcement updated
    delete:
      x-mojo-to: announcements#delete
      security:
        - Bearer: ['chairman']
      tags:
        - announcements
      summary: "Smazat notifikaci"
      operationId: deleteAnnouncement
      responses:
        204:
          description: Announcement deleted

  /posts:
    post:
      x-mojo-to: posts#create
      security:
        - Bearer: ['member', 'regp']
      tags:
        - posts
      summary: "Pridat zpravu"
      operationId: createPost
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                type:
                  type: integer
                  enum: [0, 1]
                content:
                  type: string
              required:
                - type
                - content
      responses:
        201:
          description: Post created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                    description: Post id
    get:
      x-mojo-to: posts#list
      security:
        - Bearer: ['optional', 'member', 'regp']
      tags:
        - posts
      summary: "Zpravy"
      operationId: getPosts
      parameters:
      - $ref: '#/components/parameters/offset'
      - $ref: '#/components/parameters/limit'
      - name: type
        in: query
        description: "Typ zpravy"
        required: false
        schema:
          type: integer
          enum: [0, 1]
      - name: program_entry_id
        in: query
        description: "Identifikator bodu programu"
        required: false
        schema:
          type: integer
      - name: archived
        in: query
        description: "Zobrazovat archivovane"
        required: false
        schema:
          type: boolean
      - name: sort
        description: "Razeni"
        in: query
        style: form
        schema:
          type: array
          uniqueItems: true
          items:
            type: string
            enum: [ type, datetime, -type, -datetime]
          default: [ -datetime ]
      responses:
        200:
          description: Posts
          content:
            application/json:
              schema:
                type: object
                properties:
                  count:
                    type: integer
                    description: Celkovy pocet
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Post'
  /posts/{id}:
    get:
      x-mojo-to: posts#get
      security:
        - Bearer: ['optional', 'member', 'regp']
      tags:
        - posts
      summary: "Detail zpravy"
      operationId: getPost
      responses:
        200:
          description: Post
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/Post'
    put:
      x-mojo-to: posts#update
      security:
        - Bearer: ['member', 'regp']
      tags:
        - posts
      summary: "Uprava zpravu"
      operationId: updatePost
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                state:
                  type: integer
                  enum: [0, 1, 2, 3, 4]
                content:
                  type: string
                isr_archived:
                  type: boolean
      responses:
        204:
          description: Post updated

    delete:
      x-mojo-to: posts#delete
      security:
        - Bearer: ['chairman']
      tags:
        - posts
      summary: "Smazat zpravu"
      operationId: deletePost
      responses:
        204:
          description: Post deleted

  /posts/{id}/like:
    patch:
      security:
        - Bearer: ['member', 'regp']
      x-mojo-to: posts#ranking
      tags:
        - posts
      summary: "Like"
      operationId: likePost
      parameters:
      - name: ranking
        in: query
        required: false
        schema:
          type: integer
          enum: [1]
          default: 1
      responses:
        204:
          description: Post liked

  /posts/{id}/dislike:
    patch:
      security:
        - Bearer: ['member', 'regp']
      x-mojo-to: posts#ranking
      tags:
        - posts
      summary: "Like"
      operationId: dislikePost
      parameters:
      - name: ranking
        in: query
        required: false
        schema:
          type: integer
          enum: [-1]
          default: -1
      responses:
        204:
          description: Post disliked

  /users/me:
    get:
      x-mojo-to: users#me
      security:
        - Bearer: []
      tags:
        - users
      summary: "Detail uzivatele"
      operationId: getCurrentUser
      responses:
        200:
          description: User
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/User'

  /users/{id}/ban:
    patch:
      security:
        - Bearer: ['chairman']
      x-mojo-to: users#ban
      tags:
        - users
      summary: Ban user
      operationId: banUser
      responses:
        204:
          description: User banned

  /users/{id}/unban:
    patch:
      security:
        - Bearer: ['chairman']
      x-mojo-to: users#unban
      tags:
        - users
      summary: Unban user
      operationId: UnbanUser
      responses:
        204:
          description: User banned
