From 30c2bd5fc08cd78f952c0099250531dafb02cee6 Mon Sep 17 00:00:00 2001 From: Jottyfan Date: Sat, 19 Jul 2025 20:29:23 +0200 Subject: [PATCH] restrict business camp overview by current year --- .classpath | 7 ++++++ .settings/org.eclipse.wst.common.component | 20 ++++++++++------ build.gradle | 2 +- .../business/bookings/BookingsController.java | 22 ++++++++++-------- .../business/bookings/BookingsRepository.java | 23 ++++++++++++++++++- .../business/bookings/BookingsService.java | 8 +++++-- .../templates/business/bookings.html | 13 ++++++++--- .../resources/templates/business/camp.html | 2 +- src/main/resources/templates/template.html | 2 +- 9 files changed, 74 insertions(+), 25 deletions(-) diff --git a/.classpath b/.classpath index f3bdce0..607b789 100644 --- a/.classpath +++ b/.classpath @@ -12,6 +12,13 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 59fc2ab..31a62d0 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,8 +1,14 @@ - - - - - - - + + + + + + + + + + + + + diff --git a/build.gradle b/build.gradle index ca094c0..da15fd5 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group = 'de.jottyfan.camporganizer' -version = '0.9.7' +version = '0.9.8' description = """CampOrganizer2""" diff --git a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsController.java b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsController.java index e86d21b..961ad5b 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsController.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsController.java @@ -1,10 +1,11 @@ package de.jottyfan.camporganizer.module.business.bookings; -import jakarta.annotation.security.RolesAllowed; +import java.time.LocalDate; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestParam; import de.jottyfan.camporganizer.module.business.bookings.model.AddPaymentBean; import de.jottyfan.camporganizer.module.business.bookings.model.BookerBean; import de.jottyfan.camporganizer.module.camplist.CommonController; +import jakarta.annotation.security.RolesAllowed; /** * @@ -29,21 +31,23 @@ public class BookingsController extends CommonController { @Autowired private BookingsService bookingsService; - @GetMapping("/business/bookings") + @GetMapping("/business/bookings/{year}") @RolesAllowed({"business_booking"}) - public String getBookings(Model model) { - model.addAttribute("bookers", bookingsService.getBookers(getCurrentUser())); + public String getBookings(Model model, @Nullable @PathVariable("year") Integer year) { + model.addAttribute("bookers", bookingsService.getBookers(getCurrentUser(), year)); model.addAttribute("addBean", new AddPaymentBean()); + model.addAttribute("year", LocalDate.now().getYear()); + model.addAttribute("years", bookingsService.getAllCampYears()); return "business/bookings"; } - @GetMapping("/business/bookings/{id}") + @GetMapping("/business/bookings_by_id/{id}") @RolesAllowed({"business_booking"}) public String getBooking(Model model, @PathVariable("id") Integer id) { BookerBean bean = bookingsService.getBooker(id, getCurrentUser()); model.addAttribute("booker", bean); model.addAttribute("addBean", new AddPaymentBean()); - return bean == null ? getBookings(model) : "business/booker"; + return bean == null ? getBookings(model, LocalDate.now().getYear()) : "business/booker"; } @PostMapping("/business/bookings/payment/{id}") @@ -54,13 +58,13 @@ public class BookingsController extends CommonController { return getBooking(model, id); } - @PostMapping("/business/bookings/listpayment/{id}") + @PostMapping("/business/bookings/listpayment/{id}/{year}") @RolesAllowed({"business_booking"}) - public String addListPayment(Model model, @ModelAttribute("bean") AddPaymentBean bean, @PathVariable("id") Integer id, @RequestParam(defaultValue = "") String search) { + public String addListPayment(Model model, @ModelAttribute("bean") AddPaymentBean bean, @PathVariable("id") Integer id, @PathVariable("year") Integer year, @RequestParam(defaultValue = "") String search) { Double payment = bean.getPayment(); bookingsService.addPayment(id, payment); LOGGER.debug("search is {}", search); model.addAttribute("search", search); - return getBookings(model); + return getBookings(model, year); } } diff --git a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsRepository.java b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsRepository.java index 5a9a8b7..269bfe6 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsRepository.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsRepository.java @@ -15,11 +15,14 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jooq.DSLContext; import org.jooq.Record; +import org.jooq.Record1; import org.jooq.Record10; import org.jooq.Record13; import org.jooq.SelectConditionStep; +import org.jooq.SelectSeekStep1; import org.jooq.SelectSeekStep4; import org.jooq.UpdateConditionStep; +import org.jooq.impl.DSL; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -49,10 +52,11 @@ public class BookingsRepository { * get a list of all registered persons that have booked the camp * * @param username the name of the current user in this session + * @param year the year of the camp; may be null * * @return a list of bookings; an empty one at least */ - public List getBookings(String username) { + public List getBookings(String username, Integer year) { SelectSeekStep4, EnumCamprole, EnumSex, String, String> sql = jooq // @formatter:off .select(T_PERSON.PK, T_PERSON.PROGRESS, T_PERSON.PAID, T_PERSON.FORENAME, T_PERSON.SURNAME, T_PERSON.CAMPROLE, T_PERSON.SEX, T_PERSON.CREATED, V_CAMP.NAME, V_CAMP.YEAR) @@ -61,6 +65,7 @@ public class BookingsRepository { .leftJoin(T_CAMPPROFILE).on(T_CAMPPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP)).and(T_CAMPPROFILE.MODULE.eq(EnumModule.business)) .leftJoin(T_PROFILE).on(T_PROFILE.PK.eq(T_CAMPPROFILE.FK_PROFILE)) .where(T_PROFILE.USERNAME.eq(username)) + .and(year != null ? V_CAMP.YEAR.eq(year.doubleValue()) : DSL.trueCondition()) .orderBy(T_PERSON.CAMPROLE, T_PERSON.SEX, T_PERSON.SURNAME, T_PERSON.FORENAME); // @formatter:on LOGGER.trace(sql); @@ -168,4 +173,20 @@ public class BookingsRepository { LOGGER.trace(sql); return sql.execute(); } + + /** + * get an ordered list of all camp years found in the database + * + * @return the list of camp years + */ + public List getAllCampYears() { + SelectSeekStep1, Double> sql = jooq + // @formatter:off + .selectDistinct(V_CAMP.YEAR) + .from(V_CAMP) + .orderBy(V_CAMP.YEAR); + // @formatter:on + LOGGER.trace(sql); + return sql.fetchInto(Integer.class); + } } diff --git a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsService.java b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsService.java index d63f42d..36d28ae 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsService.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/BookingsService.java @@ -18,8 +18,8 @@ public class BookingsService { @Autowired private BookingsRepository bookingsGateway; - public List getBookers(String username) { - return bookingsGateway.getBookings(username); + public List getBookers(String username, Integer year) { + return bookingsGateway.getBookings(username, year); } public BookerBean getBooker(Integer id, String username) { @@ -29,4 +29,8 @@ public class BookingsService { public Integer addPayment(Integer id, Double payment) { return bookingsGateway.addPayment(id, payment); } + + public List getAllCampYears() { + return bookingsGateway.getAllCampYears(); + } } diff --git a/src/main/resources/templates/business/bookings.html b/src/main/resources/templates/business/bookings.html index 46cec1e..0d040d4 100644 --- a/src/main/resources/templates/business/bookings.html +++ b/src/main/resources/templates/business/bookings.html @@ -8,7 +8,14 @@
-
Angemeldete Personen
+
+
Angemeldete Personen
+
im Jahr + + + +
+
@@ -25,12 +32,12 @@ - + - + diff --git a/src/main/resources/templates/template.html b/src/main/resources/templates/template.html index d74fcb8..1fd780a 100644 --- a/src/main/resources/templates/template.html +++ b/src/main/resources/templates/template.html @@ -79,7 +79,7 @@
-
+
diff --git a/src/main/resources/templates/business/camp.html b/src/main/resources/templates/business/camp.html index 06a75b2..0ba9c59 100644 --- a/src/main/resources/templates/business/camp.html +++ b/src/main/resources/templates/business/camp.html @@ -70,7 +70,7 @@