Skip to content
Open
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
196 changes: 158 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,162 @@

This is a sample Java / Maven / Spring Boot application which provides RESTful services. It can be used as a starter project. Currently it is designed to work as [this project](https://github.com/mertakdut/React-Sample-Project)'s backend.

---

## Installation Instructions
You can import the project as a maven application to your favorite IDE. I made my tests by using eclipse jee-2018-12.

If lombok gets in your way, by referring [this answer](https://stackoverflow.com/a/22332248/4130569), you can install lombok by its jar file.

## To run the application
Use one of the several ways of running a Spring Boot application. Below are just three options:

1. Build using maven goal (or by using maven wrapper): `mvn clean package` and execute the resulting artifact as follows `java -jar BankApplicationBackend-0.0.1-SNAPSHOT.jar` or
2. On Unix/Linux based systems: run `mvn clean package` then run the resulting jar as any other executable `./BankApplicationBackend-0.0.1-SNAPSHOT.jar`
3. Run as a [Docker](https://www.docker.com/) container.
1) Clone the repository.
2) cd to project root directory.
3) `docker build -t demo/bankapp .`
* If you get a `./mvnw not found` error, just run `mvn -N io.takari:maven:wrapper -Dmaven=3.5.3` while in the root directory of the project.
4) `docker run --expose 8080 -p 8080:8080 demo/bankapp`

## To test the application
1. Create a user with /api/user/create url.

`$ curl -X POST localhost:8080/api/user/create -d "{\"username\": \"yourUsername\", \"password\": \"yourPassword\", \"tcno\": \"12512561125\"}" -H "Content-Type:application/json"`
You'll get a response as in below.

`{"username":"yourUsername","tcno":"12512561125"}`
2. Generate an access token by /api/login url.

`$ curl -H "Content-Type: application/json" -X POST -d "{\"username\": \"yourUsername\", \"password\": \"yourPassword\"}" http://localhost:8080/api/login`

You'll be getting an access token similar to this.

`eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ5b3VyVXNlcm5hbWUiLCJleHAiOjE1NTI0NDMzNjZ9.0WSCg4vaP7BVeJz8tQnL3s-BYjBB6UWXlQKCZHm1_zqEVIiA8_71Ni7tbPDm2DbW-Qc_fPP9CQF1jKcRC9njFQ`

3. Use the token to access content available to all authenticated users, through the RESTful API.

Http.Get request example:
`curl -i -H "Accept: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ5b3VyVXNlcm5hbWUiLCJleHAiOjE1NTI0NDMzNjZ9.0WSCg4vaP7BVeJz8tQnL3s-BYjBB6UWXlQKCZHm1_zqEVIiA8_71Ni7tbPDm2DbW-Qc_fPP9CQF1jKcRC9njFQ" -X GET http://localhost:8080/api/user/find/all`

Http.Post request example:
`curl -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ5b3VyVXNlcm5hbWUiLCJleHAiOjE1NTI0NDMzNjZ9.0WSCg4vaP7BVeJz8tQnL3s-BYjBB6UWXlQKCZHm1_zqEVIiA8_71Ni7tbPDm2DbW-Qc_fPP9CQF1jKcRC9njFQ" -X POST -d "{\"username\": \"yourUsername\", \"buying\": \"true\", \"currency\": \"USD\", \"amount\": \"250\"}" http://localhost:8080/api/transaction/create`

You can import the project as a Maven application to your favorite IDE. The project was originally tested using **Eclipse JEE 2018-12**.

If Lombok causes issues in your IDE, you can install it manually by following [this StackOverflow answer](https://stackoverflow.com/a/22332248/4130569)

---

## Important Notes

### Java Version Requirement

⚠️ **This project requires Java 8**

This project was built and tested using **Java 8**. Running or building the project with **Java 9+ (including Java 17)** may result in compilation or test failures due to outdated dependencies and Java module system restrictions.

**Recommended Java version:** Java 8

---

### Docker Notes

The original Dockerfile uses the base image:

```dockerfile
openjdk:8-jdk-alpine
```

This image is **no longer available on Docker Hub**.

If you encounter Docker build issues, consider replacing it with:

```dockerfile
eclipse-temurin:8-jdk
```

`eclipse-temurin` is the official OpenJDK successor and works correctly with this project when using Java 8.

---

### Tests

Some tests may fail in modern environments due to legacy configuration and dependency behavior.

If the goal is to **build and run the application**, the project can be packaged successfully using:

```bash
mvn package -DskipTests
```

This allows the application to start even if certain legacy tests fail.

---

## To Run the Application

You can run the Spring Boot application using one of the following methods.

### 1️⃣ Run Using Maven

```bash
mvn clean package
java -jar target/BankApplicationBackend-0.0.1-SNAPSHOT.jar
```

### 2️⃣ Run on Unix / Linux Systems

```bash
mvn clean package
chmod +x target/BankApplicationBackend-0.0.1-SNAPSHOT.jar
./target/BankApplicationBackend-0.0.1-SNAPSHOT.jar
```

### 3️⃣ Run as a Docker Container

1. Clone the repository
2. Navigate to the project root directory
3. Build the Docker image:

```bash
docker build -t demo/bankapp .
```

**Note:** If you get a `./mvnw not found` error, run the following command in the project root directory:

```bash
mvn -N io.takari:maven:wrapper -Dmaven=3.5.3
```

4. Run the container:

```bash
docker run --expose 8080 -p 8080:8080 demo/bankapp
```

---

## To Test the Application

### 1️⃣ Create a User

```bash
curl -X POST http://localhost:8080/api/user/create \
-H "Content-Type: application/json" \
-d '{
"username": "yourUsername",
"password": "yourPassword",
"tcno": "12512561125"
}'
```

**Response:**

```json
{
"username": "yourUsername",
"tcno": "12512561125"
}
```

### 2️⃣ Generate an Access Token

```bash
curl -H "Content-Type: application/json" \
-X POST \
-d '{"username": "yourUsername", "password": "yourPassword"}' \
http://localhost:8080/api/login
```

You will receive a JWT token similar to:

```
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9...
```

### 3️⃣ Access Protected APIs Using the Token

**HTTP GET Example:**

```bash
curl -i \
-H "Accept: application/json" \
-H "Authorization: Bearer <TOKEN>" \
-X GET http://localhost:8080/api/user/find/all
```

**HTTP POST Example:**

```bash
curl -H "Content-Type: application/json" \
-H "Authorization: Bearer <TOKEN>" \
-X POST \
-d '{"username": "yourUsername", "buying": "true", "currency": "USD", "amount": "250"}' \
http://localhost:8080/api/transaction/create
```

**Note:** Replace `<TOKEN>` with the actual JWT token received from the login endpoint.