WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

srijeeta0425/user-api-springboot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👩‍💻 User Management API – Spring Boot + MongoDB

This is a simple REST API project for managing users, built using Java 17, Spring Boot, and MongoDB. It supports creating, updating, listing, and toggling user activation status.


Table of Contents

Features

  • POST /api/create-user – Create a new user
  • POST /api/update-user – Update existing user details
  • GET /api/users – List all users
  • POST /api/toggle-user?id= – Activate or deactivate a user
  • .idea folder removed and include in .gitignore
  • Includes basic unit testing cases
  • Proper Git Branching and Pull Request for workflow followed

MongoDB Document Structure

{
  "_id": "ObjectId",
  "email": "string",
  "firstName": "string",
  "lastName": "string",
  "isActive": true,
  "tenantId": "string",
  "createdAt": "datetime",
  "updatedAt": "datetime"
}

Technologies Used

  • Java 17

  • Spring Boot 3.2.4

  • MongoDB (local)

  • Maven

  • IntelliJ IDEA

  • Git & GitHub

  • Postman (for API testing)

  • Swagger (springdoc-openapi-ui)

Project Structure

user-api-springboot/
├── src/
│   ├── main/
│   │   ├── java/com/example/userapi/
│   │   │   ├── controller/            # REST API controllers
│   │   │   ├── model/                 # User model
│   │   │   ├── repository/            # MongoDB repository
│   │   │   └── service/               # Business logic
│   │   └── resources/
│   │       ├── application.properties
│   │       └── static/
│   │           └── swagger-ui.png     # Swagger screenshot (if added)
│
│   ├── test/
│   │   └── java/com/example/userapi/
│   │       ├── DummyTest.java         # Basic test to verify setup
│
├── .gitignore                         # Now includes `.idea/`
├── pom.xml                            # Maven project file with dependencies
├── README.md                          # Full documentation

🔍 API Endpoints

Method Endpoint Description
POST /api/create-user Create a new user
POST /api/update-user Update existing user info
GET /api/users Fetch list of all users
POST /api/toggle-user Toggle user activation by ID

How to Run This Project

🖥️ Prerequisites

  • MongoDB running locally on mongodb://localhost:27017

  • Java 17 installed

  • IntelliJ IDEA (or other Java IDE)

Steps to Run

1. Clone the repo:

git clone https://github.com/srijeeta0425/user-api-springboot.git

2. Open the project in IntelliJ IDEA

3. Configure MongoDB if needed in:

src/main/resources/application.properties

4. Run the application:

Open UserApiApplication.java

Click the green Run button or use Shift + F10

5. Test the API in Swagger UI:

Run Commands

# Install dependencies and build the project

mvn clean install

# Run the Spring Boot application
mvn spring-boot:run

The application runs on:

http://localhost:8080

MongoDB Setup

Step-by-step:

  1. Download MongoDB Community Edition from MongoDB Downloads

  2. Start MongoDB server (default port is 27017)

  3. Make sure MongoDB is running

  4. In application.properties, set the URI:

spring.data.mongodb.uri=mongodb://localhost:27017/user-api-db

Spring Boot will auto-create the collections.

OpenAPI Documentation

Swagger Setup

Included dependency in pom.xml:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.14</version>
</dependency>

Swagger Endpoints:

Git Ignore Setup

A .gitignore file was added to exclude unnecessary files:

# Build output
/target/

# IDE settings
/.idea/
*.iml

# OS clutter
.DS_Store
Thumbs.db

Swagger UI Screenshot

![Swagger UI](src/main/resources/static/swagger-ui.png)

Example

  1. POST request to /api/create-user:
{
  "email": "[email protected]",
  "firstName": "Srijeeta",
  "lastName": "Purkait",
  "tenantId": "getpostlabs123"
}
  1. POST request to /api/update-user:
{
  "email": "[email protected]",
  "firstName": "Updated",
  "lastName": "Name",
  "tenantId": "newTenant"
}

3.GET request to /api/users:

{
  "email": "[email protected]",
  "firstName": "Srijeeta",
  "lastName": "Purkait",
  "tenantId": "getpostlabs123"
}
  1. POST request to /api/toggle-user:
{
  "email": "[email protected]",
    "firstName": "Updated",
    "lastName": "Name",
    "tenantId": "newTenant"
}

Author

Srijeeta Purkait

Software Engineer Trainee– [GetPost Labs]

📫 Email: [email protected]

🔗 GitHub: https://github.com/srijeeta0425/user-api-springboot/tree/master

About

Spring Boot + MongoDB User Management API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published