-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nelvindc
authored and
nelvindc
committed
Mar 25, 2024
1 parent
83192cb
commit 64d2a5d
Showing
14 changed files
with
450 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# take-home | ||
# take-home | ||
|
||
accessible thru http://localhost:8080/quantrics/takehome/track |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/com/quantrics/demo/adapter/MediaWikiAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.quantrics.demo.adapter; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
import com.quantrics.demo.model.MediaWiki; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
public class MediaWikiAdapter { | ||
Log log = LogFactory.getLog(MediaWikiAdapter.class); | ||
|
||
private final WebClient webClient; | ||
|
||
public MediaWikiAdapter(WebClient.Builder webClientBuilder) { | ||
this.webClient = webClientBuilder.baseUrl("https://en.wikipedia.org").build(); | ||
} | ||
|
||
public Mono<String> someRestCall(String name) { | ||
return this.webClient.get().uri("/sample", name) | ||
.retrieve().bodyToMono(String.class); | ||
} | ||
|
||
public MediaWiki getPlaces(String latitude, String longitude) { | ||
|
||
StringBuffer coordinates = new StringBuffer(latitude); | ||
coordinates.append("|"); | ||
coordinates.append(longitude); | ||
log.info("coordinates: " + latitude + " " + longitude); | ||
|
||
return this.webClient.get().uri(uriBuilder -> uriBuilder | ||
.path("/w/api.php") | ||
.queryParam("action", "query") | ||
.queryParam("list", "geosearch") | ||
.queryParam("gsradius", "10000") | ||
.queryParam("gslimit", "10") | ||
//.queryParam("gscoord", "37.786971|-122.399677") | ||
//.queryParam("gscoord", "15.8700|100.9925") | ||
.queryParam("gscoord", coordinates.toString()) | ||
.queryParam("gsprop", "country") | ||
.queryParam("format", "json") | ||
.build()) | ||
.retrieve() | ||
.bodyToMono(MediaWiki.class) | ||
.block(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/quantrics/demo/adapter/OpenNotifyAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
package com.quantrics.demo.adapter; | ||
|
||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
import com.quantrics.demo.model.OpenNotify; | ||
|
||
|
||
@Component | ||
public class OpenNotifyAdapter { | ||
Log log = LogFactory.getLog(OpenNotifyAdapter.class); | ||
|
||
private final WebClient webClient; | ||
|
||
public OpenNotifyAdapter(WebClient.Builder webClientBuilder) { | ||
this.webClient = webClientBuilder.baseUrl("http://api.open-notify.org").build(); | ||
} | ||
|
||
public OpenNotify getIssLocation() { | ||
return this.webClient.get().uri("/iss-now.json") | ||
.retrieve().bodyToMono(OpenNotify.class).block(); | ||
} | ||
|
||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/quantrics/demo/controller/TakeHomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.quantrics.demo.controller; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.quantrics.demo.model.TrackResult; | ||
import com.quantrics.demo.service.TakeHomeService; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
|
||
@RestController | ||
@ControllerAdvice | ||
@RequestMapping ("/quantrics/takehome") | ||
public class TakeHomeController { | ||
Log log = LogFactory.getLog(TakeHomeController.class); | ||
|
||
@Autowired | ||
private TakeHomeService takeHomeService; | ||
|
||
@GetMapping("/track") | ||
public ResponseEntity<TrackResult> getTrackPlaces() { | ||
TrackResult result = new TrackResult(); | ||
result = takeHomeService.getTrackPlaces(); | ||
return new ResponseEntity<>(result, HttpStatus.OK); | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.quantrics.demo.model; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(Include.NON_NULL) | ||
public class GeoSearch { | ||
|
||
private String title; | ||
|
||
private BigDecimal lat; | ||
|
||
private BigDecimal lon; | ||
|
||
private BigDecimal distance; | ||
|
||
private String country; | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public BigDecimal getLat() { | ||
return lat; | ||
} | ||
|
||
public void setLat(BigDecimal lat) { | ||
this.lat = lat; | ||
} | ||
|
||
public BigDecimal getLon() { | ||
return lon; | ||
} | ||
|
||
public void setLon(BigDecimal lon) { | ||
this.lon = lon; | ||
} | ||
|
||
public BigDecimal getDistance() { | ||
return distance; | ||
} | ||
|
||
public void setDistance(BigDecimal distance) { | ||
this.distance = distance; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.quantrics.demo.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(Include.NON_NULL) | ||
public class MediaWiki { | ||
|
||
private QueryResult query; | ||
|
||
public QueryResult getQuery() { | ||
return query; | ||
} | ||
|
||
public void setQuery(QueryResult query) { | ||
this.query = query; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.quantrics.demo.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(Include.NON_NULL) | ||
public class OpenNotify { | ||
|
||
private Position iss_position; | ||
|
||
private String message; | ||
|
||
public Position getIss_position() { | ||
return iss_position; | ||
} | ||
|
||
public void setIss_position(Position iss_position) { | ||
this.iss_position = iss_position; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.quantrics.demo.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(Include.NON_NULL) | ||
public class Position { | ||
|
||
private String latitude; | ||
|
||
private String longitude; | ||
|
||
public String getLatitude() { | ||
return latitude; | ||
} | ||
|
||
public void setLatitude(String latitude) { | ||
this.latitude = latitude; | ||
} | ||
|
||
public String getLongitude() { | ||
return longitude; | ||
} | ||
|
||
public void setLongitude(String longitude) { | ||
this.longitude = longitude; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.quantrics.demo.model; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(Include.NON_NULL) | ||
public class QueryResult { | ||
|
||
private List<GeoSearch> geosearch; | ||
|
||
public List<GeoSearch> getGeosearch() { | ||
return geosearch; | ||
} | ||
|
||
public void setGeosearch(List<GeoSearch> geosearch) { | ||
this.geosearch = geosearch; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.quantrics.demo.model; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class TrackPlace { | ||
|
||
private String title; | ||
|
||
private BigDecimal latitude; | ||
|
||
private BigDecimal longitude; | ||
|
||
private String country; | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public BigDecimal getLatitude() { | ||
return latitude; | ||
} | ||
|
||
public void setLatitude(BigDecimal latitude) { | ||
this.latitude = latitude; | ||
} | ||
|
||
public BigDecimal getLongitude() { | ||
return longitude; | ||
} | ||
|
||
public void setLongitude(BigDecimal longitude) { | ||
this.longitude = longitude; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.