Skip to content

Commit

Permalink
Added payload DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonali Shakya authored and Sonali Shakya committed Dec 23, 2024
1 parent 7a50225 commit b007498
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ondc.yugabyte_integration.Controller;

import com.ondc.yugabyte_integration.Entity.Payload;
import com.ondc.yugabyte_integration.Entity.PayloadDetailsDTO;
import com.ondc.yugabyte_integration.Entity.SessionDetails;
import com.ondc.yugabyte_integration.Repository.PayloadRepository;
import com.ondc.yugabyte_integration.Repository.SessionDetailsRepository;
Expand Down Expand Up @@ -66,11 +67,8 @@ public SessionDetails createSession(@RequestBody SessionDetails sessionDetails)
}

@GetMapping("/payload/{sessionId}")
public List<Payload> getPayloadBySessionId(@PathVariable String sessionId) {
SessionDetails sessionDetails = sdRepository.findBySessionId(sessionId)
.orElseThrow(() -> new RuntimeException("SessionDetails not found for sessionId: " + sessionId));
;
return sessionDetails.getPayloads();
public List<PayloadDetailsDTO> getPayloadBySessionId(@PathVariable String sessionId) {
return sessionDetailsService.getPayloadDetails(sessionId);
}

@PutMapping("/{sessionId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ondc.yugabyte_integration.Entity;

import java.util.List;

public class PayloadDetailsDTO {
private SessionDetails.Type npType;
private String domain;
private Payload payloads;

public PayloadDetailsDTO(SessionDetails.Type npType, String domain, Payload payloads) {
this.npType = npType;
this.domain = domain;
this.payloads = payloads;
}

public SessionDetails.Type getNpType() {
return npType;
}

public void setNpType(SessionDetails.Type npType) {
this.npType = npType;
}

public String getDomain() {
return domain;
}

public void setDomain(String domain) {
this.domain = domain;
}

public Payload getPayloads() {
return payloads;
}

public void setPayloads(Payload payloads) {
this.payloads = payloads;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.ondc.yugabyte_integration.Service;

import com.ondc.yugabyte_integration.Entity.Payload;
import com.ondc.yugabyte_integration.Entity.PayloadDetailsDTO;
import com.ondc.yugabyte_integration.Entity.SessionDetails;
import com.ondc.yugabyte_integration.Repository.SessionDetailsRepository;
import jakarta.transaction.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -60,4 +64,15 @@ public void deleteSession(String sessionId) {
public Optional<SessionDetails> getSessionWithPayloads(String sessionId) {
return sessionDetailsRepository.findWithPayloadsBySessionId(sessionId);
}

public List<PayloadDetailsDTO> getPayloadDetails(String sessionId) {
SessionDetails sessionDetails = sessionDetailsRepository.findBySessionId(sessionId)
.orElseThrow(() -> new RuntimeException("SessionDetails not found for sessionId: " + sessionId));

List<PayloadDetailsDTO> payloadDetailsDTOS = new ArrayList<>();
for (Payload payload : sessionDetails.getPayloads()) {
payloadDetailsDTOS.add(new PayloadDetailsDTO(sessionDetails.getNpType(), sessionDetails.getDomain(), payload));
}
return payloadDetailsDTOS;
}
}
2 changes: 1 addition & 1 deletion yugabyte-integration/target/classes/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spring.application.name=yugabyte-integration
#spring.datasource.url=${DB_URL}
spring.datasource.url=jdbc:postgresql://127.0.0.1:5433/my_app
spring.datasource.username=yugabyte
spring.datasource.password=
#spring.datasource.password=
#spring.datasource.password=${DB_PASSWORD}
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b007498

Please sign in to comment.