This commit is contained in:
@@ -35,7 +35,7 @@ public class IndexController extends CommonController {
|
||||
@GetMapping("/")
|
||||
public String index(Model model) {
|
||||
super.setupSession(model, request);
|
||||
model.addAttribute("camps", service.getAllCamps());
|
||||
model.addAttribute("camps", service.getAllCamps(true));
|
||||
return super.isLoggedIn(request) ? dashboard(model) : "/index";
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class IndexController extends CommonController {
|
||||
model.addAttribute("mybookings", service.getBookingsOf(super.getCurrentUser(request)));
|
||||
model.addAttribute("bookingBean", new BookingBean());
|
||||
model.addAttribute("keycloakProfileUrl", keycloak.getUserClientUrl());
|
||||
model.addAttribute("camps", service.getAllCamps());
|
||||
model.addAttribute("camps", service.getAllCamps(true));
|
||||
return "/dashboard";
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -28,8 +29,8 @@ public class IndexService {
|
||||
*
|
||||
* @return the list of found camps
|
||||
*/
|
||||
public List<VCampRecord> getAllCamps() {
|
||||
Condition condition = V_CAMP.DEPART.greaterOrEqual(LocalDateTime.now());
|
||||
public List<VCampRecord> getAllCamps(Boolean upcomingOnly) {
|
||||
Condition condition = upcomingOnly ? V_CAMP.DEPART.greaterOrEqual(LocalDateTime.now()) : DSL.trueCondition();
|
||||
Stream<VCampRecord> stream = gateway.getAllCamps(condition);
|
||||
List<VCampRecord> list = new ArrayList<>();
|
||||
stream.forEach(o -> list.add(o));
|
||||
|
||||
@@ -31,13 +31,17 @@ public class RegistrationController extends CommonController {
|
||||
@GetMapping("/registration/{fkCamp}")
|
||||
public String index(@PathVariable(name = "fkCamp", required = true) Integer fkCamp, Model model) {
|
||||
super.setupSession(model, request);
|
||||
CampBean campBean = service.getCamp(fkCamp);
|
||||
model.addAttribute("camp", campBean);
|
||||
RegistrationBean bean = new RegistrationBean();
|
||||
bean.setFkCamp(fkCamp);
|
||||
bean.setRegisterInKeycloak(true); // we want people to register generally
|
||||
model.addAttribute("bean", bean);
|
||||
return "/registration/registration";
|
||||
if (service.campIsNotYetOver(fkCamp)) {
|
||||
CampBean campBean = service.getCamp(fkCamp);
|
||||
model.addAttribute("camp", campBean);
|
||||
RegistrationBean bean = new RegistrationBean();
|
||||
bean.setFkCamp(fkCamp);
|
||||
bean.setRegisterInKeycloak(true); // we want people to register generally
|
||||
model.addAttribute("bean", bean);
|
||||
return "/registration/registration";
|
||||
} else {
|
||||
return "/registration/isover";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/registration/register")
|
||||
|
||||
@@ -239,4 +239,26 @@ public class RegistrationGateway {
|
||||
});
|
||||
return lrw.getCounter();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the end date of the camp is not yet over
|
||||
*
|
||||
* @param fkCamp the camp ID
|
||||
* @return true or false
|
||||
*/
|
||||
public Boolean campIsNotYetOver(Integer fkCamp) {
|
||||
SelectConditionStep<Record1<LocalDateTime>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(T_CAMP.DEPART)
|
||||
.from(T_CAMP)
|
||||
.where(T_CAMP.PK.eq(fkCamp));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
for (Record1<LocalDateTime> r : sql.fetch()) {
|
||||
LocalDateTime depart = r.get(T_CAMP.DEPART);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
return now.isBefore(depart);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,16 @@ public class RegistrationService {
|
||||
@Autowired
|
||||
private KeycloakRepository keycloak;
|
||||
|
||||
/**
|
||||
* return true if the camp is not yet over
|
||||
*
|
||||
* @param fkCamp the camp ID
|
||||
* @return true or false
|
||||
*/
|
||||
public Boolean campIsNotYetOver(Integer fkCamp) {
|
||||
return gateway.campIsNotYetOver(fkCamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the camp
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user