This project, named "User Management," is a robust Spring Boot application designed for managing user data efficiently. It provides a set of RESTful API endpoints that allow you to perform various operations on user records, such as adding, retrieving, updating, and deleting user information.
- Framework: Spring Boot
- Language: Java
- Build Tool: Maven
The User
class in our User Management System model is equipped with comprehensive data validation to ensure the accuracy and consistency of user data. Here are the key points about the validations applied to the fields:
- Validation:
@NotNull
- Description: The
userId
field is required and cannot be null.
- Validation:
@NotBlank
,@Pattern(regexp = "^[a-zA-Z ]+$")
- Description: The
userName
field must not be blank, and it must consist of alphabetic characters and spaces only.
- Validation: None
- Description: The
type
field is not subject to additional validation as it represents an enumeration of predefined user types.
- Validation:
@Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "Date of birth must be in yyyy-mm-dd format")
- Description: The
dateOfBirth
field is validated to ensure it adheres to the "yyyy-mm-dd" format.
- Validation:
@Email(message = "Invalid email format. Please enter a valid Email!")
- Description: The
userEmail
field is validated to ensure it contains a valid email address.
- Validation:
@Size(min = 12, max = 12)
,@Pattern(regexp = "91[0-9]{10}$", message = "Enter a Valid Phone Number,Phone number must start with 91 and be followed by 10 digits")
- Description: The
userContactNo
field is validated to ensure it is exactly 12 characters long and starts with "91," followed by 10 digits.
- Validation:
@NotNull(message = "Date cannot be null")
,@Past(message = "Date must be in the past")
- Description: The
date
field is validated to ensure it is not null and represents a date in the past.
- Validation:
@NotNull(message = "Time cannot be null")
- Description: The
time
field is validated to ensure it is not null.
-
Dynamic Default Values: Both the
date
andtime
fields have dynamic default values. Thedate
field is set to the current date, and thetime
field is set to the current time when a newUser
object is created. -
Custom Validation: We have implemented custom validation annotations for
LocalDate
andLocalTime
fields to enforce specific format and logic requirements. These custom annotations are used for more fine-grained validation.
These validations ensure that user data is accurately captured and meets specified criteria, contributing to the reliability and integrity of our User Management System. Users can trust that their information is handled with care and precision.
The Controller layer is responsible for handling incoming HTTP requests and delegating them to the appropriate services. It defines API endpoints for the following operations:
- Add User:
POST /user
- Add Users:
POST /users
- Get All Users:
GET /users
- Get User by ID:
GET /user/{userID}
- Update User Phone Number:
PUT /user/{userID}/number/{phoneNumber}
- Update User Address:
PUT /user/{userID}/address/{email}
- Delete User by ID:
DELETE /user/{userID}
@RestController
@Validated
public class UserController {
@Autowired
UserService userService;
// Add a user
@PostMapping("user")
public String addUser(@Valid @RequestBody User user) {
return userService.inputUser(user);
}
// Get all users
@GetMapping("users")
public List<User> getAllUsers() {
return userService.getAllUser();
}
// ...
}
The Services layer implements the core business logic, data processing, and interaction with the data repository. Key responsibilities include:
- Validating input data.
- Performing CRUD operations on user data.
- Handling data transformations and interactions with external systems (if applicable).
@Service
public class UserService {
@Autowired
UserRepo userRepo;
public List<User> getAllUser() {
return userRepo.getUsers();
}
// ...
}
The Repository layer manages data access to the underlying database. It handles database operations such as Create, Read, Update, and Delete (CRUD) for user data. Additionally, it may include data mapping and conversion between Java objects and database entities.
@Repository
public class UserRepo {
@Autowired
private List<User> userList;
public List<User> getUsers() {
return userList;
}
// ...
}
The project's database design includes tables for user management, with fields such as:
userId
(User ID)userName
(User Name)type
(User Type)userEmail
(Email Address)userContactNo
(Phone Number)dob
(Date of Birth)- Timestamps for record creation and modification
Column Name | Data Type | Description |
---|---|---|
userId | INT | Unique identifier for each user |
userName | VARCHAR(255) | User's full name |
type | ENUM | User type (ADMIN, INTERNAL, EXTERNAL) |
userEmail | VARCHAR(255) | User's email address |
userContactNo | VARCHAR(12) | User's phone number (e.g., 911234567890) |
dob | DATE | User's date of birth |
created_at | TIMESTAMP | Timestamp of record creation |
updated_at | TIMESTAMP | Timestamp of record modification |
The "User" table stores user-related information, including user IDs, names, types, contact information, date of birth, and timestamps for record creation and modification.
This database design ensures data integrity and provides a structured approach to managing user information within the application.
The project utilizes the following data structures:
The User
class defines the structure for user data and includes the following fields:
userId
(User ID): An integer that serves as a unique identifier for each user.userName
(User Name): A string representing the user's full name.type
(User Type): An enumeration specifying the user type, including ADMIN, INTERNAL, and EXTERNAL.userEmail
(Email Address): A string containing the user's email address.userContactNo
(Phone Number): A string representing the user's phone number (e.g., 911234567890).dob
(Date of Birth): A date field indicating the user's date of birth.- Timestamps for record creation and modification.
The Type
enum enumerates the possible user types:
ADMIN
: Represents an administrator user.INTERNAL
: Represents an internal user.EXTERNAL
: Represents an external user.
The project utilizes the ArrayList
data structure to store and manage lists of User
objects in various parts of the application. ArrayList
provides dynamic sizing and efficient element retrieval, making it suitable for storing user records and performing operations on them.
These data structures enable the application to organize and manipulate user data efficiently while maintaining data integrity.
The User Management project is a robust Spring Boot application designed for efficient user data management. It offers a set of RESTful API endpoints for various user-related operations, including adding, retrieving, updating, and deleting user information.
- Framework: Spring Boot
- Language: Java
- Build Tool: Maven
The Controller layer handles incoming HTTP requests and routes them to the appropriate services. It defines API endpoints for operations such as adding, retrieving, updating, and deleting user records.
The Services layer implements core business logic and data processing, including input validation, CRUD operations on user data, and data transformations.
The Repository layer manages data access to the underlying database, performing Create, Read, Update, and Delete (CRUD) operations for user data.
The database design includes tables for user management, featuring fields like userId
, userName
, type
, userEmail
, userContactNo
, dob
, and timestamps for record creation and modification.
- User Class: Defines the structure for user data, including user attributes and timestamps.
- Type Enum: Enumerates user types, such as ADMIN, INTERNAL, and EXTERNAL.
- ArrayList: Utilized for managing lists of
User
objects efficiently.
- RESTful API endpoints for user management.
- Data validation to ensure data integrity.
- Clean code separation with a layered architecture (Controller, Services, Repository).
- Robust error handling for improved reliability.
- Java-based backend and Maven for build management.
The User Management project serves as a practical example of Spring Boot application development, demonstrating best practices in API design and user data management. It offers a solid foundation for building and extending user management systems in various applications.
This project is licensed under the GNU General Public License v3.0.
Thank you to the Spring Boot and Java communities for providing excellent tools and resources.
For questions or feedback, please contact Amit Ashok Swain.