Skip to content

Commit 56d35ea

Browse files
emmanuelbernardNaros
authored andcommitted
[ogm/hiking] Get list of hikes in trip details
1 parent 8a0ee05 commit 56d35ea

File tree

4 files changed

+157
-17
lines changed

4 files changed

+157
-17
lines changed

hibernate-ogm/hiking-demo/src/main/java/org/hibernate/ogm/hiking/rest/TripResource.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.hibernate.ogm.hiking.model.Trip;
1717
import org.hibernate.ogm.hiking.repository.TripRepository;
1818
import org.hibernate.ogm.hiking.rest.model.ExternalTrip;
19+
import org.hibernate.ogm.hiking.rest.model.ExternalTripWithHikes;
1920

2021
@Path("/trips")
2122
@Stateless
@@ -44,9 +45,9 @@ public List<ExternalTrip> getAllTrips() {
4445
@GET
4546
@Path("/{id}")
4647
@Produces("application/json")
47-
public ExternalTrip getTripById(@PathParam("id") long tripId) {
48+
public ExternalTripWithHikes getTripById(@PathParam("id") long tripId) {
4849
// full load
49-
return new ExternalTrip( tripRepository.getTripById( tripId ), true );
50+
return new ExternalTripWithHikes( tripRepository.getTripById( tripId ) );
5051
}
5152

5253
@POST
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.hibernate.ogm.hiking.rest.model;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.hibernate.ogm.hiking.model.Hike;
7+
import org.hibernate.ogm.hiking.model.Section;
8+
9+
public class ExternalHikeSummary {
10+
11+
private long id;
12+
private String from;
13+
private String to;
14+
15+
public ExternalHikeSummary() {
16+
}
17+
18+
public ExternalHikeSummary(Hike hike) {
19+
this.id = hike.id;
20+
this.from = hike.start;
21+
this.to = hike.destination;
22+
}
23+
24+
public long getId() {
25+
return id;
26+
}
27+
28+
public void setId(long id) {
29+
this.id = id;
30+
}
31+
32+
public String getFrom() {
33+
return from;
34+
}
35+
36+
public void setFrom(String from) {
37+
this.from = from;
38+
}
39+
40+
public String getTo() {
41+
return to;
42+
}
43+
44+
public void setTo(String to) {
45+
this.to = to;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return "ExternalHikeSummary [id=" + id + ", from=" + from + ", to=" + to + "]";
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package org.hibernate.ogm.hiking.rest.model;
2+
3+
import java.util.Date;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
7+
import org.hibernate.ogm.hiking.model.Hike;
8+
import org.hibernate.ogm.hiking.model.Person;
9+
import org.hibernate.ogm.hiking.model.Trip;
10+
11+
public class ExternalTripWithHikes {
12+
13+
private long id;
14+
private String name;
15+
private Date startDate;
16+
private Date endDate;
17+
private double price;
18+
private Person organizer;
19+
private Set<ExternalHikeSummary> availableHikes;
20+
21+
public ExternalTripWithHikes() {
22+
}
23+
24+
public ExternalTripWithHikes(Trip trip) {
25+
this.id = trip.id;
26+
this.name = trip.name;
27+
this.startDate = trip.startDate;
28+
this.endDate = trip.endDate;
29+
this.price = trip.price;
30+
this.organizer = trip.organizer;
31+
this.availableHikes = new HashSet<>( trip.availableHikes.size() );
32+
for ( Hike hike : trip.availableHikes ) {
33+
this.availableHikes.add( new ExternalHikeSummary( hike ) );
34+
}
35+
}
36+
37+
public long getId() {
38+
return id;
39+
}
40+
41+
public void setId(long id) {
42+
this.id = id;
43+
}
44+
45+
public String getName() {
46+
return name;
47+
}
48+
49+
public void setName(String name) {
50+
this.name = name;
51+
}
52+
53+
public Date getStartDate() {
54+
return startDate;
55+
}
56+
57+
public void setStartDate(Date startDate) {
58+
this.startDate = startDate;
59+
}
60+
61+
public Date getEndDate() {
62+
return endDate;
63+
}
64+
65+
public void setEndDate(Date endDate) {
66+
this.endDate = endDate;
67+
}
68+
69+
public double getPrice() {
70+
return price;
71+
}
72+
73+
public void setPrice(double price) {
74+
this.price = price;
75+
}
76+
77+
public Person getOrganizer() {
78+
return organizer;
79+
}
80+
81+
public void setOrganizer(Person organizer) {
82+
this.organizer = organizer;
83+
}
84+
85+
public Set<ExternalHikeSummary> getAvailableHikes() {
86+
return availableHikes;
87+
}
88+
89+
public void setAvailableHikes(Set<ExternalHikeSummary> availableHikes) {
90+
this.availableHikes = availableHikes;
91+
}
92+
93+
@Override
94+
public String toString() {
95+
return "TripDescription [id=" + id + ", name=" + name + "]";
96+
}
97+
98+
}

hibernate-ogm/hiking-demo/src/main/webapp/trips-detail.html

+4-15
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,15 @@
5757

5858
<!-- Hikes -->
5959
<div class="form-group">
60-
<label class="col-sm-2 control-label">Sections</label>
60+
<label class="col-sm-2 control-label">Available hikes</label>
6161
<div class="col-md-6">
62-
<div ng-repeat="section in hike.sections">
62+
<div ng-repeat="hike in trip.availableHikes">
6363
<div class="form-group row">
64-
<div class="col-md-4">
65-
<input class="form-control" id="inputKey" placeholder="From"
66-
ng-model="section.from" type="text">
67-
</div>
68-
<div class="col-md-4">
69-
<input class="form-control" id="inputValue" placeholder="To"
70-
ng-model="section.to" type="text">
71-
</div>
72-
<div style="padding-top:6px">
73-
<a href ng-click="hike.sections.splice($index, 1)">Remove</a>
64+
<div class="col-md-8">
65+
Hike from <a href="#/edit/{{hike.id}}">{{hike.from}} to {{hike.to}}</a>
7466
</div>
7567
</div>
7668
</div>
77-
<div style="padding-top:6px">
78-
<a href ng-click="hike.sections.push({})">Add...</a>
79-
</div>
8069
</div>
8170
</div>
8271

0 commit comments

Comments
 (0)