hxvMI / Spring_Boot_Quiz_Application

Spring Boot-based web Quiz creation app
0 stars 0 forks source link

QuizApp

Reason for Project

I wanted to use everything I have been learning for the past couple of months to use and make something simple including as much of everything as I could.

Overview

QuizApp is a Spring Boot-based web application designed to manage quizzes. The application allows users to create, retrieve, and submit quizzes. It uses a RESTful API with full CRUD operations and interacts with a MySQL database. This project also supports user quiz submissions and score calculation.

Features

Technologies Used

How to Run

  1. Clone the repository
    git clone https://github.com/hxvMI/Spring_Boot_Quiz_Application.git
  2. Navigate to the project folder
    cd quizapp
  3. Modify application.properties to configure the database connection if necessary.
  4. Run the application using Maven
    mvn spring-boot:run
  5. The app will be available at http://localhost:8083.

Project Structure

src/main/java/com/vhashiro/quizapp
├── controller   # Contains API controllers
├── entity       # Defines JPA entities
├── repository   # Database access with JPA
├── service      # Business logic and services
├── QuizAppApplication.java  # Spring Boot main class
└── application.properties   # Configuration file 

Database Configuration

MySQL (Default)

Ensure your MySQL server is running, and configure the application.properties file for the database connection:

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/quiz_database
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

H2 (In-Memory Database)

For development and testing, you can switch to an H2 in-memory database by uncommenting the following lines in application.properties:

#spring.h2.console.enabled=true
#spring.datasource.url=jdbc:h2:mem:dcbapp
#spring.datasource.driver-class-name=org.h2.Driver
#spring.datasource.username=sa
#spring.datasource.password=password
#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

API Endpoints

Question Endpoints

Testing the API

You can use Postman or curl to test the endpoints.

Postman Link: https://www.postman.com/downloads/

Example: Create a Quiz

curl -X POST "http://localhost:8083/quiz/create?questionCategory=java&numQuestions=5&title=JavaBasics"

Example: Submit a Quiz

curl -X POST "http://localhost:8083/quiz/submit/1" \
-H "Content-Type: application/json" \
-d '[
    {"id": 1, "selectedOption": "option1"},
    {"id": 2, "selectedOption": "option3"}
]'

I have also included other examples in quizapp/quizapp/src/main/java/com/vhashiro/quizapp/Request Testing Resources