Commit 2356d4c0 authored by Mahesh Rohra's avatar Mahesh Rohra

Read data from PostgreSQL database

parent 4bd17d0e
...@@ -29,6 +29,7 @@ dependencies { ...@@ -29,6 +29,7 @@ dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools' developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql' runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
compile 'com.vladmihalcea:hibernate-types-52:2.0.0'
testImplementation('org.springframework.boot:spring-boot-starter-test') { testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
} }
......
package com.safeway.epe.controller;
import com.safeway.epe.domain.TransactionRecorder;
import com.safeway.epe.service.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class TransactionController
{
@Autowired
private TransactionService service;
/*@GetMapping("transactions")
public ResponseEntity<List<TransactionController>> getAllTransactions()
{
return service.getAllTransactions();
}*/
@GetMapping("transaction/{uuid}")
public ResponseEntity<TransactionRecorder> getTransaction(@PathVariable("uuid") String uuid)
{
return service.getTransactionById(uuid);
}
}
package com.safeway.epe.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.UUID;
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "transaction_recorder")
@TypeDef(
name = "jsonb",
typeClass = JsonBinaryType.class
)
public class TransactionRecorder
{
@Id
@Column(name = "uuid")
@JsonProperty("uuid")
UUID uuid;
@Type(type = "jsonb")
@JsonProperty("offertransactionresponse")
@Column(name = "offertransactionresponse")
String offerTransactionResponse;
@Type(type="jsonb")
@JsonProperty("offers")
@Column(name="offers")
String offers;
@Column(name="isprocessed")
boolean isProcessed;
}
package com.safeway.epe.repository;
import com.safeway.epe.domain.TransactionRecorder;
import com.safeway.epe.service.TransactionService;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
@Repository
public interface TransactionRepository extends CrudRepository<TransactionRecorder, UUID>
{
}
package com.safeway.epe.service;
import com.safeway.epe.controller.TransactionController;
import com.safeway.epe.domain.TransactionRecorder;
import org.springframework.http.ResponseEntity;
import java.util.List;
public interface TransactionService
{
//ResponseEntity<List<TransactionController>> getAllTransactions();
ResponseEntity<TransactionRecorder> getTransactionById(String uuid);
}
package com.safeway.epe.service;
import com.safeway.epe.controller.TransactionController;
import com.safeway.epe.domain.TransactionRecorder;
import com.safeway.epe.repository.TransactionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class TransactionServiceImpl implements TransactionService
{
@Autowired
TransactionRepository repository;
/*@Override
public ResponseEntity<List<TransactionController>> getAllTransactions() {
List<TransactionRecorder> transactions = new ArrayList<TransactionRecorder>();
repository.findAll().forEach(transactions::add);
return new ResponseEntity<List<TransactionController>>(HttpStatus.OK);
}*/
@Override
public ResponseEntity<TransactionRecorder> getTransactionById(String uuid) {
Optional<TransactionRecorder> optionalTransaction = repository.findById(UUID.fromString(uuid));
return ResponseEntity.status(HttpStatus.FOUND).body(optionalTransaction.get());
}
}
spring:
application:
name: store-producer
datasource:
url: jdbc:postgresql://127.0.0.1:5432/epe
username: postgres
password: welcome
driver-class-name: org.postgresql.Driver
jpa:
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
server:
port: 8200
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment