Mini Project 1
Mini Project 1
Mini Project 1
Deadline is Friday 07/03/2025 11:59 PM
1 Introduction
This project is a basic application using Spring Boot. It consists of four main models: User, Product,
Cart, and Order. Each model has a corresponding repository, service, and controller. The objective is
to implement missing methods in the service, repository, and controller files.
2 Installation
You Should clone the project from this link: https://github.com/Scalable2025/Mini-Project1-Base.git
then structure the project as follows
3 Project Structure
The project follows a standard Spring Boot architecture. Please name the packages as the same
names mentioned below:
|- src
| |-main/java/com/example
| | |-MiniProject1
| | | |-MiniProject1Application.java
| | |-data
| | | |- users.json
| | | |- products.json
| | | |- carts.json
| | | |- orders.json
| | |- model
| | | |- User.java
| | | |- Product.java
| | | |- Cart.java
| | | |- Order.java
| | |- repository
| | | |- UserRepository.java
| | | |- ProductRepository.java
| | | |- CartRepository.java
| | | |- OrderRepository.java
| | |- service
| | | |- UserService.java
| | | |- ProductService.java
1
| | | |- CartService.java
| | | |- OrderService.java
| | |- controller
| | | |- UserController.java
| | | |- ProductController.java
| | | |- CartController.java
| | | |- OrderController.java
| |-test/java/com/example
| | |-MiniProject1ApplicationTests.java
4 Data
In folder data there are json files for every model in the project where the objects of each class should be
stored. For example users.json will contain the users you add by your methods like addUser() and you
will get these users also by methods like getUsers()
5 Models
All the Models must include the getters and setter for all the attributes present in the models. Also, your
implementation should include 3 constructors for each class as implemented in Lab 1.
5.1 User
Represents individual customers. Each user has a unique identifier, a name, and a list of their orders.
@Component
public class User {
private UUID id;
private String name;
private List<Order> orders=new ArrayList<>();
}
5.2 Product
Defines items available for purchase, with attributes like a unique identifier, name, and price.
@Component
public class Product {
private UUID id;
private String name;
private double price;
}
5.3 Cart
Acts as a temporary storage for products that users intend to buy. Each cart is associated with a user
and maintains a list of products.
@Component
public class Cart {
private UUID id;
private UUID userId;
2
private List<Product> products=new ArrayList<>();
}
5.4 Order
Captures finalized orders. An order includes a unique identifier, the associated user’s identifier, the total
price, and a list of purchased products.
@Component
public class Order {
private UUID id;
private UUID userId;
private double totalPrice;
private List<Product> products=new ArrayList<>();
}
6 Repositories
You should implement standard CRUD operations.
6.2 UserRepository
The repository that will interact with the users JSON file.
@Repository
@SuppressWarnings("rawtypes")
public class UserRepository extends MainRepository<User>{
}
}
3
public ArrayList<User> getUsers();
6.3 ProductRepository
The repository that will interact with the products JSON file.
@Repository
@SuppressWarnings("rawtypes")
public class ProductRepository extends MainRepository<Product> {
4
public ProductRepository() {
}
}
6.4 CartRepository
The repository that will interact with the carts JSON file.
5
6.4.1 Class
@Repository
@SuppressWarnings("rawtypes")
public class CartRepository extends MainRepository<Cart> {
public CartRepository(){
}
}
6
6.4.2.7 Delete the Cart
To delete a specific cart by passing its ID.
6.5 OrderRepository
The repository that will interact with the orders JSON file.
@Repository
@SuppressWarnings("rawtypes")
public class OrderRepository extends MainRepository<Order> {
public OrderRepository() {
}
}
7
7 Services
All logic, aside from interacting with the JSON files, should be handled in the services.
7.2 UserService
The service handling the functionalities related to the User.
@Service
@SuppressWarnings("rawtypes")
public class UserService extends MainService<User>{
//The Constructor with the requried variables mapping the Dependency Injection.
8
7.2.2.5 Add a New Order
Here the user checks out his cart by creating a new order. The user should empty his cart and calculate
everything related to his order and add the new order to his list of orders.
7.3 ProductService
The service handling the functionalities related to the Product.
@Service
@SuppressWarnings("rawtypes")
public class ProductService extends MainService<Product> {
//The Constructor with the requried variables mapping the Dependency Injection.
9
public ArrayList<Product> getProducts();
7.4 CartService
The service handling the functionalities related to the Cart.
@Service
@SuppressWarnings("rawtypes")
public class CartService extends MainService<Cart>{
//The Constructor with the requried variables mapping the Dependency Injection.
}
10
7.4.2.2 Get All Carts
To get all the carts in our system.
7.5 OrderService
The service handling the functionalities related to the Order.
@Service
@SuppressWarnings("rawtypes")
public class OrderService extends MainService<Order> {
//The Constructor with the requried variables mapping the Dependency Injection.
}
11
7.5.2 Required Methods
8 Controllers
You should implement RESTful endpoints. And Please Do not change the RequestMap-
ping paths keep it as it is
8.1 UserController
@RestController
@RequestMapping("/user")
public class UserController {
//The Constructor with the requried variables mapping the Dependency Injection.
12
8.1.2 Required Endpoints
13
8.1.2.8 Add Product To the Cart
Put Request to add a specific product to the cart by passing their IDs in the request
body.
@PutMapping("/addProductToCart")
public String addProductToCart(@RequestParam UUID userId, @RequestParam UUID productId);
8.2 ProductController
8.2.1 Class
@RestController
@RequestMapping("/product")
public class ProductController {
//The Constructor with the requried variables mapping the Dependency Injection.
14
@GetMapping("/")
public ArrayList<Product> getProducts();
8.3 CartController
8.3.1 Class
@RestController
@RequestMapping("/cart")
public class CartController {
//The Constructor with the requried variables mapping the Dependency Injection.
15
}
8.4 OrderController
@RestController
@RequestMapping("/order")
16
public class OrderController {
//The Constructor with the requried variables mapping the Dependency Injection.
9 Docker
Create dockerfile for your project and handle mounting the data.json files as explained in
the labs. Also you should change the environment variables in the Dockerfile to be the
new path of the json files in the container
17
10 Test Cases
For each API that you will write you have to write 3 Unit Test cases for each Service
that you will implement. You have in the project 25 Service which means you
are required to implement 75 unit test cases in a new test case file other than the
public commented ones. To run the public API tests, uncomment the code in the test file
then run mvn test in terminal
11 Submission
Create a repository for your Project with separate branches for each team member with the
Main branch for integrating your work. Your repository name should be Your Team Num-
ber - your Team name (e.g. 100-Random_01). Then add **Scalable-Submissions** OR
**[email protected]** as colaborator to your repository. Your history of com-
mits will be monitored as an indication for the participation for all the team members so
make sure you divide the work equally among you.
18