Wrap events in _embedded
parent
497941d0bf
commit
f8afdf1e6d
|
@ -10,14 +10,14 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
|
|||
import org.springframework.data.rest.webmvc.RepositoryRestController;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by admin on 01/04/2017.
|
||||
|
@ -58,4 +58,17 @@ public class EventController {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/events", method = RequestMethod.GET)
|
||||
public ResponseEntity<?> getEventsById(@RequestParam(required = false) Long typeId) {
|
||||
Iterable<Event> result;
|
||||
if(typeId == null) {
|
||||
result = repository.findAll();
|
||||
} else {
|
||||
result = repository.findByEventTypeId(typeId);
|
||||
}
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.OK)
|
||||
.body(new Object() { public Object _embedded = result;});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,10 @@ import ba.steleks.repository.projection.EventProjection;
|
|||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RepositoryRestResource(excerptProjection = EventProjection.class)
|
||||
public interface EventsJpaRepository extends PagingAndSortingRepository<Event, Long> {
|
||||
List<Event> findByEventTypeId(Long eventTypeId);
|
||||
}
|
||||
|
|
Reference in New Issue