openapi: 3.0.0
info:
  title: intra API
  description: |
    Backend API for intra
    The API tries to follow the [Google API Design Guide](https://google.aip.dev/general)
    - to retrieve resources across multiple collections use `-`
      - /missions/-/accounts/{account} is an example for find all the missions a account is in
    - to shortcut the retrieval of information for the authenticated user use `me`
      - /accounts/me is an example for get your own account

    Exceptions are the following:
    - filter parameters only support '=' and '!='
  license:
    name: Apache-2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.txt
  version: '0.1'
  contact:
    name: API Support
    email: patrick@42heilbronn.de
servers:
  - url: /api/v1
tags:
  - name: account
    description: account
  - name: auth
    description: auth
  - name: diary
    description: diary
  - name: event
    description: event
  - name: mission
    description: mission
  - name: mission/account
    description: mission account
    x-displayName: mission account
  - name: mission/milestone
    description: mission milestone
    x-displayName: mission milestone
  - name: file
    description: file
paths:
  /accounts:
    get:
      tags:
        - account
      summary: Get all accounts
      description: |
        Pagination not supported for now!
        Returns a list of accounts.
        default page size 30.
        max page size 1000.
      operationId: getAccounts
      security:
        - jwtAuth:
            - account.read
        - jwtAuth:
            - account.admin
      parameters:
        - $ref: '#/components/parameters/page_size'
        - $ref: '#/components/parameters/page_token'
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                type: object
                properties:
                  accounts:
                    $ref: '#/components/schemas/getAccountsResponse'
                  next_page_token:
                    type: string
                required:
                  - accounts
                  - next_page_token
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '500':
          $ref: '#/components/responses/R500'
    put:
      tags:
        - account
      summary: Create or update an account from jwt
      operationId: putAccount
      security:
        - jwtAuth:
            - user
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/account'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '500':
          $ref: '#/components/responses/R500'
  /accounts:batchUpdate:
    post:
      tags:
        - account
      summary: Batch update accounts
      operationId: batchUpdateAccounts
      security:
        - jwtAuth:
            - account.admin
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/account-update'
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/account'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '500':
          $ref: '#/components/responses/R500'
  /accounts/{account}:
    get:
      tags:
        - account
      summary: Get an account
      operationId: getAccount
      security:
        - jwtAuth:
            - account.read
        - jwtAuth:
            - account.admin
      parameters:
        - $ref: '#/components/parameters/account'
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/getAccountResponse'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
  /accounts/{account}/diaries:
    get:
      tags:
        - account
        - diary
      summary: Get all diaries
      operationId: getDiaries
      security:
        - jwtAuth:
            - diary.read
        - jwtAuth:
            - diary.admin
      parameters:
        - $ref: '#/components/parameters/account'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/diary'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    post:
      tags:
        - account
        - diary
      summary: Create a diary
      operationId: createDiary
      security:
        - jwtAuth:
            - diary.write
        - jwtAuth:
            - diary.admin
      parameters:
        - $ref: '#/components/parameters/account'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/diary-post'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/diary'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '500':
          $ref: '#/components/responses/R500'
  /accounts/{account}/diaries/{diary}:
    get:
      tags:
        - account
        - diary
      summary: Get a diary entry
      operationId: getDiary
      security:
        - jwtAuth:
            - diary.read
        - jwtAuth:
            - diary.admin
      parameters:
        - $ref: '#/components/parameters/account'
        - $ref: '#/components/parameters/diary'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/diary'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    patch:
      tags:
        - account
        - diary
      summary: Update a diary
      description: |
        The user can update the diary entry for this week with a grace period of +- 1 day.
        Within a period of 2 weeks the user can also update the completion status of the goals.
      operationId: updateDiary
      security:
        - jwtAuth:
            - diary.write
        - jwtAuth:
            - diary.admin
      parameters:
        - $ref: '#/components/parameters/account'
        - $ref: '#/components/parameters/diary'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/diary-patch'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/diary'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    delete:
      tags:
        - account
        - diary
      summary: Delete a diary
      operationId: deleteDiary
      security:
        - jwtAuth:
            - diary.write
        - jwtAuth:
            - diary.admin
      parameters:
        - $ref: '#/components/parameters/account'
        - $ref: '#/components/parameters/diary'
        - $ref: '#/components/parameters/allow_missing'
      responses:
        '204':
          $ref: '#/components/responses/R204'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
  /events:
    get:
      tags:
        - event
      summary: Get all events
      operationId: getEvents
      security: []
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/event'
        '500':
          $ref: '#/components/responses/R500'
    post:
      tags:
        - event
      summary: Create an event
      operationId: postEvent
      security:
        - jwtAuth:
            - event.admin
      parameters:
        - name: event_id
          description: '4-63 valid characters: /[a-z][0-9]-/'
          in: query
          required: false
          schema:
            type: string
            minLength: 4
            maxLength: 63
            pattern: ^[a-z0-9-]+$
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/event-post'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/event'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /events/{event}:
    get:
      tags:
        - event
      summary: Get an event
      operationId: getEvent
      security: []
      parameters:
        - $ref: '#/components/parameters/event'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/event'
        '500':
          $ref: '#/components/responses/R500'
    patch:
      tags:
        - event
      summary: Update an event
      operationId: patchEvent
      security:
        - jwtAuth:
            - event.admin
      parameters:
        - $ref: '#/components/parameters/event'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/event-patch'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/event'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '500':
          $ref: '#/components/responses/R500'
  /missions:
    get:
      tags:
        - mission
      summary: Get all missions
      operationId: getMissions
      security: []
      parameters:
        - name: format
          in: query
          required: false
          schema:
            type: string
            enum:
              - summary
              - extended
            default: summary
        - name: filter
          description: Filter by [mission_state, approval_state]
          in: query
          required: false
          schema:
            type: string
          example: mission_state=active
        - name: order_by
          description: Order by [title, like_count]
          in: query
          required: false
          schema:
            type: string
        - $ref: '#/components/parameters/show_deleted'
        - name: show_unapproved
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/getMissionResponse'
        '400':
          $ref: '#/components/responses/R400'
        '500':
          $ref: '#/components/responses/R500'
    post:
      tags:
        - mission
      summary: Create a mission
      operationId: postMission
      security:
        - jwtAuth:
            - mission.write
        - jwtAuth:
            - mission.admin
      parameters:
        - name: mission_id
          description: '4-63 valid characters: /[a-z][0-9]-/'
          in: query
          required: false
          schema:
            type: string
            minLength: 4
            maxLength: 63
            pattern: ^[a-z0-9-]+$
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mission-post'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}:
    get:
      tags:
        - mission
      summary: Get a mission
      operationId: getMission
      security: []
      parameters:
        - $ref: '#/components/parameters/mission'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission'
        '400':
          $ref: '#/components/responses/R400'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    patch:
      tags:
        - mission
      summary: Update a mission
      description: |
        - for admins: allow update all fields
        - for leader: allow update description, description_goal, description_skills, github_link
        - for other users: return 403
      operationId: patchMission
      security:
        - jwtAuth:
            - mission.write
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mission-patch'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    delete:
      tags:
        - mission
      summary: Delete a mission
      operationId: deleteMission
      security:
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/allow_missing'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}:undelete:
    post:
      tags:
        - mission
      summary: Undelete a mission
      operationId: undeleteMission
      security:
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}:reject:
    post:
      tags:
        - mission
      summary: Reject a mission
      operationId: rejectMission
      security:
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}:like:
    post:
      tags:
        - mission
      summary: Like a mission
      operationId: likeMission
      security: []
      parameters:
        - $ref: '#/components/parameters/mission'
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission'
        '400':
          $ref: '#/components/responses/R400'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}:approve:
    post:
      tags:
        - mission
      summary: Approve a mission
      operationId: approveMission
      security:
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}/milestones:
    get:
      tags:
        - mission/milestone
      summary: Get all milestones of a mission
      operationId: getMissionMilestones
      security: []
      parameters:
        - $ref: '#/components/parameters/mission'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/mission_milestone'
        '400':
          $ref: '#/components/responses/R400'
        '404':
          $ref: '#/components/responses/R404'
    post:
      tags:
        - mission/milestone
      summary: Create a milestone
      operationId: postMissionMilestone
      security:
        - jwtAuth:
            - mission.write
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - name: milestone_id
          description: '4-63 valid characters: /[a-z][0-9]-/'
          in: query
          required: false
          schema:
            type: string
            minLength: 4
            maxLength: 63
            pattern: ^[a-z0-9-]+$
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mission_milestone-post'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission_milestone'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}/milestones/{milestone}:
    get:
      tags:
        - mission/milestone
      summary: Get a milestone
      operationId: getMissionMilestone
      security: []
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/mission_milestone'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission_milestone'
        '400':
          $ref: '#/components/responses/R400'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    patch:
      tags:
        - mission/milestone
      summary: Update a milestone
      operationId: patchMissionMilestone
      security:
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/mission_milestone'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mission_milestone-patch'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission_milestone'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    delete:
      tags:
        - mission/milestone
      summary: Delete a milestone
      operationId: deleteMissionMilestone
      security:
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/mission_milestone'
        - $ref: '#/components/parameters/allow_missing'
      responses:
        '204':
          $ref: '#/components/responses/R204'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}/milestones/{milestone}:complete:
    post:
      tags:
        - mission/milestone
      summary: Complete a milestone
      operationId: completeMissionMilestone
      security:
        - jwtAuth:
            - mission.write
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/mission_milestone'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission_milestone'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}/accounts:
    get:
      tags:
        - mission/account
      summary: Get all accounts in a mission
      description: |
        The leader will be able to see emails.
      operationId: getMissionAccounts
      security: []
      parameters:
        - $ref: '#/components/parameters/mission'
        - name: filter
          description: Filter by [approved]
          in: query
          required: false
          schema:
            type: string
          example: approved=true
        - name: show_unapproved
          description: If set to true will show unapproved missionaccounts
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/mission_account'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    post:
      tags:
        - mission/account
      summary: Join a mission
      description: |
        Request to join a mission
        - For admins: allow add any account
        - For self: allow add your own account
      operationId: postMissionAccount
      security:
        - jwtAuth:
            - mission.write
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - name: approved
          description: |
            Can only be used by admins.
            If set to true will add the account without needing approval from leader.
          in: query
          required: false
          schema:
            type: boolean
            default: false
        - name: self
          description: If set to true will add your own account and ignore body.
          in: query
          required: false
          schema:
            type: boolean
            default: false
      requestBody:
        required: false
        description: If not set your own account will be added.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/mission_account-post'
          empty: {}
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission_account'
        '204':
          $ref: '#/components/responses/R204'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}/accounts/{account}:
    get:
      tags:
        - mission/account
      summary: Get an account in a mission
      operationId: getMissionAccount
      security: []
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/account'
        - name: show_unapproved
          description: If set to true will show unapproved missionaccounts
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/mission_account'
        '400':
          $ref: '#/components/responses/R400'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
    delete:
      tags:
        - mission/account
      summary: Remove an account from a mission
      operationId: deleteMissionAccount
      security:
        - jwtAuth:
            - mission.write
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/account'
        - $ref: '#/components/parameters/allow_missing'
      responses:
        '204':
          $ref: '#/components/responses/R204'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}/accounts/{account}:reject:
    post:
      tags:
        - mission/account
      summary: Reject a join request
      operationId: rejectMissionAccount
      security:
        - jwtAuth:
            - mission.write
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/account'
      responses:
        '204':
          $ref: '#/components/responses/R204'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /missions/{mission}/accounts/{account}:approve:
    post:
      tags:
        - mission/account
      summary: Approve a join request
      operationId: approveMissionAccount
      security:
        - jwtAuth:
            - mission.write
        - jwtAuth:
            - mission.admin
      parameters:
        - $ref: '#/components/parameters/mission'
        - $ref: '#/components/parameters/account'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/mission_account'
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '404':
          $ref: '#/components/responses/R404'
        '409':
          $ref: '#/components/responses/R409'
        '500':
          $ref: '#/components/responses/R500'
  /files:
    post:
      tags:
        - file
      summary: Upload a file
      description: Endpoint to upload a file
      operationId: uploadFile
      security:
        - jwtAuth:
            - file.admin
      parameters:
        - name: bucketName
          in: query
          description: The name of the bucket to upload the file to
          required: true
          schema:
            type: string
            enum:
              - public
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        '200':
          description: File uploaded successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  fileId:
                    type: string
                  fileUrl:
                    type: string
                    format: uri
                required:
                  - fileId
        '400':
          $ref: '#/components/responses/R400'
        '401':
          $ref: '#/components/responses/R401'
        '403':
          $ref: '#/components/responses/R403'
        '500':
          $ref: '#/components/responses/R500'
