Project events into json with medis and type

master
esensar 2017-06-10 14:20:27 +02:00
parent 71da53ffd6
commit d4f86c106c
3 changed files with 33 additions and 2 deletions

View File

@ -19,12 +19,17 @@ public class Event {
private Timestamp dateTime; private Timestamp dateTime;
private int duration; private int duration;
private long createdById; private long createdById;
@ManyToOne @ManyToOne
@JoinColumn @JoinColumn
private EventType eventType; private EventType eventType;
@ManyToMany @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn @JoinTable(
name = "event_media_set",
joinColumns=@JoinColumn(name = "event_id"),
inverseJoinColumns = @JoinColumn(name="media_set_id")
)
private Set<Media> mediaSet; private Set<Media> mediaSet;
protected Event() {} protected Event() {}

View File

@ -4,8 +4,11 @@
package ba.steleks.repository; package ba.steleks.repository;
import ba.steleks.model.Event; import ba.steleks.model.Event;
import ba.steleks.repository.projection.EventProjection;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource(excerptProjection = EventProjection.class)
public interface EventsJpaRepository extends PagingAndSortingRepository<Event, Long> { public interface EventsJpaRepository extends PagingAndSortingRepository<Event, Long> {
} }

View File

@ -0,0 +1,23 @@
package ba.steleks.repository.projection;/**
* Created by ensar on 10/06/17.
*/
import ba.steleks.model.Event;
import ba.steleks.model.EventType;
import ba.steleks.model.Media;
import org.springframework.data.rest.core.config.Projection;
import java.sql.Timestamp;
import java.util.Set;
@Projection(name = "eventProjection", types = { Event.class })
public interface EventProjection {
String getTitle();
String getShortText();
String getLongText();
Timestamp getDateTime();
int getDuration();
long getCreatedById();
EventType getEventType();
Set<Media> getMediaSet();
}