From 57898e56816982c12985c6f96c4c90fc9f1cae76 Mon Sep 17 00:00:00 2001 From: aoc38 Date: Mon, 29 May 2023 01:16:58 -0500 Subject: [PATCH 1/2] Adding new files for activating sim card --- .../controller/SimCardActivateController.java | 27 +++++++++++++++++++ .../java/au/com/telstra/model/SIMCard.java | 22 +++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/java/au/com/telstra/controller/SimCardActivateController.java create mode 100644 src/main/java/au/com/telstra/model/SIMCard.java diff --git a/src/main/java/au/com/telstra/controller/SimCardActivateController.java b/src/main/java/au/com/telstra/controller/SimCardActivateController.java new file mode 100644 index 0000000..83ce49a --- /dev/null +++ b/src/main/java/au/com/telstra/controller/SimCardActivateController.java @@ -0,0 +1,27 @@ +package au.com.telstra.controller; + +import au.com.telstra.model.SIMCard; +import org.springframework.http.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@RestController +public class SimCardActivateController { + + private static final String ACTIVATE_SIM_API = "http://localhost:8444/actuate"; + + RestTemplate restTemplate = new RestTemplate(); + + @PostMapping("/activatesimcard") + public void addUser(@RequestBody SIMCard newSimCard){ + System.out.println(callActivateSimCard(newSimCard)); + } + + public String callActivateSimCard(SIMCard newSimCard){ + ResponseEntity response = restTemplate.postForEntity(ACTIVATE_SIM_API,newSimCard,Object.class); + return response.getBody().toString(); + } + +} diff --git a/src/main/java/au/com/telstra/model/SIMCard.java b/src/main/java/au/com/telstra/model/SIMCard.java new file mode 100644 index 0000000..ed71d70 --- /dev/null +++ b/src/main/java/au/com/telstra/model/SIMCard.java @@ -0,0 +1,22 @@ +package au.com.telstra.model; + +public class SIMCard { + private String iccid; + private String customerEmail; + + public String getIccid() { + return iccid; + } + + public void setIccid(String iccid) { + this.iccid = iccid; + } + + public String getCustomerEmail() { + return customerEmail; + } + + public void setCustomerEmail(String customerEmail) { + this.customerEmail = customerEmail; + } +} From 2715f075d017e721a97bead776925c485120b8fc Mon Sep 17 00:00:00 2001 From: Divyaja Kakarla Date: Wed, 6 Mar 2024 22:40:22 -0600 Subject: [PATCH 2/2] task2 --- .../controller/SimCardActivateController.java | 28 ++++++++++---- .../au/com/telstra/pojo/SimCardEntity.java | 31 ++++++++++++++++ .../com/telstra/pojo/SimCardResponseDTO.java | 37 +++++++++++++++++++ .../com/telstra/repository/SimRepository.java | 16 ++++++++ .../com/telstra/service/SimCardService.java | 23 ++++++++++++ 5 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 src/main/java/au/com/telstra/pojo/SimCardEntity.java create mode 100644 src/main/java/au/com/telstra/pojo/SimCardResponseDTO.java create mode 100644 src/main/java/au/com/telstra/repository/SimRepository.java create mode 100644 src/main/java/au/com/telstra/service/SimCardService.java diff --git a/src/main/java/au/com/telstra/controller/SimCardActivateController.java b/src/main/java/au/com/telstra/controller/SimCardActivateController.java index 83ce49a..3e62c47 100644 --- a/src/main/java/au/com/telstra/controller/SimCardActivateController.java +++ b/src/main/java/au/com/telstra/controller/SimCardActivateController.java @@ -1,10 +1,11 @@ package au.com.telstra.controller; import au.com.telstra.model.SIMCard; +import au.com.telstra.pojo.SimCardResponseDTO; +import au.com.telstra.service.SimCardService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; @RestController @@ -12,16 +13,29 @@ public class SimCardActivateController { private static final String ACTIVATE_SIM_API = "http://localhost:8444/actuate"; - RestTemplate restTemplate = new RestTemplate(); + RestTemplate restTemplate = new RestTemplate(); + @Autowired + private SimCardService simCardService; @PostMapping("/activatesimcard") - public void addUser(@RequestBody SIMCard newSimCard){ + public void addUser(@RequestBody SIMCard newSimCard) { System.out.println(callActivateSimCard(newSimCard)); + simCardService.addSimCard(newSimCard); } - public String callActivateSimCard(SIMCard newSimCard){ - ResponseEntity response = restTemplate.postForEntity(ACTIVATE_SIM_API,newSimCard,Object.class); + public String callActivateSimCard(SIMCard newSimCard) { + ResponseEntity response = restTemplate.postForEntity(ACTIVATE_SIM_API, newSimCard, Object.class); return response.getBody().toString(); } + @GetMapping("/{simCardId}") + public SimCardResponseDTO getSimCardByID(@PathVariable long simCardId) { + SIMCard sim = simCardService.getSimCardById(simCardId); + return new SimCardResponseDTO(sim.getIccid(), + sim.getCustomerEmail(), + true + ); + } + + } diff --git a/src/main/java/au/com/telstra/pojo/SimCardEntity.java b/src/main/java/au/com/telstra/pojo/SimCardEntity.java new file mode 100644 index 0000000..f10df2e --- /dev/null +++ b/src/main/java/au/com/telstra/pojo/SimCardEntity.java @@ -0,0 +1,31 @@ +package au.com.telstra.pojo; + +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class SimCardEntity { + public SimCardEntity(String iccid, String customerEmail, boolean active) { + this.iccid = iccid; + this.customerEmail = customerEmail; + this.active = active; + } + + @Id + @GeneratedValue + private long id; + private String iccid; + private String customerEmail; + private boolean active; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } +} diff --git a/src/main/java/au/com/telstra/pojo/SimCardResponseDTO.java b/src/main/java/au/com/telstra/pojo/SimCardResponseDTO.java new file mode 100644 index 0000000..8896756 --- /dev/null +++ b/src/main/java/au/com/telstra/pojo/SimCardResponseDTO.java @@ -0,0 +1,37 @@ +package au.com.telstra.pojo; + +public class SimCardResponseDTO { + public SimCardResponseDTO(String iccid, String customerEmail, boolean active) { + this.iccid = iccid; + this.customerEmail = customerEmail; + this.active = active; + } + + private String iccid; + private String customerEmail; + private boolean active; + + public String getIccid() { + return iccid; + } + + public void setIccid(String iccid) { + this.iccid = iccid; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public String getCustomerEmail() { + return customerEmail; + } + + public void setCustomerEmail(String customerEmail) { + this.customerEmail = customerEmail; + } +} diff --git a/src/main/java/au/com/telstra/repository/SimRepository.java b/src/main/java/au/com/telstra/repository/SimRepository.java new file mode 100644 index 0000000..38cfd25 --- /dev/null +++ b/src/main/java/au/com/telstra/repository/SimRepository.java @@ -0,0 +1,16 @@ +package au.com.telstra.repository; + +import au.com.telstra.model.SIMCard; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface SimRepository extends JpaRepository { + @Override + S save(S entity); + + @Override + Optional findById(Long aLong); +} diff --git a/src/main/java/au/com/telstra/service/SimCardService.java b/src/main/java/au/com/telstra/service/SimCardService.java new file mode 100644 index 0000000..db44b4e --- /dev/null +++ b/src/main/java/au/com/telstra/service/SimCardService.java @@ -0,0 +1,23 @@ +package au.com.telstra.service; + +import au.com.telstra.model.SIMCard; +import au.com.telstra.repository.SimRepository; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +public class SimCardService { + private SimRepository simRepository; + + public SIMCard addSimCard(SIMCard simCard){ + return simRepository.save(simCard); + } + + public SIMCard getSimCardById(long simCardId){ + return simRepository.findById(simCardId).isPresent() + ? simRepository.findById(simCardId).get() + : null; + } + +}