What Is StudyBuddy

StudyBuddy is a dynamic platform designed to support students in their academic journey. Whether you’re tackling math, science, history, or any other subject, StudyBuddy is here to help you succeed. Our goal is to make learning fun, engaging, and effective. With a variety of tools at your fingertips, StudyBuddy offers a comprehensive study experience:

What is my part about?

This allows users to collaborate with each other and let them express their facts to each other. This fosters an educational exchange of information between users interacting with the facts page.

Facts API Documentation

This API allows users to manage “facts” associated with individuals. It includes endpoints for creating, retrieving, updating, and deleting facts, as well as an initialization function to populate sample data.

Model: Facts

The Facts model represents an individual fact entry in the database. It contains the following attributes:

  • id: (Integer) Primary key, auto-incremented.
  • _name: (String) The name of the individual. Must be unique and non-null.
  • _fact: (String) The fact associated with the individual. Must be unique and non-null.

Methods:

create()

  • Description: Adds the current instance of Facts to the database and commits the transaction.
  • Raises: Rolls back the transaction and raises an exception if an error occurs.

read()

  • Description: Returns the fact’s data as a dictionary containing id, name, and fact.

update(users)

  • Description: Commits changes to the database.
  • Raises: Rolls back the transaction and raises an exception if an error occurs.

delete()

  • Description: Deletes the current instance of Facts from the database and commits the transaction.
  • Raises: Rolls back the transaction and raises an exception if an error occurs.

  • Adding Information (POST Request):
    • New users access the site, which is initially empty.
    • They fill it in with a fact of their liking.
    • A POST request is sent to store the fact in the database and generate a unique user ID.
  • Loading Information (GET Request):
    • A GET request is triggered when the facts page is reloaded.
    • Retrieves user facts from the database.
    • Displays the facts based on the current user’s id.
  • Updating Information (PUT Request):
    • Users can edit facts in the database.
    • A PUT request is sent to update their facts in the database with the updated info and user ID.
  • Deleting Information (DELETE Request):
    • Users can choose to remove their facts from the database.
    • A DELETE request is sent to remove facts from the database.

Endpoints

1. POST /api/userfacts

Description: Adds a new fact to the database.

  • Request Body (JSON):
    {
      "name": "Alice",
      "fact": "Apples are green or red"
    }
    
  • Response:
    • 201 Created:
      {
        "message": "Fact added successfully"
      }
      
    • 400 Bad Request:
      {
        "error": "Missing data"
      }
      

2. GET /api/userfacts

Description: Retrieves all facts from the database.

  • Response:
    • 200 OK:
      [
        {
          "id": 1,
          "name": "Alice",
          "fact": "Apples are green or red"
        },
        {
          "id": 2,
          "name": "Bob",
          "fact": "Honey never spoils"
        }
      ]
      

3. DELETE /api/userfacts/<int:id>

Description: Deletes a fact by its ID.

  • Response:
    • 200 OK:
      {
        "message": "Fact deleted successfully"
      }
      
    • 404 Not Found:
      {
        "error": "Fact not found"
      }
      

4. PUT /api/userfacts/<int:id>

Description: Updates an existing fact by its ID.

  • Request Body (JSON):
    {
      "name": "Alice",
      "fact": "Bananas are yellow"
    }
    
  • Response:
    • 200 OK:
      {
        "message": "Fact updated successfully"
      }
      
    • 400 Bad Request:
      {
        "error": "Missing data"
      }
      
    • 404 Not Found:
      {
        "error": "Fact not found"
      }
      

Initialization Function: initfacts

Description: Creates the database tables and populates the Facts table with sample data.

Sample Data:

  • Alice: “Apples are green or red”
  • Bob: “Honey never spoils”
  • Charlie: “The moon is made of cheese”
  • Diana: “The earth is flat”

Usage: Call initfacts() within the application context to initialize the database.


This documentation now reflects the functionality described in the provided code.