Skip to content

Commit

Permalink
modified response type of car and polygon services to return detailed…
Browse files Browse the repository at this point in the history
… cars and strategic respectively, cars are returned in the list by car service sorted according to their vin, implemented end to end flows of position service, impleemnted algorithm to check if a poijht lies within a polygon in position service, implemented unit tests for verifying car and polygon placement algorithm with all edge cases, added networking attributes, host names in docker compose
  • Loading branch information
ANIRBANSTIFLER committed Mar 18, 2021
1 parent 7ed90a9 commit a71f5c6
Show file tree
Hide file tree
Showing 58 changed files with 902 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("search")
Expand Down Expand Up @@ -42,4 +43,13 @@ public ResponseEntity<?> getAllCars() throws CarServiceException {
return response;
}

@GetMapping("withdetails")
public ResponseEntity<?> getAllCarsWithDetails() throws CarServiceException {
LOGGER.info("Requesting all cars and their details");
Set<CarDetailsVO> voList = this.service.retrieveAllCarsWithDetails();
ResponseEntity<Set<CarDetailsVO>> response = ResponseEntity.ok(voList);
LOGGER.info("Responding with all available cars and their details");
return response;
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.teenthofabud.codingchallenge.sharenow.car.model.entity;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.redis.core.RedisHash;
Expand All @@ -18,13 +15,15 @@
@RedisHash("Car")
@TypeAlias("Car")
@NoArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class CarEntity implements Serializable {

@Indexed
private int id;
private int locationId;
@Id
@Indexed
@EqualsAndHashCode.Include
private String vin;
private String numberPlate;
private PositionEntity position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@Getter
@Setter
public class CarDetailsVO {
public class CarDetailsVO implements Comparable<CarDetailsVO> {

private int id;
private int locationId;
Expand All @@ -15,4 +15,8 @@ public class CarDetailsVO {
private float fuel;
private String model;

@Override
public int compareTo(CarDetailsVO o) {
return this.vin.compareTo(o.getVin());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public interface CarService {

public List<CarVO> retrieveAllCars();

public Set<CarDetailsVO> retrieveAllCarsWithDetails();

public CarDetailsVO retrieveCarDetailsByVin(String vin) throws CarServiceException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ public List<CarVO> retrieveAllCars() {
return carVOList;
}

@Override
public Set<CarDetailsVO> retrieveAllCarsWithDetails() {
Set<CarDetailsVO> carVOList = new TreeSet<>();
Iterable<CarEntity> entityItr = this.repository.findAll();
for(CarEntity entity : entityItr) {
if(entity != null && StringUtils.hasText(entity.getVin())) {
CarDetailsVO vo = this.complexVOConverter.convert(entity);
carVOList.add(vo);
}
}
LOGGER.info("Found {} cars", carVOList.size());
return carVOList;
}

@Override
public CarDetailsVO retrieveCarDetailsByVin(String vin) throws CarServiceException {
if(StringUtils.hasText(vin)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.routes[0].id=car-service
spring.cloud.gateway.routes[0].uri=lb://car-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/car-service/**
spring.cloud.gateway.routes[0].filters[0]=RewritePath=/car-service(?<segment>/?.*), ${segment}

spring.cloud.gateway.routes[1].id=polygon-service
spring.cloud.gateway.routes[1].uri=lb://polygon-service
#spring.cloud.gateway.routes[1].predicates[0]=Path=/polygon-service/**
spring.cloud.gateway.routes[1].predicates[0]=Path=/polygon/**
#spring.cloud.gateway.routes[1].filters[0]=RewritePath=/polygon-service/(?<segment>.*), /polygon-service/${segment}
spring.cloud.gateway.routes[1].filters[0]=RewritePath=/polygon(?<segment>/?.*), ${segment}

spring.cloud.gateway.routes[2].id=position-service
spring.cloud.gateway.routes[2].uri=lb://position-service
spring.cloud.gateway.routes[2].predicates[0]=Path=/position-service/**
spring.cloud.gateway.routes[2].filters[0]=RewritePath=/position-service(?<segment>/?.*), ${segment}

eureka.instance.prefer-ip-address=true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ eureka.client.service-url.defaultZone=${NAMING_SERVER_URL}/eureka
spring.cloud.gateway.routes[0].id=car-service
spring.cloud.gateway.routes[0].uri=lb://car-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/car-service/**
spring.cloud.gateway.routes[0].filters[0]=RewritePath=/car-service(?<segment>/?.*), ${segment}

spring.cloud.gateway.routes[1].id=polygon-service
spring.cloud.gateway.routes[1].uri=lb://polygon-service
spring.cloud.gateway.routes[1].predicates[0]=Path=/polygon-service/**
spring.cloud.gateway.routes[1].filters[0]=RewritePath=/polygon-service(?<segment>/?.*), ${segment}

spring.cloud.gateway.routes[2].id=position-service
spring.cloud.gateway.routes[2].uri=lb://position-service
spring.cloud.gateway.routes[2].predicates[0]=Path=/position-service/**
spring.cloud.gateway.routes[2].filters[0]=RewritePath=/position-service(?<segment>/?.*), ${segment}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ spring.sleuth.web.skipPattern=(^cleanup.*|.+favicon.*)

spring.zipkin.baseUrl=http://localhost:9411

poss.polygon-service.url=http://polygon-service
poss.car-service.url=http://car-service
poss.polygon-service.url=localhost:18080
poss.car-service.url=localhost:17080

poss.placement.infinite.end.limit=1000

eureka.instance.prefer-ip-address=true
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ spring.sleuth.web.skipPattern=(^cleanup.*|.+favicon.*)
spring.zipkin.baseUrl=${TRACING_SERVER_URL}

poss.polygon-service.url=${POLYGON_SERVICE_URL}
poss.car-service.url=${CAR_SERVICE_URL}
poss.car-service.url=${CAR_SERVICE_URL}

poss.placement.infinite.end.limit=1000
50 changes: 50 additions & 0 deletions docker-compose-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3.9"

services:

documentdb-service:
image: mongo:4.4-bionic
container_name: documentdb-service
hostname: documentdb-service
volumes:
- "/data/db:/opt/sharenow-coding-challenge-data/mongodb"
ports:
- "27017:27017"

naming-service:
image: teenthofabud/sharenow-coding-challenge-naming-service:1.0.0-SNAPSHOT
container_name: naming-service
hostname: naming-service
ports:
- "8761:8761"

configuration-service:
image: teenthofabud/sharenow-coding-challenge-configuration-service:1.0.0-SNAPSHOT
container_name: configuration-service
hostname: configuration-service
ports:
- "8888:8888"

tracing-service:
image: openzipkin/zipkin
container_name: tracing-service
hostname: tracing-service
ports:
- "9411:9411"

polygon-service:
image: teenthofabud/sharenow-coding-challenge-polygon-service:1.0.0-SNAPSHOT
container_name: polygon-service
hostname: polygon-service
environment:
- PROFILE=staging
- DOCUMENTDB_SERVER_HOST=documentdb-service
- DOCUMENTDB_SERVER_PORT=27017
- TRACING_SERVER_URL=http://tracing-service:9411
- CONFIGURATION_SERVER_URL=http://configuration-service:8888
- NAMING_SERVER_URL=http://naming-service:8761
depends_on:
- documentdb-service
- configuration-service
- naming-service
- tracing-service
58 changes: 50 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,72 @@ services:
cache-service:
image: redis:3.0.7-alpine
container_name: cache-service
hostname: cache-service
ports:
- "6379:6379"
networks:
- car

documentdb-service:
image: mongo:4.4-bionic
container_name: documentdb-service
hostname: documentdb-service
volumes:
- "/data/db:/opt/sharenow-coding-challenge-data/mongodb"
ports:
- "27017:27017"
networks:
- polygon

tracing-service:
image: openzipkin/zipkin
container_name: tracing-service
hostname: tracing-service
ports:
- "9411:9411"
networks:
- car
- polygon

car2godeveloper-service:
image: car2godeveloper/api-for-coding-challenge
container_name: car2godeveloper-service
hostname: car2godeveloper-service
ports:
- "3000:3000"
networks:
- car

naming-service:
image: teenthofabud/sharenow-coding-challenge-naming-service:1.0.0-SNAPSHOT
container_name: naming-service
hostname: naming-service
ports:
- "8761:8761"
networks:
- car
- polygon

configuration-service:
image: teenthofabud/sharenow-coding-challenge-configuration-service:1.0.0-SNAPSHOT
container_name: configuration-service
hostname: configuration-service
ports:
- "8888:8888"
networks:
- car
- polygon

gateway-service:
image: teenthofabud/sharenow-coding-challenge-gateway-service:1.0.0-SNAPSHOT
container_name: gateway-service
hostname: gateway-service
networks:
- car
- polygon
environment:
- PROFILE=staging
- CONFIGURATION_SERVER_URL=http://configuration-service/8888
- CONFIGURATION_SERVER_URL=http://configuration-service:8888
- NAMING_SERVER_URL=http://naming-service:8761
depends_on:
- configuration-service
Expand All @@ -56,11 +81,14 @@ services:
polling-service:
image: teenthofabud/sharenow-coding-challenge-polling-service:1.0.0-SNAPSHOT
container_name: polling-service
hostname: polling-service
networks:
- car
environment:
- PROFILE=staging
- CACHE_SERVER_HOST=cache-service
- CACHE_SERVER_PORT=6379
- CONFIGURATION_SERVER_URL=http://configuration-service/8888
- CONFIGURATION_SERVER_URL=http://configuration-service:8888
- NAMING_SERVER_URL=http://naming-service:8761
- CAR2GO_SERVER_URL=http://car2godeveloper-service:3000
depends_on:
Expand All @@ -73,12 +101,15 @@ services:
car-service:
image: teenthofabud/sharenow-coding-challenge-car-service:1.0.0-SNAPSHOT
container_name: car-service
hostname: car-service
networks:
- car
environment:
- PROFILE=staging
- CACHE_SERVER_HOST=cache-service
- CACHE_SERVER_PORT=6379
- TRACING_SERVER_URL=http://tracing-service:9411
- CONFIGURATION_SERVER_URL=http://configuration-service/8888
- CONFIGURATION_SERVER_URL=http://configuration-service:8888
- NAMING_SERVER_URL=http://naming-service:8761
depends_on:
- cache-service
Expand All @@ -91,12 +122,15 @@ services:
polygon-service:
image: teenthofabud/sharenow-coding-challenge-polygon-service:1.0.0-SNAPSHOT
container_name: polygon-service
hostname: polygon-service
networks:
- polygon
environment:
- PROFILE=staging
- DOCUMENTDB_SERVER_HOST=documentdb-service
- DOCUMENTDB_SERVER_PORT=27017
- TRACING_SERVER_URL=http://tracing-service:9411
- CONFIGURATION_SERVER_URL=http://configuration-service/8888
- CONFIGURATION_SERVER_URL=http://configuration-service:8888
- NAMING_SERVER_URL=http://naming-service:8761
depends_on:
- documentdb-service
Expand All @@ -108,17 +142,25 @@ services:
position-service:
image: teenthofabud/sharenow-coding-challenge-position-service:1.0.0-SNAPSHOT
container_name: position-service
hostname: position-service
networks:
- car
- polygon
environment:
- PROFILE=staging
- TRACING_SERVER_URL=http://tracing-service:9411
- CONFIGURATION_SERVER_URL=http://configuration-service/8888
- CONFIGURATION_SERVER_URL=http://configuration-service:8888
- NAMING_SERVER_URL=http://naming-service:8761
- CAR_SERVICE_URL=http://car-service
- POLYGON_SERVICE_URL=http://polygon-service
- CAR_SERVICE_URL=car-service
- POLYGON_SERVICE_URL=polygon-service
depends_on:
- tracing-service
- car-service
- polygon-service
- configuration-service
- naming-service
- gateway-service
- gateway-service

networks:
car:
polygon:
4 changes: 4 additions & 0 deletions gateway-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
Expand Down

This file was deleted.

Loading

0 comments on commit a71f5c6

Please sign in to comment.