restrict business camp overview by current year

This commit is contained in:
Jottyfan
2025-07-19 20:29:23 +02:00
parent 27c1669ed3
commit 30c2bd5fc0
9 changed files with 74 additions and 25 deletions

View File

@@ -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);
}
}

View File

@@ -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<BookerBean> getBookings(String username) {
public List<BookerBean> getBookings(String username, Integer year) {
SelectSeekStep4<Record10<Integer, EnumProgress, BigDecimal, String, String, EnumCamprole, EnumSex, LocalDateTime, String, Double>, 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<Integer> getAllCampYears() {
SelectSeekStep1<Record1<Double>, 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);
}
}

View File

@@ -18,8 +18,8 @@ public class BookingsService {
@Autowired
private BookingsRepository bookingsGateway;
public List<BookerBean> getBookers(String username) {
return bookingsGateway.getBookings(username);
public List<BookerBean> 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<Integer> getAllCampYears() {
return bookingsGateway.getAllCampYears();
}
}