openapi: 3.0.2
info:
  title: CLAAC - OpenAPI 3.0
  description: >-
    This is the OpenAPI 3.0 documentation for CLAAC. This will include
    information on login, register, and other aspects that our profect uses.
  termsOfService: http://swagger.io/terms/
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.11
externalDocs:
  description: Find out more about Swagger
  url: http://swagger.io
servers:
  - url: https://caprifoliaceous-dessie-postpositively.ngrok-free.dev/api
    description: Always running backend server through rasberry pi and docker.
tags:
  - name: login
    description: Handles getting access to an already established account.
  - name: users
    description: Access to user information and features.
  - name: profile
    description: information about current user
  - name: children
    description: data about the children under an administrators account
  - name: register
    description: handles starting an account and entering the account into the database
paths:
  /login/admin/:
    post:
      tags:
        - login
      summary: Login to an administrator account
      description: Access the account of a administrator
      operationId: login
      requestBody:
        description: Access the account of a administrator
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Login'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoginSuccess'
        '400':
          description: Invalid Creditials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /users/{userId}/preferred-words/:
    get:
      tags:
        - users
      summary: Get the interest of a student within their profile.
      description: Return a list of strings
      operationId: fetchPreferredWords
      parameters:
        - name: userId
          description: The account number of the child account.
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PreferredWords'
        '400':
          description: User Issue
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: error
                  message:
                    type: string
                    example: User not found
  /profile/:
    get:
      tags:
        - profile
      summary: Finds the data in a profile.
      operationId: loadProfile
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProfileGet'
  /children/admin_id={user_id}:
    get:
      tags:
        - children
      summary: Find the children associated with an Admin Account
      description: Returns a list of strings
      operationId: fetchChildren
      parameters:
        - name: user_id
          description: The id number of the admin account logged in.
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChildrenGet'
        '400':
          description: Fail
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: admin_id required
  /register/admin/:
    post:
      tags:
        - register
      summary: Puts a new admin account into the database
      description: ''
      operationId: createAdmin
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Admin'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminCreate'
        '400':
          description: Failed Operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
  /register/child/:
    post:
      tags:
        - register
      summary: Add a new child account to the database under the logged in Admin
      description: Add a new child account to the database.
      operationId: createChild
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Child'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChildCreated'
        '400':
          description: Failed Registration
components:
  schemas:
    Login:
      type: object
      required:
        - email
        - password
      properties:
        email:
          type: string
          example: bob@gmail.com
        password:
          type: string
          example: 12345B
    Admin:
      type: object
      required:
        - username
        - email
        - password
        - role
      properties:
        username:
          type: string
          example: John Doe
        email:
          type: string
          example: johndoe@gmail.com
        password:
          type: string
          example: john12345
        role:
          type: string
          example: admin
    Child:
      type: object
      required:
        - username
        - guardian_id
        - role
      properties:
        username:
          type: string
          example: Jane Doe
        guardian_id:
          type: integer
          example: 67
        role:
          type: string
          example: child
    Error:
      type: object
      properties:
        error:
          type: string
          example: Invalid credentials
    LoginSuccess:
      type: object
      properties:
        message:
          type: string
          example: Login successful
        role:
          type: string
          example: admin
        token:
          type: string
          example: c6fke676-676t-6767-67i6-67676
        user_id:
          type: integer
          example: 67
    ProfileGet:
      type: object
      properties:
        email:
          type: string
          example: johndoe@gmail.com
        id:
          type: integer
          example: 67
        role:
          type: string
          example: admin
        username:
          type: string
          example: John Doe
    ChildrenGet:
      type: array
      items:
        type: object
        properties:
          id:
            type: integer
            example: 67
          username:
            type: string
            example: Jane Doe
    ChildCreated:
      type: object
      properties:
        token:
          type: string
          example: c6fke676-676t-6767-67i6-67676
        user:
          type: object
          properties:
            guardian:
              type: integer
              example: 67
            id:
              type: integer
              example: 69
            role:
              type: string
              example: child
            username:
              type: string
              example: Jane Doe
    AdminCreate:
      type: object
      properties:
        token:
          type: string
          example: c6fke676-676t-6767-67i6-67676
        user:
          type: object
          properties:
            email:
              type: string
              example: johndoe@gmail.com
            id:
              type: integer
              example: 67
            password:
              type: string
              example: john12345
            role:
              type: string
              example: admin
            username:
              type: string
              example: John
    AdminError:
      type: object
      properties:
        password:
          type: array
          items:
            type: string
          example:
            - This field may not be blank.
        username:
          type: array
          items:
            type: string
          example:
            - This field may not be blank.
    PreferredWords:
      type: object
      properties:
        status:
          type: string
          example: success
        user_id:
          type: integer
          example: 67
        preferred_words:
          type: array
          items:
            type: string
          example:
            - dinosaur
        interests:
          type: array
          items:
            type: string
          example:
            - books
