Skip to content

Commit 6c22ff7

Browse files
authored
feat: add spring-mysql-redis to samples java (#78)
* feat:Add spring-mysql-redis to samples java Signed-off-by: Hermione Dadheech <[email protected]> * remove .idea and target folder Signed-off-by: Hermione Dadheech <[email protected]> * add .idea and target to gitignore Signed-off-by: Hermione Dadheech <[email protected]> * add .idea and target to gitignore Signed-off-by: Hermione Dadheech <[email protected]> * remove reports from .gitignore Signed-off-by: Hermione Dadheech <[email protected]> --------- Signed-off-by: Hermione Dadheech <[email protected]>
1 parent 746082e commit 6c22ff7

File tree

28 files changed

+35160
-0
lines changed

28 files changed

+35160
-0
lines changed

spring-mysql-redis/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
/.idea/
3+
/target/
4+
/keploy/reports/

spring-mysql-redis/README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Todo Spring Application
2+
3+
This is a simple Todo application built with Spring Boot, PostgreSQL, and Redis. The application provides RESTful APIs to manage Todo items.
4+
5+
## Prerequisites
6+
7+
- Java 8
8+
- Maven
9+
- Docker
10+
11+
## Installation
12+
13+
### 1. Clone the Repository
14+
15+
```sh
16+
git clone https://github.com/yourusername/todo-spring-app.git
17+
cd todo-spring-app
18+
```
19+
20+
### 2. Build the Application
21+
22+
```sh
23+
mvn clean install
24+
```
25+
26+
### 3. Set Up Docker Containers
27+
28+
#### PostgreSQL Container
29+
30+
1. Pull the MySQL Docker Image:
31+
32+
```sh
33+
docker pull mysql:latest
34+
```
35+
36+
2. un the MySQL Container:
37+
38+
```sh
39+
docker run --name mysql-todo -e MYSQL_DATABASE=todoapp -e MYSQL_USER=yourusername -e MYSQL_PASSWORD=yourpassword -e MYSQL_ROOT_PASSWORD=rootpassword -p 3306:3306 -d mysql:latest
40+
```
41+
42+
#### Redis Container
43+
44+
1. Pull the Redis Docker Image:
45+
46+
```sh
47+
docker pull redis:latest
48+
```
49+
50+
2. Run the Redis Container:
51+
52+
```sh
53+
docker run --name redis-todo -p 6379:6379 -d redis:latest
54+
```
55+
56+
### 4. Configure Application Properties
57+
58+
Update the src/main/resources/application.properties file with your MySQL username and password:
59+
60+
```properties
61+
spring.datasource.url=jdbc:mysql://localhost:3306/todoapp?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
62+
spring.datasource.username=yourusername
63+
spring.datasource.password=yourpassword
64+
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
65+
spring.jpa.hibernate.ddl-auto=update
66+
67+
spring.redis.host=localhost
68+
spring.redis.port=6379
69+
```
70+
71+
### 5. Run the Application
72+
73+
```sh
74+
mvn spring-boot:run
75+
```
76+
77+
## Database Setup
78+
79+
The necessary schema for the Todo application will be created automatically by Hibernate. However, you can manually create the table using the following SQL script:
80+
81+
```sql
82+
CREATE TABLE todo (
83+
id SERIAL PRIMARY KEY,
84+
title VARCHAR(255) NOT NULL,
85+
description TEXT,
86+
completed BOOLEAN NOT NULL DEFAULT FALSE
87+
);
88+
```
89+
90+
## Usage
91+
92+
### API Endpoints
93+
94+
#### Create a Todo Item
95+
96+
```sh
97+
curl -X POST http://localhost:8080/api/todos \
98+
-H "Content-Type: application/json" \
99+
-d '{
100+
"title": "Learn Spring Boot",
101+
"description": "Read the Spring Boot documentation and write some sample code",
102+
"completed": false
103+
}'
104+
```
105+
106+
#### Get All Todo Items
107+
108+
```sh
109+
curl -X GET http://localhost:8080/api/todos
110+
```
111+
112+
#### Get a Todo Item by ID
113+
114+
```sh
115+
curl -X GET http://localhost:8080/api/todos/{id}
116+
```
117+
Replace `{id}` with the actual ID of the Todo item you want to retrieve.
118+
119+
#### Update a Todo Item
120+
121+
```sh
122+
curl -X PUT http://localhost:8080/api/todos/{id} \
123+
-H "Content-Type: application/json" \
124+
-d '{
125+
"title": "Learn Spring Boot",
126+
"description": "Read the Spring Boot documentation and write a comprehensive project",
127+
"completed": true
128+
}'
129+
```
130+
Replace `{id}` with the actual ID of the Todo item you want to update.
131+
132+
#### Delete a Todo Item
133+
134+
```sh
135+
curl -X DELETE http://localhost:8080/api/todos/{id}
136+
```
137+
Replace `{id}` with the actual ID of the Todo item you want to delete.
138+
139+
## License
140+
141+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
142+

0 commit comments

Comments
 (0)