Skip to content

Commit

Permalink
readme & api response
Browse files Browse the repository at this point in the history
  • Loading branch information
surabhi-mahawar committed Jul 12, 2022
1 parent f2ac0f7 commit 2699184
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Build on Push & Pull Request
# Build on Push & Pull Request
name: Maven Build
on:
push:
branches:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Docker Build & Push on Tag

# Docker Build & Push on Tag
name: Docker Build
on:
push:
tags:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# whatsapp-outbound
![Maven Build](https://github.com/samagra-comms/outbound/actions/workflows/build.yml/badge.svg)
![Docker Build](https://github.com/samagra-comms/outbound/actions/workflows/docker-build-push.yml/badge.svg)

# Overview
Outbound converts the xMessage to the one that will be sent to the channel(sms/whatsapp). It will then be sent to the network provider(Netcore/Gupshup) who will send it to the channel.
28 changes: 14 additions & 14 deletions src/main/java/com/uci/outbound/health/HealthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.uci.dao.service.HealthService;

import com.uci.utils.model.ApiResponse;
import com.uci.utils.model.ApiResponseParams;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -24,20 +27,17 @@ public class HealthController {

@Autowired
private HealthService healthService;

@RequestMapping(value = "/health", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> statusCheck() throws JsonProcessingException, IOException {
ObjectMapper mapper = new ObjectMapper();
/* Current Date Time */
LocalDateTime localNow = LocalDateTime.now();
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
String dateString = fmt.format(localNow).toString();

JsonNode jsonNode = mapper.readTree("{\"id\":\"api.content.health\",\"ver\":\"3.0\",\"ts\":\"2021-06-26T22:47:05Z+05:30\",\"params\":{\"resmsgid\":\"859fee0c-94d6-4a0d-b786-2025d763b78a\",\"msgid\":null,\"err\":null,\"status\":\"successful\",\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"checks\":[{\"name\":\"redis cache\",\"healthy\":true},{\"name\":\"graph db\",\"healthy\":true},{\"name\":\"cassandra db\",\"healthy\":true}],\"healthy\":true}}");

((ObjectNode) jsonNode).put("ts", dateString);
((ObjectNode) jsonNode).put("result", healthService.getAllHealthNode());

return ResponseEntity.ok(jsonNode);
public ResponseEntity<ApiResponse> statusCheck() throws JsonProcessingException, IOException {
log.error("Health API called");
ApiResponse response = ApiResponse.builder()
.id("api.health")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getAllHealthNode())
.build();

return ResponseEntity.ok(response);
}
}
69 changes: 32 additions & 37 deletions src/main/java/com/uci/outbound/health/ServiceStatusController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.uci.dao.service.HealthService;

import com.uci.utils.model.ApiResponse;
import com.uci.utils.model.ApiResponseParams;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -25,47 +28,39 @@ public class ServiceStatusController {
@Autowired
private HealthService healthService;

@RequestMapping(value = "/health", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> statusCheck() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree("{\"id\":\"api.content.service.health\",\"ver\":\"3.0\",\"ts\":null,\"params\":{\"resmsgid\":null,\"msgid\":null,\"err\":null,\"status\":\"successful\",\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"healthy\":true}}");
return ResponseEntity.ok(json);
}

@RequestMapping(value = "/health/cassandra", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> cassandraStatusCheck() throws IOException, JsonProcessingException {
JsonNode jsonNode = getResponseJsonNode();
((ObjectNode) jsonNode).put("result", healthService.getCassandraHealthNode());

return ResponseEntity.ok(jsonNode);
public ResponseEntity<ApiResponse> cassandraStatusCheck() throws IOException, JsonProcessingException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.cassandra")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getCassandraHealthNode())
.build();

return ResponseEntity.ok(response);
}

@RequestMapping(value = "/health/kafka", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> kafkaStatusCheck() throws IOException, JsonProcessingException {
JsonNode jsonNode = getResponseJsonNode();
((ObjectNode) jsonNode).put("result", healthService.getKafkaHealthNode());

return ResponseEntity.ok(jsonNode);
public ResponseEntity<ApiResponse> kafkaStatusCheck() throws IOException, JsonProcessingException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.kafka")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getKafkaHealthNode())
.build();

return ResponseEntity.ok(response);
}

@RequestMapping(value = "/health/campaign", method = RequestMethod.GET, produces = { "application/json", "text/json" })
public ResponseEntity<JsonNode> campaignUrlStatusCheck() throws JsonProcessingException, IOException {
JsonNode jsonNode = getResponseJsonNode();
((ObjectNode) jsonNode).put("result", healthService.getCampaignUrlHealthNode());

return ResponseEntity.ok(jsonNode);
}

/**
* Returns json node for service response
*
* @return JsonNode
* @throws JsonMappingException
* @throws JsonProcessingException
*/
private JsonNode getResponseJsonNode() throws JsonMappingException, JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree("{\"id\":\"api.content.service.health\",\"ver\":\"3.0\",\"ts\":null,\"params\":{\"resmsgid\":null,\"msgid\":null,\"err\":null,\"status\":\"successful\",\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"healthy\":false}}");
return jsonNode;
public ResponseEntity<ApiResponse> campaignUrlStatusCheck() throws JsonProcessingException, IOException {
ApiResponse response = ApiResponse.builder()
.id("api.service.health.campaign")
.params(ApiResponseParams.builder().build())
.responseCode(HttpStatus.OK.name())
.result(healthService.getCampaignUrlHealthNode())
.build();

return ResponseEntity.ok(response);
}
}

0 comments on commit 2699184

Please sign in to comment.