components:
  securitySchemes:
    jwtAuth:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://keycloak.on.42heilbronn.de/realms/os/protocol/openid-connect/auth
          tokenUrl: https://keycloak.on.42heilbronn.de/realms/os/protocol/openid-connect/token
          scopes:
            openid: default scope required
            roles: needed for admins to impersonate other users
            account.read: needed for reading account data
            account.write: needed for writing account data
            account.admin: needed for admin actions on accounts
            mission.read: needed for reading mission data
            mission.write: needed for writing mission data
            mission.admin: needed for admin actions on missions
            diary.read: needed for reading diary data
            diary.write: needed for writing diary data
            diary.admin: needed for admin actions on diaries
            file.admin: needed for admin actions on files
            event.admin: needed for admin actions on events
  parameters:
    page_size:
      name: page_size
      in: query
      description: |
        The maximum number to return. May return fewer than this value.
        If unspecified (or specifies 0), a defualt is chosen.
      required: false
      schema:
        type: integer
    page_token:
      name: page_token
      in: query
      description: |
        A page token, received from a previous call.
        Provide this to retrieve the subsequent page.
        When paginating, all other parameters provided must match
        the call that provided the page token.
      required: false
      schema:
        type: string
    account:
      name: account
      in: path
      required: true
      schema:
        type: string
      x-go-name: accountID
    diary:
      name: diary
      in: path
      required: true
      schema:
        type: string
      x-go-name: diaryWeek
    allow_missing:
      name: allow_missing
      in: query
      description: delete will return 2xx if the resource is not found
      required: false
      schema:
        type: boolean
        default: false
    event:
      name: event
      in: path
      required: true
      schema:
        type: string
      x-go-name: eventID
    show_deleted:
      name: show_deleted
      in: query
      description: include soft deleted resources
      required: false
      schema:
        type: boolean
        default: false
    mission:
      name: mission
      in: path
      required: true
      schema:
        type: string
      x-go-name: missionID
    mission_milestone:
      name: milestone
      in: path
      required: true
      schema:
        type: string
      x-go-name: milestoneID
  schemas:
    account:
      properties:
        name:
          type: string
          x-order: 1
        nick_name:
          type: string
          x-order: 4
          maxLength: 255
        email:
          type: string
          maxLength: 255
          x-order: 7
        create_time:
          type: string
          format: date-time
          x-order: 15
        update_time:
          type: string
          format: date-time
          x-order: 16
        last_login_time:
          type: string
          format: date-time
          x-order: 17
        delete_time:
          type: string
          format: date-time
          x-order: 18
        purge_time:
          type: string
          format: date-time
          x-order: 19
      required:
        - name
        - nick_name
        - email
        - create_time
        - update_time
        - last_login_time
    accountArray:
      type: array
      items:
        $ref: '#/components/schemas/account'
    name:
      type: string
      x-order: 1
    nick_name:
      type: string
      x-order: 4
      maxLength: 255
    email:
      type: string
      maxLength: 255
      x-order: 7
    account-public:
      properties:
        name:
          $ref: '#/components/schemas/name'
        nick_name:
          $ref: '#/components/schemas/nick_name'
        email:
          $ref: '#/components/schemas/email'
      required:
        - name
        - nick_name
    accountPublicArray:
      type: array
      items:
        $ref: '#/components/schemas/account-public'
    getAccountsResponse:
      oneOf:
        - $ref: '#/components/schemas/accountArray'
        - $ref: '#/components/schemas/accountPublicArray'
    account-update:
      properties:
        name:
          $ref: '#/components/schemas/name'
        nick_name:
          $ref: '#/components/schemas/nick_name'
        email:
          $ref: '#/components/schemas/email'
      required:
        - name
        - nick_name
        - email
    getAccountResponse:
      oneOf:
        - $ref: '#/components/schemas/account'
        - $ref: '#/components/schemas/account-public'
    diary_goal:
      properties:
        title:
          type: string
          x-order: 1
        completed:
          type: boolean
          x-order: 2
      required:
        - title
        - completed
    diary:
      properties:
        name:
          type: string
          x-order: 1
        account_id:
          type: string
          x-order: 2
        entry_date:
          type: string
          format: date
          description: The date of the start of the week on which the diary entry is based
          x-order: 3
        project:
          type: string
          description: The project the user is working on
          x-order: 4
        completion_weeks:
          type: integer
          format: int32
          description: The number of weeks until the project is completed
          x-order: 5
        motivation:
          type: integer
          format: int32
          description: The user's motivation for the project
          x-order: 6
        learnings:
          type: string
          description: The user's learnings from the project
          x-order: 7
        obstacles:
          type: string
          description: The user's obstacles for the project
          x-order: 8
        goals:
          type: array
          items:
            $ref: '#/components/schemas/diary_goal'
            x-order: 9
        create_time:
          type: string
          format: date-time
          description: The time the diary entry was created
          x-order: 10
        update_time:
          type: string
          format: date-time
          description: The time the diary entry was last updated
          x-order: 11
        editable_diary:
          type: boolean
          description: Whether the currently used access token can edit / delete the diary entry
          x-order: 12
        editable_goal_completion:
          type: boolean
          description: Whether the currently used access token can edit the goals
          x-order: 13
      required:
        - name
        - account_id
        - entry_date
        - project
        - completion_weeks
        - motivation
        - learnings
        - obstacles
        - goals
        - create_time
        - update_time
        - editable_diary
        - editable_goal_completion
    entry_date:
      type: string
      format: date
      description: The date of the start of the week on which the diary entry is based
      x-order: 3
    project:
      type: string
      description: The project the user is working on
      x-order: 4
    completion_weeks:
      type: integer
      format: int32
      description: The number of weeks until the project is completed
      x-order: 5
    motivation:
      type: integer
      format: int32
      description: The user's motivation for the project
      x-order: 6
    learnings:
      type: string
      description: The user's learnings from the project
      x-order: 7
    obstacles:
      type: string
      description: The user's obstacles for the project
      x-order: 8
    goals:
      type: array
      items:
        $ref: '#/components/schemas/diary_goal'
        x-order: 9
    diary-post:
      properties:
        entry_date:
          $ref: '#/components/schemas/entry_date'
        project:
          $ref: '#/components/schemas/project'
        completion_weeks:
          $ref: '#/components/schemas/completion_weeks'
        motivation:
          $ref: '#/components/schemas/motivation'
        learnings:
          $ref: '#/components/schemas/learnings'
        obstacles:
          $ref: '#/components/schemas/obstacles'
        goals:
          $ref: '#/components/schemas/goals'
      required:
        - entry_date
        - project
        - completion_weeks
        - motivation
        - learnings
        - obstacles
        - goals
    diary-patch:
      properties:
        project:
          $ref: '#/components/schemas/project'
        completion_weeks:
          $ref: '#/components/schemas/completion_weeks'
        motivation:
          $ref: '#/components/schemas/motivation'
        learnings:
          $ref: '#/components/schemas/learnings'
        obstacles:
          $ref: '#/components/schemas/obstacles'
        goals:
          $ref: '#/components/schemas/goals'
    event:
      properties:
        name:
          type: string
          x-order: 1
        title:
          type: string
          x-order: 2
        topic:
          type: string
          x-order: 3
        picture_uri:
          type: string
          format: uri
          x-order: 4
        link:
          type: string
          format: uri
          x-order: 5
        description:
          type: string
          x-order: 6
        location:
          type: string
          x-order: 7
        begin_time:
          type: string
          format: date-time
          x-order: 8
        end_time:
          type: string
          format: date-time
          x-order: 9
      required:
        - name
        - title
        - topic
        - picture_uri
        - link
        - description
        - location
        - begin_time
        - end_time
    title:
      type: string
      x-order: 2
    topic:
      type: string
      x-order: 3
    picture_uri:
      type: string
      format: uri
      x-order: 4
    link:
      type: string
      format: uri
      x-order: 5
    description:
      type: string
      x-order: 6
    location:
      type: string
      x-order: 7
    begin_time:
      type: string
      format: date-time
      x-order: 8
    end_time:
      type: string
      format: date-time
      x-order: 9
    event-post:
      properties:
        title:
          $ref: '#/components/schemas/title'
        topic:
          $ref: '#/components/schemas/topic'
        picture_uri:
          $ref: '#/components/schemas/picture_uri'
        link:
          $ref: '#/components/schemas/link'
        description:
          $ref: '#/components/schemas/description'
        location:
          $ref: '#/components/schemas/location'
        begin_time:
          $ref: '#/components/schemas/begin_time'
        end_time:
          $ref: '#/components/schemas/end_time'
      required:
        - title
        - topic
        - picture_uri
        - link
        - description
        - location
        - begin_time
        - end_time
    event-patch:
      properties:
        title:
          $ref: '#/components/schemas/title'
        topic:
          $ref: '#/components/schemas/topic'
        picture_uri:
          $ref: '#/components/schemas/picture_uri'
        link:
          $ref: '#/components/schemas/link'
        description:
          $ref: '#/components/schemas/description'
        location:
          $ref: '#/components/schemas/location'
        begin_time:
          $ref: '#/components/schemas/begin_time'
        end_time:
          $ref: '#/components/schemas/end_time'
    mission_mission_state:
      type: string
      enum:
        - active
        - completed
        - failed
    mission_approval_state:
      type: string
      enum:
        - pending
        - approved
        - rejected
    mission:
      properties:
        name:
          type: string
          readOnly: true
          x-go-type-skip-optional-pointer: true
          x-order: 1
        title:
          type: string
          maxLength: 255
          x-order: 2
        description:
          type: string
          maxLength: 1000
          x-order: 3
        description_goal:
          type: string
          maxLength: 1000
          x-order: 4
        description_skills:
          type: string
          maxLength: 1000
          x-order: 5
        github_link:
          type: string
          format: uri
          x-order: 6
        leader:
          type: string
          x-order: 7
        mission_state:
          $ref: '#/components/schemas/mission_mission_state'
          x-order: 8
        approval_state:
          $ref: '#/components/schemas/mission_approval_state'
          x-order: 9
        like_count:
          type: integer
          format: int32
          x-order: 10
        kickoff_time:
          type: string
          format: date-time
          x-order: 11
        end_time:
          type: string
          format: date-time
          x-order: 12
        create_time:
          type: string
          format: date-time
          x-order: 13
        update_time:
          type: string
          format: date-time
          x-order: 14
        delete_time:
          type: string
          format: date-time
          x-order: 15
      required:
        - name
        - title
        - description
        - description_goal
        - description_skills
        - github_link
        - leader
        - mission_state
        - approval_state
        - like_count
        - kickoff_time
        - create_time
        - update_time
    missionArray:
      type: array
      items:
        $ref: '#/components/schemas/mission'
    properties-name:
      type: string
      readOnly: true
      x-go-type-skip-optional-pointer: true
      x-order: 1
    properties-title:
      type: string
      maxLength: 255
      x-order: 2
    properties-description:
      type: string
      maxLength: 1000
      x-order: 3
    mission-summary:
      properties:
        name:
          $ref: '#/components/schemas/properties-name'
        title:
          $ref: '#/components/schemas/properties-title'
        description:
          $ref: '#/components/schemas/properties-description'
        mission_state:
          $ref: '#/components/schemas/mission_mission_state'
        like_count:
          type: integer
          format: int32
          x-order: 4
        milestones_count:
          type: integer
          format: int32
          x-order: 5
        completed_milestones_count:
          type: integer
          format: int32
          x-order: 6
        account_count:
          type: integer
          format: int32
          x-order: 7
      required:
        - name
        - title
        - description
        - mission_state
        - like_count
        - milestones_count
        - completed_milestones_count
        - account_count
    missionSummaryArray:
      type: array
      items:
        $ref: '#/components/schemas/mission-summary'
    getMissionResponse:
      oneOf:
        - $ref: '#/components/schemas/missionArray'
        - $ref: '#/components/schemas/missionSummaryArray'
    description_goal:
      type: string
      maxLength: 1000
      x-order: 4
    description_skills:
      type: string
      maxLength: 1000
      x-order: 5
    github_link:
      type: string
      format: uri
      x-order: 6
    kickoff_time:
      type: string
      format: date-time
      x-order: 11
    properties-end_time:
      type: string
      format: date-time
      x-order: 12
    mission-post:
      properties:
        title:
          $ref: '#/components/schemas/properties-title'
        description:
          $ref: '#/components/schemas/properties-description'
        description_goal:
          $ref: '#/components/schemas/description_goal'
        description_skills:
          $ref: '#/components/schemas/description_skills'
        github_link:
          $ref: '#/components/schemas/github_link'
        kickoff_time:
          $ref: '#/components/schemas/kickoff_time'
        end_time:
          $ref: '#/components/schemas/properties-end_time'
      required:
        - title
        - description
        - description_goal
        - description_skills
        - github_link
        - kickoff_time
    mission-patch:
      properties:
        title:
          $ref: '#/components/schemas/properties-title'
        description:
          $ref: '#/components/schemas/properties-description'
        description_goal:
          $ref: '#/components/schemas/description_goal'
        description_skills:
          $ref: '#/components/schemas/description_skills'
        github_link:
          $ref: '#/components/schemas/github_link'
    mission_milestone_state:
      type: string
      enum:
        - planned
        - in progress
        - completed
        - failed
    mission_milestone:
      properties:
        name:
          type: string
          readOnly: true
          x-go-type-skip-optional-pointer: true
          x-order: 1
        description:
          type: string
          maxLength: 1000
          x-order: 2
        state:
          $ref: '#/components/schemas/mission_milestone_state'
          x-order: 3
        end_time:
          type: string
          format: date-time
          x-order: 4
      required:
        - name
        - description
        - state
        - end_time
    mission_milestone-post:
      properties:
        description:
          type: string
          maxLength: 1000
          x-order: 1
        end_time:
          type: string
          format: date-time
          x-order: 2
      required:
        - description
        - end_time
    mission_milestone-patch:
      properties:
        description:
          type: string
          maxLength: 1000
          x-order: 2
        end_time:
          type: string
          format: date-time
          x-order: 2
    mission_account:
      properties:
        name:
          type: string
          readOnly: true
          x-go-type-skip-optional-pointer: true
          x-order: 1
        account:
          $ref: '#/components/schemas/account-public'
        mission:
          type: string
          x-order: 3
        approved:
          type: boolean
          x-order: 4
      required:
        - name
        - account
        - mission
    mission_account-post:
      properties:
        account:
          type: string
          x-order: 1
      required:
        - account
  responses:
    R401:
      description: Unauthorized
    R403:
      description: Forbidden
    R500:
      description: Internal Server Error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                example: database error
            required:
              - message
    R400:
      description: Bad Request
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                example: Invalid Amount
            required:
              - message
    R404:
      description: Not Found
    R204:
      description: No Content
    R409:
      description: Conflict
x-tagGroups:
  - name: auth
    tags:
      - auth
  - name: account
    tags:
      - account
      - diary
  - name: event
    tags:
      - event
  - name: mission
    tags:
      - mission
      - mission/account
      - mission/milestone
  - name: file
    tags:
      - file
