Skip to content
Snippets Groups Projects
Commit 2567ee6e authored by Chris Lemaire's avatar Chris Lemaire
Browse files

Add initial timeslot selection

parent 1b8dfb33
No related branches found
No related tags found
1 merge request!17WIP: Timeslots setup [DO NOT MERGE]
package nl.tudelft.ewi.walkytalky;
import lombok.NoArgsConstructor;
import nl.tudelft.ewi.walkytalky.model.*;
import nl.tudelft.ewi.walkytalky.repository.AdminRepository;
import nl.tudelft.ewi.walkytalky.repository.AreaRepository;
......@@ -7,9 +8,13 @@ import nl.tudelft.ewi.walkytalky.repository.PatientRepository;
import nl.tudelft.ewi.walkytalky.repository.TabletRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.Collections;
@NoArgsConstructor
@Service
@Profile("!production")
public class DataLoader {
@Autowired
......@@ -34,8 +39,10 @@ public class DataLoader {
private Patient patient2;
private Patient patient3;
@PostConstruct
private void setup() {
setupAreas();
setupTablets();
setupPatients();
}
......@@ -58,10 +65,10 @@ public class DataLoader {
private void setupPatients() {
patient1 = patientRepository.save(new Patient(
null, "id1", new Name("Jan", "Janssen", null), area1, Collections.emptyList()));
null, "id1", "token1", new Name("Jan", "Janssen", null), area1, Collections.emptyList()));
patient2 = patientRepository.save(new Patient(
null, "id2", new Name("Yrma", "Tamboerijn", null), area1, Collections.emptyList()));
null, "id2", "token2", new Name("Yrma", "Tamboerijn", null), area1, Collections.emptyList()));
patient3 = patientRepository.save(new Patient(
null, "id3", new Name("Christiaan", "Bonebakker", null), area1, Collections.emptyList()));
null, "id3", "token3", new Name("Christiaan", "Bonebakker", null), area1, Collections.emptyList()));
}
}
package nl.tudelft.ewi.walkytalky.controller;
import nl.tudelft.ewi.walkytalky.exception.TimeslotClaimedException;
import nl.tudelft.ewi.walkytalky.model.Patient;
import nl.tudelft.ewi.walkytalky.model.Timeslot;
import nl.tudelft.ewi.walkytalky.repository.PatientRepository;
import nl.tudelft.ewi.walkytalky.services.TimeslotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.convert.Jsr310Converters;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Map;
/**
* Controller for guests to pick timeslots with.
......@@ -8,5 +20,40 @@ import org.springframework.stereotype.Controller;
* getting the waiting room URL, etc.
*/
@Controller
@RequestMapping("/timeslot/")
public class TimeslotController {
@Autowired
private PatientRepository patientRepository;
@Autowired
private TimeslotService timeslotService;
@GetMapping("/{guestToken}")
public String landing(@PathVariable String guestToken,
Model model) {
Patient patient = patientRepository.findByToken(guestToken);
assert patient != null;
long today = LocalDateTime.now().toLocalDate().toEpochDay();
Map<Timeslot, Integer> timeslots = timeslotService.availableSlots(
patient.getArea(), today);
model.addAttribute("token", guestToken);
model.addAttribute("patient", patient);
model.addAttribute("timeslots", timeslots);
return "guest/index";
}
@PostMapping("/{guestToken}")
public String postTimeslot(@PathVariable String guestToken,
@RequestBody Timeslot timeslot) throws TimeslotClaimedException {
Patient patient = patientRepository.findByToken(guestToken);
assert patient != null;
timeslotService.claimSlot(timeslot, patient);
return "redirect:/timeslot/" + guestToken;
}
}
......@@ -2,11 +2,13 @@ package nl.tudelft.ewi.walkytalky.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Embeddable;
import javax.validation.constraints.NotNull;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Embeddable
public class Name {
......
......@@ -5,7 +5,10 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Embeddable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
@Data
@NoArgsConstructor
......@@ -21,4 +24,18 @@ public class Timeslot {
minuteStart = start.getMinute();
minuteEnd = end.getMinute();
}
public String value() {
return
}
public String name() {
return startLocalDateTime()
.format(DateTimeFormatter.ISO_DATE_TIME);
}
public LocalDateTime startLocalDateTime() {
return LocalDateTime
.of(LocalDate.ofEpochDay(day), LocalTime.of(minuteStart / 60, minuteStart % 60));
}
}
......@@ -9,8 +9,8 @@ import java.util.List;
* The repository where the patients are stored. These can be included in classes using the @Autowired annotation
*/
public interface PatientRepository extends CrudRepository<Patient, Long> {
@Override
List<Patient> findAll();
Patient findByToken(String token);
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="container">
<body>
<section layout:fragment="container">
<script type="text/javascript" src="/webjars/bootstrap-select/js/bootstrap-select.min.js"></script>
<link rel="stylesheet" href="/webjars/bootstrap-select/css/bootstrap-select.min.css" type="text/css"/>
<div class="container mt-4">
<form method="post" th:action="@{/timeslot/{token}(token=${guestToken})}">
<select class="selectpicker" id="timeslotSelect">
<th:block th:each="timeslot : ${timeslots.entrySet()}">
<option th:value="${timeslot.key}"
th:text="${timeslot.key.name()}">
</option>
</th:block>
</select>
<button type="submit">Choose</button>
</form>
</div>
</section>
</body>
</html>
......@@ -7,9 +7,6 @@
<h1>Home</h1>
<p th:text="#{hello}"></p>
</div>
<script type="application/javascript">
createJitsiRoom("id42244", "password", "Chris")
</script>
</section>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment