Skip to content

A RESTful API service using Spring Boot to manage the Leaderboard for a Coding Platform while using MongoDB to persist the data.

Notifications You must be signed in to change notification settings

geetanjaligit/CoderHack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CoderHack Application

CoderHack is a Spring Boot application that gamifies user engagement by assigning scores and badges based on their performance. It leverages a MongoDB database to manage users and their achievements effectively.

Table of Contents

  1. Features
  2. Tech Stack
  3. Setup Instructions
  4. Project Structure
  5. Example Usage
  6. Testing

Features

  • CRUD Operations: Create, Read, Update, and Delete user data.
  • Score Tracking: Dynamically update user scores with validation.
  • Badge System: Automatically assign badges based on user performance:
    • Code Ninja: Score between 1–30.
    • Code Champ: Score between 30–60.
    • Code Master: Score above 60.
  • Sorted Leaderboard: Retrieve all users sorted by scores in descending order.

Tech Stack

  • Backend: Spring Boot
  • Database: MongoDB
  • Testing: JUnit, Mockito

Setup Instructions

  1. Clone the Repository:
git clone https://github.com/geetanjaligit/CoderHack.git
cd CoderHack
  1. Setup MongoDB:
  • Ensure MongoDB is installed and running locally on localhost:27017.
  • Default database: Coderhackdb.
  1. Configure Application Properties:
  • Edit src/main/resources/application.properties if needed:
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=Coderhackdb
spring.data.mongodb.auto-index-creation=true
  1. Run the Application:
./mvnw spring-boot:run
  1. API Endpoints:
  • Get All Users: GET /users
  • Get User by ID: GET /users/id/{userId}
  • Create User: POST /users
  • Update User Score: PUT /users/id/{userId}
  • Delete User: DELETE /users/{userId}

Project Structure

  • Controller: Manages API endpoints.
    • UserController.java
  • Service: Handles business logic.
    • UserService.java
    • UserScoreComparator.java
  • Repository: Interfaces with MongoDB.
    • UserRepository.java
  • Entity: Defines the data model.
    • User.java
  • Testing: Ensures reliability with JUnit and Mockito.
    • UserServiceTest.java

Example Usage

Add a User

POST /users
{
  "id": "101",
  "username": "John",
  "score": 0,
  "badges": []
}

Update User Score

PUT /users/id/101
Body: 40

Response:

{
  "id": "101",
  "username": "John",
  "score": 40,
  "badges": ["Code Champ"]
}

Testing

Run unit tests with:

./mvnw test

Sample Test Cases:

  • Verify badge assignment logic.
  • Validate CRUD operations.
  • Test for invalid score inputs.

About

A RESTful API service using Spring Boot to manage the Leaderboard for a Coding Platform while using MongoDB to persist the data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages