작성
·
227
3
EntityModel 객체를 상속하고 EntityModel 내부를 뜯어보았을 때 of 메소드 패턴을 가지고 있고, EventResource는 Event라는 도메인에 종속된 객체이기 때문에 아래와 같이 처리하였습니다.
public class EventResource extends EntityModel<Event> {
private static WebMvcLinkBuilder selfLinkBuilder = linkTo(EventController.class);
private EventResource(){ }
public static EntityModel<Event> of(Event event, String profile){
List<Link> links = getSelfLink(event);
links.add(Link.of(profile, "profile"));
return EntityModel.of(event, links);
}
public static EntityModel<Event> of(Event event){
List<Link> links = getSelfLink(event);
return EntityModel.of(event, links);
}
private static List<Link> getSelfLink(Event event) {
selfLinkBuilder.slash(event.getId());
List<Link> links = new ArrayList<>();
links.add(selfLinkBuilder.withSelfRel());
return links;
}
public static URI getCreatedUri(Event event) {
return selfLinkBuilder.slash(event.getId()).toUri();
}
}