Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/main/java/edu/drexel/TrainDemo/trips/models/Itinerary.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@ public class Itinerary {
private StationEntity to;
private Time departure;
private Time arrival;

private String departureDate;

public Itinerary() {

}

public Itinerary(TripEntity trip, StationEntity from, StationEntity to, Time departure, Time arrival) {
public Itinerary(TripEntity trip,
StationEntity from,
StationEntity to,
Time departure,
Time arrival,
String departureDate) {
this.trip = trip;
this.from = from;
this.to = to;
this.departure = departure;
this.arrival = arrival;
this.departureDate = departureDate;
}

public Itinerary(TripEntity trip, StopTimeEntity from, StopTimeEntity to) {
Expand Down Expand Up @@ -72,6 +79,14 @@ public Time getArrival() {
public void setArrival(Time arrival) {
this.arrival = arrival;
}

public String getDepartureDate() {
return departureDate;
}

public String setDepartureDate(String departureDate) {
this.departureDate = departureDate;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
public class TripSearchRequest {
private String from;
private String to;
private String date;

public TripSearchRequest() {

}

public TripSearchRequest(String from, String to) {
public TripSearchRequest(String from, String to, String date) {
this.from = from;
this.to = to;
this.date = date;
}


public String getFrom() {
return from;
}
Expand All @@ -29,5 +30,13 @@ public String getTo() {
public void setTo(String to) {
this.to = to;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package edu.drexel.TrainDemo.trips.models.entities;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity(name = "calendar")
public class CalendarEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private boolean monday;
private boolean tuesday;
private boolean wednesday;
private boolean thursday;
private boolean friday;
private boolean saturday;
private boolean sunday;
// private Date startDate;
// private Date endDate;

protected CalendarEntity() {
}

public CalendarEntity(boolean monday,
boolean tuesday,
boolean wednesday,
boolean thursday,
boolean friday,
boolean saturday,
boolean sunday) {
this.monday = monday;
this.tuesday = tuesday;
this.wednesday = wednesday;
this.thursday = thursday;
this.friday = friday;
this.saturday = saturday;
this.sunday = sunday;
}


public boolean isMonday() {
return monday;
}

public boolean isTuesday() {
return tuesday;
}

public boolean isWednesday() {
return wednesday;
}

public boolean isThursday() {
return thursday;
}

public boolean isFriday() {
return friday;
}

public boolean isSaturday() {
return saturday;
}

public boolean isSunday() {
return sunday;
}

@Override
public String toString() {
return "Calendar{" +
"id=" + id +
", monday=" + monday +
", tuesday=" + tuesday +
", wednesday=" + wednesday +
", thursday=" + thursday +
", friday=" + friday +
", saturday=" + saturday +
", sunday=" + sunday +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package edu.drexel.TrainDemo.trips.models.entities;

import javax.persistence.*;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Entity(name = "trip")
Expand All @@ -9,10 +12,13 @@ public class TripEntity {
@Id
private long id;
private long routeId;
private long calendarId;
private String headsign;
private boolean direction;

@OneToOne(fetch= FetchType.LAZY)
@JoinColumn(name = "calendar_id")
private CalendarEntity calendarEntity;

@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "trip_id")
private List<StopTimeEntity> stops;
Expand All @@ -38,6 +44,33 @@ public StopTimeEntity getStopByStationId(String stopId) {
return null;
}

public boolean isTripOnDate(String date)
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this code into the constructor of Itinerary instead?

LocalDate localDate = LocalDate.parse(date, formatter);
DayOfWeek dayOfWeek = localDate.getDayOfWeek();

switch (dayOfWeek)
{
case SUNDAY:
return calendarEntity.isSunday();
case MONDAY:
return calendarEntity.isMonday();
case TUESDAY:
return calendarEntity.isTuesday();
case WEDNESDAY:
return calendarEntity.isWednesday();
case THURSDAY:
return calendarEntity.isThursday();
case FRIDAY:
return calendarEntity.isFriday();
case SATURDAY:
return calendarEntity.isSaturday();
default:
return false;
}
}

@Override
public String toString() {
return "TripEntity{" +
Expand All @@ -48,4 +81,4 @@ public String toString() {
", direction=" + direction +
'}';
}
}
}
23 changes: 13 additions & 10 deletions src/main/java/edu/drexel/TrainDemo/trips/services/TripService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public TripService(StationRepository stationRepository, TripRepository tripRepos
public List<Itinerary> getMatchingTrips(TripSearchRequest searchRequest) {
String toId = searchRequest.getTo();
String fromId = searchRequest.getFrom();
String date = searchRequest.getDate();

StationEntity toStation = safeGetStationFromId(toId);
StationEntity fromStation = safeGetStationFromId(fromId);
Expand All @@ -51,16 +52,18 @@ public List<Itinerary> getMatchingTrips(TripSearchRequest searchRequest) {
StopTimeEntity fromStopTimeEntity = trip.getStopByStationId(fromId);
StopTimeEntity toStopTimeEntity = trip.getStopByStationId(toId);

resultList.add(
new Itinerary(
trip,
fromStation,
toStation,
fromStopTimeEntity.getDepartureTime(),
toStopTimeEntity.getArrivalTime()
)
);

if (trip.isTripOnDate(date)) {
resultList.add(
new Itinerary(
trip,
fromStation,
toStation,
fromStopTimeEntity.getDepartureTime(),
toStopTimeEntity.getArrivalTime(),
date
)
);
}
}

return resultList;
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/templates/trips/search_trip.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@
<html xmlns:th="https://www.thymeleaf.org">
<head>
<th:block th:replace="base :: header"/>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<th:block th:replace="base :: navbar"/>
<h1>Search Trips</h1>
<!--/*@thymesVar id="TripSearchRequest" type="edu.drexel.TrainDemo.trips.models.TripSearchRequest"*/-->

<!--<h4 id="selectedDateVal"></h4>-->
<script>
$( function() {
$.datepicker.setDefaults({
onClose:function(date, inst){
$("#selectedDateVal").html(date);
}
});

$( "#datepicker" ).datepicker();
});
</script>

<form action="#" id="userProfileForm" method="post" th:action="@{/trips/search/submit}"
th:object="${TripSearchRequest}">
<label>Departure Date: <input type="text" id="datepicker" th:field="*{date}"></label>

@SaffatHasan SaffatHasan Mar 9, 2020

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does something like th:type="${#date}" work here?
Saw <p th:text="${#dates.format(standardDate, 'dd-MM-yyyy HH:mm')}"></p> online at this link.

<br/>
<label>From</label>
<select th:field="*{from}">
<option value="">Select From</option>
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/trips/search_trip_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<tr>
<th>TRIP ID</th>
<th>FROM station</th>
<th>DEPARTURE DATE</th>
<th>DEPARTURE time</th>
<th>TO station</th>
<th>ARRIVAL time</th>
Expand All @@ -19,6 +20,7 @@
<tr>
<td th:text="${itinerary.trip.id}"></td>
<td th:text="${itinerary.from.name}"></td>
<td th:text="${itinerary.departureDate}"></td>
<td th:text="${itinerary.departure}"></td>
<td th:text="${itinerary.to.name}"></td>
<td th:text="${itinerary.arrival}"></td>
Expand Down