This is a Java-based Quiz Application built using Spring Boot and PostgreSQL, providing a dynamic quiz-taking experience with APIs to fetch questions from various categories, randomize question selection, and evaluate answers for final scoring. The app uses JPA for seamless interaction with the database and supports a flexible many-to-many relationship structure.
- Dynamic Question Fetching: Retrieve quiz questions by category or in randomized sets.
- Randomized Quiz Generation: Use of a master table to select random questions.
- Answer Scoring API: Final API endpoint to calculate the user’s score by comparing answers to those stored in the database.
- Database Integration: PostgreSQL backend stores questions, answers, and options, ensuring data persistence and efficient querying.
- Many-to-Many Relationships: Supports categorization and tagging of questions to allow versatile quiz generation.
- Java with Spring Boot for the backend.
- PostgreSQL as the database.
- Spring Data JPA for database interaction.
- RESTful APIs to handle quiz functionality.
- Master Table: Holds quiz metadata and connects questions to various categories.
- Quiz Table: Stores each question id with primary key.
-
Fetch Questions: Retrieve quiz questions by category or random selection.
- GET
/api/question/allQuestions - GET
/api/question/category/{value} - GET
/quiz/get/{id}
- GET
-
Submit Quiz Answers: Submit answers for scoring.
- POST
/api/quiz/submit - Request Body: JSON containing question IDs and corresponding answers.
- POST
-
Calculate Score: Calculate the score based on user-submitted answers.
- POST
/quiz/submit/{quiz id} - Compares answers with the database and returns the final score.
- POST
-
Add New questions: Add new questions for quiz in db directly.
- POST
/question/add - Pass data in req.body.
- POST
- Clone the repository:
git clone https://github.com/your-username/quiz-app.git
- Set up PostgreSQL and configure database credentials in
application.properties. - Run the application:
mvn spring-boot:run
- Update
application.propertiesto connect to your PostgreSQL instance:spring.datasource.url=jdbc:postgresql://localhost:5432/quizdb spring.datasource.username=your-username spring.datasource.password=your-password spring.jpa.hibernate.ddl-auto=update
- Run the server and access the endpoints to create quizzes, submit answers, and retrieve scores.
- Use Postman or similar tools to test APIs.