Skip to content

ggerve/DemoSpringBootApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Management API

A Spring Boot REST API for user management with OpenAPI documentation.

Technologies

  • Spring Boot: 3.4.3
  • H2 Database: 2.3.232
  • SpringDoc OpenAPI: 2.8.0
  • Spring Data JPA: 3.4.3
  • Maven: 3.9.0

Features

  • Create, read, update, and delete users
  • Validation for user data
  • Exception handling with appropriate HTTP status codes
  • OpenAPI documentation
  • In-memory H2 database

Getting Started

Prerequisites

  • Java 17 or higher
  • Maven 3.8.0 or higher

Running the Application

  1. Clone the repository
  2. Navigate to the project directory
  3. Run the application using Maven:
./mvnw spring-boot:run

The application will start on port 8081.

Accessing the API

API Endpoints

Create a User

POST /api/users

Request body:

{
  "firstName": "John",
  "lastName": "Doe",
  "email": "[email protected]",
  "phoneNumber": "1234567890"
}

Get All Users

GET /api/users

Get User by ID

GET /api/users/{id}

Update User

PUT /api/users/{id}

Request body:

{
  "firstName": "John",
  "lastName": "Doe",
  "email": "[email protected]",
  "phoneNumber": "1234567890"
}

Delete User

DELETE /api/users/{id}

Database Configuration

The application uses an H2 in-memory database with the following configuration:

  • URL: jdbc:h2:mem:testdb
  • Username: sa
  • Password: password

Project Structure

src/main/java/com/example/usermanagement/
├── controller/
│   └── UserController.java
├── dto/
│   └── UserDTO.java
├── exception/
│   ├── GlobalExceptionHandler.java
│   ├── ResourceNotFoundException.java
│   └── UserAlreadyExistsException.java
├── model/
│   └── User.java
├── repository/
│   └── UserRepository.java
├── service/
│   ├── UserService.java
│   └── impl/
│       └── UserServiceImpl.java
├── config/
│   └── OpenApiConfig.java
└── UserManagementApplication.java

Error Handling

The API returns appropriate HTTP status codes and error messages:

  • 400 Bad Request: Invalid input data
  • 404 Not Found: Resource not found
  • 409 Conflict: User with the same email already exists
  • 500 Internal Server Error: Unexpected server error

Development

Building the Project

./mvnw clean package

Running Tests

./mvnw test

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages