dizda13 2017-04-16 18:01:16 +02:00
commit 5314f4b944
3 changed files with 17 additions and 8 deletions

2
config

@ -1 +1 @@
Subproject commit 0d028147e90627b077c5435b557d6b3d7d19623c Subproject commit 75a784ba6ed8f6e70ee91808d3752443e3a04d1d

View File

@ -5,6 +5,8 @@ import ba.steleks.model.Event;
import ba.steleks.model.EventTeam; import ba.steleks.model.EventTeam;
import ba.steleks.repository.EventTeamJpaRepository; import ba.steleks.repository.EventTeamJpaRepository;
import ba.steleks.repository.EventsJpaRepository; import ba.steleks.repository.EventsJpaRepository;
import ba.steleks.service.Service;
import ba.steleks.service.discovery.ServiceDiscoveryClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.data.rest.webmvc.RepositoryRestController; import org.springframework.data.rest.webmvc.RepositoryRestController;
@ -31,19 +33,22 @@ public class EventTeamController {
private RestTemplate restTemplate; private RestTemplate restTemplate;
private ServiceDiscoveryClient discoveryClient;
@Autowired @Autowired
public EventTeamController(RestTemplateBuilder restTemplateBuilder, EventTeamJpaRepository repository) { public EventTeamController(EventTeamJpaRepository repository, RestTemplateBuilder restTemplateBuilder, ServiceDiscoveryClient discoveryClient) {
this.restTemplate = restTemplateBuilder.build();
this.repository = repository; this.repository = repository;
this.restTemplate = restTemplateBuilder.build();
this.discoveryClient = discoveryClient;
} }
@RequestMapping(path = "/eventTeams", method = RequestMethod.POST) @RequestMapping(path = "/eventTeams", method = RequestMethod.POST)
public ResponseEntity<?> add(@RequestBody EventTeam eventTeam) throws ExternalServiceException { public ResponseEntity<?> add(@RequestBody EventTeam eventTeam) throws ExternalServiceException {
String oviTimoviNeki = "http://localhost:9010/teams/{id}"; String teamsServiceBase = discoveryClient.getServiceUrl(Service.TEAMS);
try { try {
String response = restTemplate.getForObject(oviTimoviNeki, String.class, eventTeam.getTeamId()); String response = restTemplate.getForObject(teamsServiceBase + "/teams/{id}", String.class, eventTeam.getTeamId());
EventTeam result = repository.save(eventTeam); EventTeam result = repository.save(eventTeam);
URI location = ServletUriComponentsBuilder URI location = ServletUriComponentsBuilder
.fromCurrentRequest().path("/{id}") .fromCurrentRequest().path("/{id}")

View File

@ -6,6 +6,8 @@ import ba.steleks.error.exception.ExternalServiceException;
import ba.steleks.model.Event; import ba.steleks.model.Event;
import ba.steleks.model.Media; import ba.steleks.model.Media;
import ba.steleks.repository.MediaJpaRepository; import ba.steleks.repository.MediaJpaRepository;
import ba.steleks.service.Service;
import ba.steleks.service.discovery.ServiceDiscoveryClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.data.rest.webmvc.RepositoryRestController; import org.springframework.data.rest.webmvc.RepositoryRestController;
@ -25,19 +27,21 @@ public class MediaController {
private MediaJpaRepository repository; private MediaJpaRepository repository;
private RestTemplate restTemplate; private RestTemplate restTemplate;
private ServiceDiscoveryClient discoveryClient;
@Autowired @Autowired
public MediaController(RestTemplateBuilder restTemplateBuilder, MediaJpaRepository repository) { public MediaController(MediaJpaRepository repository, RestTemplateBuilder restTemplateBuilder, ServiceDiscoveryClient discoveryClient) {
this.repository = repository; this.repository = repository;
this.restTemplate = restTemplateBuilder.build(); this.restTemplate = restTemplateBuilder.build();
this.discoveryClient = discoveryClient;
} }
@RequestMapping(path = "/medias", method = RequestMethod.POST) @RequestMapping(path = "/medias", method = RequestMethod.POST)
public ResponseEntity<?> add(@RequestBody Media media) throws ExternalServiceException { public ResponseEntity<?> add(@RequestBody Media media) throws ExternalServiceException {
String oviUseriNeki = "http://localhost:8090/users/{id}"; String usersServiceBase = discoveryClient.getServiceUrl(Service.USERS);
try { try {
String response = restTemplate.getForObject(oviUseriNeki, String.class, media.getCreatedById()); String response = restTemplate.getForObject(usersServiceBase + "/users/{id}", String.class, media.getCreatedById());
Media result = repository.save(media); Media result = repository.save(media);
URI location = ServletUriComponentsBuilder URI location = ServletUriComponentsBuilder
.fromCurrentRequest().path("/{id}") .fromCurrentRequest().path("/{id}")