Commit b09014b4 authored by Kali Padhi's avatar Kali Padhi

Integrate with Postgres

parent 8412d8b7
......@@ -23,6 +23,8 @@ dependencies {
//compile group: 'org.springframework', name: 'spring-context', version: '5.2.5.RELEASE'
compile group: 'com.google.guava', name: 'guava', version: '28.2-jre'
compileOnly 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
......
Download and Install Postgress In Docker ::
docker pull postgres
docker run -d -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password123 --name postgres -p 5432:5432 --restart=always postgres
Download and install pgadmin
https://www.postgresql.org/ftp/pgadmin/pgadmin4/v4.19/windows/
after installation start the pg admin by use below url
http://127.0.0.1:58283/browser/#
Once you start it will ask to create a master password
Go to Add New Server --> Give any database name --> go to connection tab and provide below details
Host = 127.0.0.1
Port = 5432
username = user
password = password123
Then click on save
In Header click on Tool -> Query Tool --> and paste the below query
===================================================
-- Table: public.offerlookup
-- DROP TABLE public.offerlookup;
CREATE TABLE public.offerlookup
(
offer_lookup_id text COLLATE pg_catalog."default" NOT NULL,
store_id text COLLATE pg_catalog."default" NOT NULL,
terminal text COLLATE pg_catalog."default" NOT NULL,
offer_type text COLLATE pg_catalog."default" NOT NULL,
offer_id text COLLATE pg_catalog."default" NOT NULL,
pre_condition text COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT "OfferLookup_pkey" PRIMARY KEY (offer_lookup_id)
)
TABLESPACE pg_default;
ALTER TABLE public.offerlookup
OWNER to "postgress";
====================================================
Once you create use the below query to insert a data
INSERT INTO public.offerlookup(
offer_lookup_id, store_id, terminal, offer_type, offer_id, pre_condition)
VALUES ('1234567890','0001','002','UPC','01','AND');
package com.nisum.offertransactionservice;
import com.nisum.offertransactionservice.dao.OfferLookupRepo;
import com.nisum.offertransactionservice.model.OfferLookup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......
......@@ -2,9 +2,11 @@ package com.nisum.offertransactionservice.converter;
import com.nisum.offertransactionservice.model.OfferTransactionResponse;
import com.nisum.offertransactionservice.model.PEResponse;
import org.springframework.stereotype.Component;
import java.util.function.Function;
@Component
public class PEResponseToOfferTransactionResConverter implements Function<PEResponse, OfferTransactionResponse> {
@Override
public OfferTransactionResponse apply(PEResponse peResponse) {
......
package com.nisum.offertransactionservice.dao;
import com.nisum.offertransactionservice.model.OfferLookup;
import org.springframework.data.repository.CrudRepository;
public interface OfferLookupRepo extends CrudRepository<OfferLookup,String> {
}
......@@ -6,18 +6,30 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = false)
@Entity
@Table(name = "offerlookup")
public class OfferLookup {
@Id
@Column(name = "offer_lookup_id")
String id;
@Column(name ="offer_id")
String offerId;
String offerType;
@Column(name ="store_id")
String storeId;
@Column(name ="terminal")
String terminal;
@Column(name ="pre_condition")
String preCondition;
String id;
@Column(name ="offer_type")
String idType;
}
......@@ -3,28 +3,34 @@ package com.nisum.offertransactionservice.service;
import com.nisum.offertransactionservice.converter.OfferConverter;
import com.nisum.offertransactionservice.converter.PEResponseToOfferTransactionResConverter;
import com.nisum.offertransactionservice.dao.OfferDao;
import com.nisum.offertransactionservice.model.OfferTransactionRequest;
import com.nisum.offertransactionservice.model.OfferTransactionResponse;
import com.nisum.offertransactionservice.model.PERequest;
import com.nisum.offertransactionservice.model.PEResponse;
import com.nisum.offertransactionservice.dao.OfferLookupRepo;
import com.nisum.offertransactionservice.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
@Service
public class OfferCallingPEService {
@Autowired
private OfferConverter offerConverter;
@Autowired
private OfferLookupRepo offerLookupRepo;
@Autowired
private OfferDao offerDao;
@Autowired
private PEResponseToOfferTransactionResConverter peResponseToOfferTransactionResConverter;
public OfferTransactionResponse getDiscountedItemList(OfferTransactionRequest offerTransactionRequest) {
//TODO add db call and get the Offerlookup data
List<OfferLookup> eligibleOffer = newArrayList();
offerLookupRepo.findAll().forEach(eligibleOffer::add);
OfferTransactionResponse offerTransactionResponse ;
PERequest peRequest = offerConverter.apply(offerTransactionRequest);
//peRequest.setEligibleOffers();
peRequest.setEligibleOffers(eligibleOffer);
PEResponse peResponse = offerDao.callPE(peRequest);
offerTransactionResponse = peResponseToOfferTransactionResConverter.apply(peResponse);
return offerTransactionResponse;
......
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/user
spring.datasource.username=user
spring.datasource.password=password123
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