Skip to content

feat: add spring-mysql-redis to samples java #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spring-mysql-redis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

/.idea/
/target/
/keploy/reports/
142 changes: 142 additions & 0 deletions spring-mysql-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Todo Spring Application

This is a simple Todo application built with Spring Boot, PostgreSQL, and Redis. The application provides RESTful APIs to manage Todo items.

## Prerequisites

- Java 8
- Maven
- Docker

## Installation

### 1. Clone the Repository

```sh
git clone https://github.com/yourusername/todo-spring-app.git
cd todo-spring-app
```

### 2. Build the Application

```sh
mvn clean install
```

### 3. Set Up Docker Containers

#### PostgreSQL Container

1. Pull the MySQL Docker Image:

```sh
docker pull mysql:latest
```

2. un the MySQL Container:

```sh
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
```

#### Redis Container

1. Pull the Redis Docker Image:

```sh
docker pull redis:latest
```

2. Run the Redis Container:

```sh
docker run --name redis-todo -p 6379:6379 -d redis:latest
```

### 4. Configure Application Properties

Update the src/main/resources/application.properties file with your MySQL username and password:

```properties
spring.datasource.url=jdbc:mysql://localhost:3306/todoapp?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
spring.datasource.username=yourusername
spring.datasource.password=yourpassword
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update

spring.redis.host=localhost
spring.redis.port=6379
```

### 5. Run the Application

```sh
mvn spring-boot:run
```

## Database Setup

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:

```sql
CREATE TABLE todo (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
completed BOOLEAN NOT NULL DEFAULT FALSE
);
```

## Usage

### API Endpoints

#### Create a Todo Item

```sh
curl -X POST http://localhost:8080/api/todos \
-H "Content-Type: application/json" \
-d '{
"title": "Learn Spring Boot",
"description": "Read the Spring Boot documentation and write some sample code",
"completed": false
}'
```

#### Get All Todo Items

```sh
curl -X GET http://localhost:8080/api/todos
```

#### Get a Todo Item by ID

```sh
curl -X GET http://localhost:8080/api/todos/{id}
```
Replace `{id}` with the actual ID of the Todo item you want to retrieve.

#### Update a Todo Item

```sh
curl -X PUT http://localhost:8080/api/todos/{id} \
-H "Content-Type: application/json" \
-d '{
"title": "Learn Spring Boot",
"description": "Read the Spring Boot documentation and write a comprehensive project",
"completed": true
}'
```
Replace `{id}` with the actual ID of the Todo item you want to update.

#### Delete a Todo Item

```sh
curl -X DELETE http://localhost:8080/api/todos/{id}
```
Replace `{id}` with the actual ID of the Todo item you want to delete.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Loading
Loading