The Stock Management Application is a Spring Boot-based CRUD (Create, Read, Update, Delete) application for managing stocks. It allows you to add, update, and retrieve stock data with various operations. This README provides information about the application's architecture, endpoints, and database configuration.
- Technologies Used
- Dependencies
- Architecture
- Data Flow
- Endpoints
- Database Table
- Data Structures
- Database Configuration
- Usage
- License
- Contact
- Framework: Spring Boot
- Language: Java 21
- Build Tool: Apache Maven 4.0.0
The Stock Management Application project relies on the following dependencies:
-
Spring Boot Starter Data JPA
- Description: Provides support for JPA (Java Persistence API) and simplifies database access using Spring Data repositories.
- Maven Dependency:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
-
Spring Boot Starter Validation
- Description: Includes validation support for request data binding and response data rendering.
- Maven Dependency:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency>
-
Spring Boot Starter Web
- Description: Provides support for building web applications, including RESTful APIs.
- Maven Dependency:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
-
H2 Database (Runtime Dependency)
- Description: An in-memory database for development and testing.
- Maven Dependency:
<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency>
-
Project Lombok (Optional)
- Description: A library that simplifies Java code by reducing boilerplate code, such as getters and setters.
- Maven Dependency:
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
-
Spring Boot Maven Plugin
- Description: A plugin for building and packaging Spring Boot applications.
- Maven Plugin Configuration (in your project's
pom.xml
):<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
-
Controller Layer
The
StockController
handles HTTP requests related to stocks and routes them to theStockService
.// StockController.java @RestController @RequestMapping("/stocks") public class StockController { // Define stock-related endpoints and methods }
-
Service Layer
The
StockService
contains business logic and interacts with theStockRepository
to perform CRUD operations on stock data.// StockService.java @Service public class StockService { // Implement stock-related service methods }
-
Repository Layer
The
StockRepository
manages data access to the stock entity using Spring Data JPA.// StockRepository.java @Repository public interface StockRepository extends JpaRepository<Stock, Long> { // Define custom queries or repository methods if needed }
-
Stock Entity
The
Stock
entity represents the structure of stock data in the database.// Stock.java (Stock Entity) @Entity public class Stock { // Define stock attributes, getters, setters, etc. }
The application follows the MVC (Model-View-Controller) architectural pattern. Key components include:
- Controller: Handles HTTP requests and routes them to appropriate services.
- Service: Contains business logic and interacts with the repository.
- Model: Represents the data structures (e.g.,
Stock
entity andStockType
enum). - Repository: Performs database operations using Spring Data JPA.
- HTTP Method: GET
- Endpoint:
/stock/by-type/{stockType}
- Description: Retrieves stocks by their type.
- Example:
/stock/by-type/ENERGY
- HTTP Method: GET
- Endpoint:
/stock/abovePrice/price/{price}/lowerDate/date/{date}
- Description: Retrieves stocks above a specific price and before a given date.
- Example:
/stock/abovePrice/price/100/lowerDate/date/2023-01-01T00:00:00
- HTTP Method: GET
- Endpoint:
/stock/cap/{capPercentage}
- Description: Retrieves stocks with a market cap above a certain percentage.
- Example:
/stock/cap/10.0
- HTTP Method: POST
- Endpoint:
/stock/stocks
- Description: Inserts a list of stocks into the database.
- Request Body: List of
Stock
objects.
- HTTP Method: PUT
- Endpoint:
/stock/marketCap/{marketCap}/id/{id}
- Description: Updates the market cap of a specific stock by ID.
- Example:
/stock/marketCap/500.0/id/1
- HTTP Method: PUT
- Endpoint:
/stock/stock/type/id
- Description: Updates the stock type by ID.
- Request Parameters:
stockType
(String) andid
(Integer).
- HTTP Method: PUT
- Endpoint:
/stock/stock/{id}
- Description: Updates a stock by ID.
- Request Body:
Stock
object with updated data.
- HTTP Method: DELETE
- Endpoint:
/stock/ownerCount/{count}
- Description: Deletes stocks based on the owner count.
- Example:
/stock/ownerCount/5
The application uses a MySQL database to store stock data. Below is the description of the Stock
table:
Column Name | Data Type | Description |
---|---|---|
stockId (Primary) | INT (Auto Increment) | Unique identifier for each stock |
stockName (Unique) | VARCHAR(255) | Name of the stock |
stockPrice | DOUBLE | Price of the stock |
stockOwnerCount | INT | Owner count of the stock |
stockType | ENUM | Type of the stock (enum values defined in code) |
stockMarketCap | DOUBLE | Market capitalization of the stock |
stockBirthTimeStamp | DATETIME | Timestamp of when the stock was created |
The Stock
class defines the structure for stock data and includes fields such as id
, name
, quantity
, and price
.
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Stock {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private Integer quantity;
private BigDecimal price;
// Define relationships, getters, setters, etc.
}
To configure the database, modify the application.properties
file with your database connection details:
spring.datasource.url=jdbc:mysql://localhost:3306/mappings
spring.datasource.username=root
spring.datasource.password=9892321787@As
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
Ensure that your MySQL database server is running and the credentials match your database setup.
- Start the Spring Boot application.
- Access the provided API endpoints to perform CRUD operations on stocks.
This project is licensed under the BSD 3-Clause License.
For questions or feedback, please contact Amit Ashok Swain.