Skip to content
Open
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
23 changes: 23 additions & 0 deletions CHANGLOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Change Log

## Version 1.0

### Added
Created REST API using Spring Boot
Added Oracle XE database connection
Added conversion endpoint
Added history save functionality
Added get all history endpoint
Added get history by ID endpoint
Added update history endpoint
Added delete history endpoint
Added README documentation

### Updated
Updated application properties configuration
Improved service layer logic

### Fixed
Fixed database save issue
Fixed update endpoint issues
Fixed delete endpoint response
185 changes: 124 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,124 @@
## Submission Instructions

To submit your Oracle JAVA Spring Boot Maven project as a solution, please follow these steps:

### Step 1: Install git on your PC
- Install "git" as shown in this tutorial: [How to install git](https://youtu.be/iYkLrXobBbA?si=_l0haibv_X9NpIjJ)
- Open command prompt and run
```bash
git version
```
- If you see the version, then git is successfully installed.

### Step 2: Fork the Repository
- Navigate to [this repository](https://github.com/CodelineAtyab/oraclequantapi) provided by Codeline.
- Click on the "Fork" button at the top-right corner of the page to create a copy of the repository under your own GitHub account.

### Step 3: Clone the Forked Repository
- Open your terminal or command prompt.
- Clone the forked repository to your local machine using the following command:
```bash
git clone https://github.com/your-username/repo-name.git
```

### Step 4: Create a new branch
- Navigate to the cloned repository directory
```bash
cd repo-name
```
- Create a new branch for your code submissions (Replace your-name with your name in your-name-submission-branch):
```bash
git checkout -b your-name-submission-branch
```


### Step 5: Add Your Code
- Implement the API

### Step 6: Commit your changes
- Run the following commands in order to commit your changes:
```bash
git add *
git commit -m "Meaningful commit message here"
```

### Step 7: Push Your Branch to GitHub
- Run the following commands to upload the changes to the forked github repository (Replace your-name with your name in your-name-submission-branch):
```bash
git push origin your-name-submission-branch
```

### Step 8: Create a Pull Request
- Go to your forked repository on GitHub.
- You should see a prompt to create a pull request. Click on "Compare & pull request".
- Provide a title and description for your pull request, then click "Create pull request".

### Step 9: Notify Codeline
- Notify on slack that you have created a PR for your solution.

## Note: If you face any issues in the process above, Please do the following:
- Watch [this youtube tutorial](https://www.youtube.com/watch?v=a_FLqX3vGR4)
- Contact Ikhlas or Atyab.
# History Conversion API

A Spring Boot REST API that converts input strings into numeric values and stores the conversion history in an Oracle XE database.

---

## Features

Convert input strings into numeric output
Save conversion history in Oracle XE
Get all history records
Get a history record by ID
Update a history record
Delete a history record
REST API using Spring Boot

---

## Technologies Used

Java 17
Spring Boot
Maven
Oracle XE
Docker
Postman

---

## API Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/convert-measurements?input=aa` | Convert input and save history |
| GET | `/history` | Get all history |
| GET | `/history/{id}` | Get history by ID |
| PUT | `/history/{id}` | Update history |
| DELETE | `/history/{id}` | Delete history |

---

## Example Request

### Convert Input
```http
GET http://localhost:8080/convert-measurements?input=aa
```

### Example Response
```json
[1]
```

---

## Update Example

### Request
```http
PUT http://localhost:8080/history/1
```

### Body
```json
{
"input": "updated",
"output": "[99]",
"sourceIpAddress": "127.0.0.1",
"timestamp": "updated"
}
```

---

## Delete Example

### Request
```http
DELETE http://localhost:8080/history/1
```

### Response
```text
History record deleted successfully
```

---

## Database Configuration

```properties
spring.datasource.url=jdbc:oracle:thin:@localhost:1521/XEPDB1
spring.datasource.username=system
spring.datasource.password=29999login
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
```

---

## Running the Project

```bash
mvn spring-boot:run
```

The application will run on:

```text
http://localhost:8080
```

---

## Testing

The API was tested using Postman for:
GET
PUT
DELETE

All endpoints worked successfully.
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public static void main(String[] args) {
SpringApplication.run(OraclequantapiApplication.class, args);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.oraclequantapi.oraclequantapi.controllers;

import com.oraclequantapi.oraclequantapi.services.ConversionService;
import com.oraclequantapi.oraclequantapi.services.HistoryService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ConversionController {

private final ConversionService conversionService;
private final HistoryService historyService;

public ConversionController(ConversionService conversionService, HistoryService historyService) {
this.conversionService = conversionService;
this.historyService = historyService;
}

@GetMapping("/convert-measurements")
public List<Integer> convertMeasurements(@RequestParam String input, HttpServletRequest request) {

List<Integer> result = conversionService.convertMeasurements(input);

historyService.saveHistory(input, result.toString(), request.getRemoteAddr());

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.oraclequantapi.oraclequantapi.controllers;

import com.oraclequantapi.oraclequantapi.models.HistoryRecord;
import com.oraclequantapi.oraclequantapi.services.HistoryService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/history")
public class HistoryController {

private final HistoryService historyService;

public HistoryController(HistoryService historyService) {
this.historyService = historyService;
}

@GetMapping
public List<HistoryRecord> getAllHistory() {
return historyService.getAllHistory();
}

@GetMapping("/{id}")
public HistoryRecord getHistoryById(@PathVariable Long id) {
return historyService.getHistoryById(id);
}

@PutMapping("/{id}")
public HistoryRecord updateHistory(@PathVariable Long id,
@RequestBody HistoryRecord updatedRecord) {
return historyService.updateHistory(id, updatedRecord);
}

@DeleteMapping
public String clearHistory() {
historyService.clearHistory();
return "History cleared successfully";
}

@DeleteMapping("/{id}")
public String deleteHistoryById(@PathVariable Long id) {
historyService.deleteHistoryById(id);
return "History record deleted successfully";
}
}
Loading