- Getting Started
- Installation
- Challenge 1
- Challenge 2
- Challenge 3
- Challenge 4
- Challenge 5
- Challenge 6
- Installation JPA
- License
This is a collection of SpringBoot Java Backend Challenges, from learning the basics of Java, to creating a restAPI for a Back-End application with documentation using swagger
Makesure you already install :
- Integrated Development Environments (IDEs), you can install Idea Intellij Community
- Java Development Kit (JDK) (version 8 or higher)
- PostgreSql as a Database
- Maven as the build tool
This guide will help you set up a Java project in IntelliJ IDEA with JPA (Java Persistence API) and Spring Security.
- Open IntelliJ IDEA.
- Select
New Projectfrom the welcome screen. - Choose
Spring Initializras the project type. - Configure your project:
- Group:
com.example - Artifact:
myproject - Name:
myproject - Dependencies:
Spring Web,Spring Data JPA,Spring Security
- Group:
This project uses Maven as the build tool. The pom.xml file will be generated automatically if you use Spring Initializr. Ensure the following dependencies are in your pom.xml file:
<dependencies>
<!-- Spring Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Database (e.g., H2 Database) -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies># Database Configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
# JPA Properties
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
# Spring Security Properties (optional)
spring.security.user.name=admin
spring.security.user.password=admin
git clone <repository-url>
cd <repository-directory>
In this challenge, the restaurant ordering system is implemented using a procedural programming approach.
- Display a menu with various food and drink options.
- Allow users to select items and specify quantities.
- Calculate the total price of the order.
- Confirm and generate a receipt saved to a file (
struk_pembelian.txt).
- The application flow is controlled by a
whileloop that continues until the user decides to exit. - Menu selection is handled using a
switchstatement. - Orders and quantities are stored in
ArrayListobjects. - The total price is calculated dynamically as items are added to the order.
- Upon order confirmation, a receipt is generated and saved to a file.
In this challenge, the restaurant ordering system is refactored to use Object-Oriented Programming principles.
- Uses a
MenuItemclass to represent each menu item with a name and price. - Uses a
Restaurantclass to handle the main application logic. - The
Restaurantclass contains methods to display the menu, process orders, and generate receipts. - Improved error handling using
try-catchblocks.
MenuItemclass: Represents individual menu items.Restaurantclass: Contains methods to start the application, process user input, and handle orders.MainRestaurantclass: Contains themainmethod to launch the application.- Menu items are stored in a static list initialized in the
Restaurantclass. - Improved structure and readability by encapsulating related functionality within classes and methods.
- Import a HTML file and watch it magically convert to Markdown
- Drag and drop images (requires your Dropbox account be linked)
- Import and save files from GitHub, Dropbox, Google Drive and One Drive
- Drag and drop markdown and HTML files into Dillinger
- Export documents as Markdown, HTML and PDF
In this challenge contains a PostgreSQL database dump for a project focusing on DDL (Data Definition Language) operations, database integration, and instructions on how to run it. Below is an overview of the database structure and how to execute it.
The database dump includes the following tables:
- merchant: Stores information about merchants, including their name, location, and open status.
- orderdetail: Contains details of orders such as order ID, product ID, and quantity.
- orderentity: Manages order entities, including order time, destination address, user ID, and completion status.
- product: Stores product information like product name, price, and associated merchant ID.
- users: Contains user details such as username, email address, and password.
To set up and run this database, follow these steps:
- Install PostgreSQL: Ensure PostgreSQL is installed on your system. You can download PostgreSql
- Create a Database: After installing PostgreSQL, create a new database. You can do this via the PostgreSQL command line or a graphical tool like pgAdmin.
- Restore the Dump: Use the
pg_restorecommand or a tool like pgAdmin to restore the database dump provided in this repository into the newly created database. For example:pg_restore -U <username> -d <database_name> dump_file.dump
In this challenge, a JPA-based system is implemented to manage entities related to a restaurant ordering system. The implementation follows the principles of object-oriented programming and leverages Spring Data JPA for database interactions.
Abstract base entity class with common audit fields. Entity classes representing merchants, orders, products, order details, and users. Service layer for managing CRUD operations and business logic. Custom response handling for consistent API responses. Pagination support for retrieving data.
AbstrackFood is base class for common fields such as creation, deletion, and update timestamps.
-
Merchant: Represents a merchant with fields like id, merchant_name, merchant_location, and products.
-
Order: Represents an order with fields like id, order_time, destination_address, completed, and associated user.
-
OrderDetail: Represents order details with fields like id, quantity, total_price, and associated order and product.
-
Product: Represents a product with fields like id, product_name, price, and associated merchant.
-
User: Represents a user with fields like id, username, emailAddress, and password.
Each service class (MerchantServiceImpl, OrderServiceImpl, ProductServiceImpl, UserServiceImpl) provides CRUD operations along with pagination support for their respective entities (Merchant, Order, Product, User).
-
Merchant Controller:
- Manages CRUD operations for merchants.
- Provides endpoints for retrieving, adding, updating, and deleting merchants.
- Supports fetching a single merchant by ID.
-
Order Controller:
- Handles CRUD operations for orders.
- Offers functionalities to retrieve all orders, add new orders, update existing orders, delete orders, and fetch a single order by ID.
-
Product Controller:
- Manages products within the system.
- Provides endpoints for fetching all products, adding new products, updating existing products, deleting products, and retrieving a single product by ID.
-
User Controller:
- Facilitates user management functionalities.
- Offers endpoints for fetching all users, adding new users, updating existing users, deleting users, and retrieving a single user by ID.
- Each controller follows RESTful conventions with clear and descriptive endpoint paths.
- Annotations such as
@RestControllerand@RequestMappingare appropriately used to define controller components and base URL paths. - The controllers utilize various HTTP methods (
GET,POST,PUT,DELETE) to perform CRUD operations. - Request bodies (
@RequestBody) and path variables (@PathVariable) are effectively utilized for handling input data and dynamic parts of the URL. - Responses are returned as
ResponseEntityobjects, allowing precise control over HTTP status codes and response bodies. - Interaction with service classes ensures separation of concerns and modularity in the codebase.
InvoiceService is responsible for generating invoices and reports for merchants:
-
generateInvoice:
- This method creates a PDF file containing transaction details of user orders, serving as an invoice for the purchases made.
-
generateReportingMerchant:
- This method generates reports detailing the merchant's income over a specific period.