Skip to content

Commit

Permalink
Refactored README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nklimovych committed Jun 10, 2024
1 parent 16ba463 commit 09c99ad
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
73 changes: 46 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,19 @@ this project sets the stage for a smooth and secure online book shopping experie
* User Profile Management: Customize your literary journey with personalized settings.
* Secure RESTful API Endpoints: Fortified endpoints, ensuring safe passage for data travelers.

## Demo video

[![Video Title](/images/video_cover_image.png)](https://youtu.be/76rQ1n_4F8s)


## Installation

1. Clone the repository:
```bash
git clone https://github.com/nklimovych/book-store.git
cd book-store
```
2. Configure the database: Create a new MySQL database:
```sql
CREATE DATABASE bookstore;
```
Update the `application.properties` file with your MySQL database credentials:
```properties
spring.datasource.url=jdbc:mysql://localhost:3306/bookstore
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
spring.jpa.open-in-view=false
```
3. Set Environment Variables:
2. Set Environment Variables:

Create a `.env` file in the project root directory and populate it with the following
environment variables:
Expand All @@ -78,21 +70,16 @@ this project sets the stage for a smooth and secure online book shopping experie
JWT_SECRET=JustAnotherSuperSecretString1234!
JWT_EXPIRATION=3600000
```
4. Install dependencies and build the project:
3. Build and Run the Docker Containers:

```bash
mvn clean install
docker-compose up --build
```
5. Build and Run the Docker Containers:
4. Access the Application:

```bash
docker-compose up
```
6. Access the Application:

Open your browser and go to `http://localhost:8080/api/swagger-ui/index.html#/`
Open your browser and go to http://localhost:8080/api/swagger-ui/index.html#/
to access the Swagger API documentation.
7. Stop and Remove Containers:
5. Stop and Remove Containers:

To stop and remove the containers created by the Compose file, use the
docker-compose down command:
Expand All @@ -107,7 +94,7 @@ Explore the detailed API documentation generated by Swagger to understand the va
and their functionalities.

<details>
<summary><h3>How to Use Swagger for API Testing</h3></summary>
<summary><h3>How to Use JWT token to test endpoints with Swagger API (click to view)</h3></summary>
<p>Follow the next steps:</p>
<ul>
<li>
Expand Down Expand Up @@ -167,13 +154,20 @@ and their functionalities.
"shippingAddress": "Main St. 57, Lviv"
}
```
* Authenticate a user: `POST /api/auth/login`
* Authenticate as user: `POST /api/auth/login`
```json
{
"email": "user@mail.com",
"password": "password"
}
```
* If you want to use admin endpoints, fill free to use credentials below:
```json
{
"email": "admin@mail.com",
"password": "password"
}
```
### 📚 Book Endpoints
Expand Down Expand Up @@ -209,4 +203,29 @@ and their functionalities.
---
### Author: [Nazar Klimovych](https://github.com/nklimovych) | [LinkedIn](https://www.linkedin.com/in/klimovych/)
## 👊 Faced Challenges
### Challenge 1: Database Migrations
Problem: Managing database changes consistently across different environments.
Solution: Used Liquibase to automate database migrations.
Steps:
* Created changelog files for database changes.
* Configured Liquibase to run these changelogs during application startup.
### Challenge 2: Dockerizing the Application
Problem: Ensuring consistent and reliable environments for development, testing, and production.
Solution: Used Docker to containerize the application and its dependencies.
Steps:
* Created Dockerfiles to define the application and database images.
* Used docker-compose to set up and manage a multi-container environment.
* Tested the application in a Dockerized environment to ensure consistency across different stages.
---
### 🥷 Author: [Nazar Klimovych](https://github.com/nklimovych) | [LinkedIn](https://www.linkedin.com/in/klimovych/)
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

services:
mysqldb:
image: mysql:8
Expand Down
Binary file added images/video_cover_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public interface BookRepository extends JpaRepository<Book, Long>, JpaSpecificat
@EntityGraph(attributePaths = {"categories"})
Optional<Book> findBookByIsbn(String isbn);

@Query("FROM Book b JOIN FETCH b.categories WHERE b.id = :id")
@Query("SELECT b FROM Book b LEFT JOIN FETCH b.categories "
+ "WHERE b.id = :id AND b.isDeleted = false")
Optional<Book> findBookById(Long id);

@Query("SELECT b FROM Book b LEFT JOIN FETCH b.categories c WHERE c.id = :categoryId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ databaseChangeLog:
columns:
- column:
name: email
value: "admin@gmail.com"
value: "admin@mail.com"
- column:
name: password
value: "$2a$10$jylhh5qCNXLrDdpPLTWmvOxGJeDTWQiSS5rN8v5b0G12QF1FlgeCe"
value: "$2a$10$fwNUUs7aPvI8Z3AdDOP/yuVM0oQSia9kR4eeWmlKBkH9boR6tunL."
- column:
name: first_name
value: "Admin"
Expand All @@ -20,4 +20,4 @@ databaseChangeLog:
value: "User"
- column:
name: shipping_address
value: "Truskavetska st. 117, Lviv"
value: "Main St. 99, Lviv"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ databaseChangeLog:
columns:
- column:
name: user_id
valueComputed: (SELECT id FROM users WHERE email = 'admin@gmail.com')
valueComputed: (SELECT id FROM users WHERE email = 'admin@mail.com')
- column:
name: role_id
valueComputed: (SELECT id FROM roles WHERE name = 'ADMIN')

0 comments on commit 09c99ad

Please sign in to comment.