Skip to content

Commit 9756413

Browse files
author
Ivan Franchin
committed
replace MySQL with Postgres
1 parent 78c9366 commit 9756413

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# springboot-react-jwt-token
22

3-
The goal of this project is to implement an application called `order-app` to manage orders. For it, we will implement a back-end application called `order-api` using [`Spring Boot`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/) and a font-end application called `order-ui` using [ReactJS](https://reactjs.org/). Besides, we will use [`JWT Authentication`](https://en.wikipedia.org/wiki/JSON_Web_Token) to secure both applications.
3+
The goal of this project is to implement an application called `order-app` to manage orders. For it, we will implement a back-end [`Spring Boot`](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/) application called `order-api` and a font-end [ReactJS](https://reactjs.org/) application called `order-ui`. Besides, we will use [`JWT Authentication`](https://en.wikipedia.org/wiki/JSON_Web_Token) to secure both applications.
44

55
## Applications
66

@@ -10,7 +10,7 @@ The goal of this project is to implement an application called `order-app` to ma
1010

1111
The application secured endpoints can just be accessed if a valid JWT access token is provided.
1212

13-
`order-api` stores its data in [`MySQL`](https://www.mysql.com/) database.
13+
`order-api` stores its data in [`Postgres`](https://www.postgresql.org/) database.
1414

1515
`order-api` has the following endpoints
1616

@@ -46,15 +46,12 @@ The goal of this project is to implement an application called `order-app` to ma
4646

4747
## Start Environment
4848

49-
- Open a terminal and inside `springboot-react-jwt-token` root folder run
49+
- In a terminal, make sure you are inside `springboot-react-jwt-token` root folder
50+
51+
- Run the following command to start docker-compose containers
5052
```
5153
docker-compose up -d
5254
```
53-
54-
- Wait for `mysql` Docker container to be up and running. To check it, run
55-
```
56-
docker-compose ps
57-
```
5855

5956
## Running order-app using Maven & Npm
6057

@@ -248,10 +245,10 @@ The goal of this project is to implement an application called `order-app` to ma
248245
249246
## Util Commands
250247
251-
- **MySQL**
248+
- **Postgres**
252249
```
253-
docker exec -it -e MYSQL_PWD=secret mysql mysql -uroot --database orderdb
254-
show tables;
250+
docker exec -it postgres psql -U postgres -d moviedb
251+
\dt
255252
```
256253
257254
- **jwt.io**

docker-compose.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ version: '3.8'
22

33
services:
44

5-
mysql:
6-
image: mysql:8.0.32
7-
container_name: mysql
5+
postgres:
6+
image: postgres:15.2
7+
container_name: postgres
88
ports:
9-
- "3306:3306"
9+
- "5432:5432"
1010
environment:
11-
- MYSQL_ROOT_PASSWORD=secret
12-
- MYSQL_DATABASE=orderdb
11+
- POSTGRES_DB=orderdb
12+
- POSTGRES_PASSWORD=postgres
13+
- POSTGRES_USER=postgres
1314
healthcheck:
14-
test: "mysqladmin ping -u root -p$${MYSQL_ROOT_PASSWORD}"
15+
test: "pg_isready -U postgres"

order-api/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
</dependency>
3030
<dependency>
3131
<groupId>org.springframework.boot</groupId>
32-
<artifactId>spring-boot-starter-web</artifactId>
32+
<artifactId>spring-boot-starter-security</artifactId>
3333
</dependency>
3434
<dependency>
3535
<groupId>org.springframework.boot</groupId>
36-
<artifactId>spring-boot-starter-security</artifactId>
36+
<artifactId>spring-boot-starter-validation</artifactId>
3737
</dependency>
3838
<dependency>
3939
<groupId>org.springframework.boot</groupId>
40-
<artifactId>spring-boot-starter-validation</artifactId>
40+
<artifactId>spring-boot-starter-web</artifactId>
4141
</dependency>
4242

4343
<!-- JSON Web Token -->
@@ -74,8 +74,8 @@
7474
</dependency>
7575

7676
<dependency>
77-
<groupId>com.mysql</groupId>
78-
<artifactId>mysql-connector-j</artifactId>
77+
<groupId>org.postgresql</groupId>
78+
<artifactId>postgresql</artifactId>
7979
<scope>runtime</scope>
8080
</dependency>
8181
<dependency>

order-api/src/main/java/com/ivanfranchin/orderapi/repository/OrderRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public interface OrderRepository extends JpaRepository<Order, String> {
1111

1212
List<Order> findAllByOrderByCreatedAtDesc();
1313

14-
List<Order> findByIdContainingOrDescriptionContainingOrderByCreatedAt(String id, String description);
14+
List<Order> findByIdContainingOrDescriptionContainingIgnoreCaseOrderByCreatedAt(String id, String description);
1515
}

order-api/src/main/java/com/ivanfranchin/orderapi/service/OrderServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public List<Order> getOrders() {
2121

2222
@Override
2323
public List<Order> getOrdersContainingText(String text) {
24-
return orderRepository.findByIdContainingOrDescriptionContainingOrderByCreatedAt(text, text);
24+
return orderRepository.findByIdContainingOrDescriptionContainingIgnoreCaseOrderByCreatedAt(text, text);
2525
}
2626

2727
@Override

order-api/src/main/resources/application.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ spring:
55
hibernate:
66
ddl-auto: create
77
datasource:
8-
url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/orderdb?characterEncoding=UTF-8&serverTimezone=UTC
9-
username: root
10-
password: secret
8+
url: jdbc:postgresql://localhost:5432/orderdb
9+
username: postgres
10+
password: postgres
1111

1212
app:
1313
jwt:
@@ -22,3 +22,4 @@ app:
2222
logging:
2323
level:
2424
org.springframework.security: DEBUG
25+
# org.hibernate.SQL: DEBUG

0 commit comments

Comments
 (0)