From e20c24d006fa4b4cc9cd8e220f8a355d456ae126 Mon Sep 17 00:00:00 2001 From: Jottyfan Date: Fri, 23 Feb 2024 15:36:37 +0100 Subject: [PATCH] added required price, see #6 --- build.gradle | 8 ++++- .../confirmation/person/PersonController.java | 12 +++++++- .../confirmation/person/PersonRepository.java | 29 +++++++++++++++++-- .../confirmation/person/PersonService.java | 10 +++++++ .../confirmation/person/model/PersonBean.java | 20 ++++++++++++- .../resources/templates/business/booker.html | 4 +++ .../templates/confirmation/person.html | 11 +++++++ 7 files changed, 88 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index f57882b..c22e337 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group = 'de.jottyfan.camporganizer' -version = '0.7.0' +version = '0.7.1' description = """CampOrganizer2""" @@ -89,6 +89,12 @@ dependencies { testImplementation 'org.springframework.security:spring-security-test' } +configurations { + runtime { + exclude(group = "commons-logging", module = "commons-logging") + } +} + test { useJUnitPlatform() } diff --git a/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonController.java b/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonController.java index 6cc1319..088921a 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonController.java +++ b/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonController.java @@ -3,6 +3,7 @@ package de.jottyfan.camporganizer.module.confirmation.person; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; @@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.PostMapping; import de.jottyfan.camporganizer.module.camplist.CommonController; import de.jottyfan.camporganizer.module.confirmation.person.model.PersonBean; +import jakarta.validation.Valid; /** * @@ -29,12 +31,20 @@ public class PersonController extends CommonController { model.addAttribute("person", personService.getPerson(username, pk)); model.addAttribute("camps", personService.getCamps(username)); model.addAttribute("annotations", personService.getAnnotations(pk)); + model.addAttribute("campPrice", personService.getCampPrice(pk)); return "confirmation/person"; } @PostMapping("/confirmation/person/update") - public String doUpdate(@ModelAttribute("bean") PersonBean bean, Model model) { + public String doUpdate(@Valid @ModelAttribute("person") PersonBean bean, BindingResult bindingResult, Model model) { String username = super.getCurrentUser(); + if (bindingResult.hasErrors()) { + model.addAttribute("currentUser", username); + model.addAttribute("camps", personService.getCamps(username)); + model.addAttribute("annotations", personService.getAnnotations(bean.getPk())); + model.addAttribute("campPrice", personService.getCampPrice(bean.getPk())); + return "confirmation/person"; + } personService.updatePerson(bean, username); return "redirect:/confirmation"; } diff --git a/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonRepository.java b/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonRepository.java index 6f484d2..8359359 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonRepository.java +++ b/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonRepository.java @@ -20,6 +20,7 @@ import org.apache.logging.log4j.Logger; import org.jooq.DSLContext; import org.jooq.InsertValuesStep2; import org.jooq.Record; +import org.jooq.Record1; import org.jooq.Record11; import org.jooq.Record4; import org.jooq.SelectConditionStep; @@ -133,6 +134,7 @@ public class PersonRepository { bean.setSex(r.get(T_PERSON.SEX)); bean.setStreet(r.get(T_PERSON.STREET)); bean.setZip(r.get(T_PERSON.ZIP)); + bean.setRequiredPrice(r.get(T_PERSON.REQUIRED_PRICE)); return bean; } return null; @@ -187,6 +189,7 @@ public class PersonRepository { .set(T_PERSON.ACCEPT, bean.getAccept()) .set(T_PERSON.CAMPROLE, bean.getCamprole()) .set(T_PERSON.FK_REGISTRATOR, fkRegistrator) + .set(T_PERSON.REQUIRED_PRICE, bean.getRequiredPrice()) .where(T_PERSON.PK.eq(bean.getPk())); // @formatter:on LOGGER.debug(sql3.toString()); @@ -300,9 +303,11 @@ public class PersonRepository { // @formatter:on LOGGER.debug(sql.toString()); StringBuilder buf = new StringBuilder(); - Iterator> i = sql.fetch().iterator(); + Iterator> i = sql + .fetch().iterator(); while (i.hasNext()) { - Record11 r = i.next(); + Record11 r = i + .next(); LocalDate birthdate = r.get(T_PERSON.BIRTHDATE); LocalDateTime arrive = r.get(T_CAMP.ARRIVE); LocalDateTime depart = r.get(T_CAMP.DEPART); @@ -318,7 +323,7 @@ public class PersonRepository { if (bookerForename == null && bookerSurname == null) { buf.append(String.format("angemeldet ohne Registrierung am %s\n", createdString)); } else { - buf.append(String.format("angemeldet von %s %s am %s\n", bookerForename, bookerSurname, createdString)); + buf.append(String.format("angemeldet von %s %s am %s\n", bookerForename, bookerSurname, createdString)); } if (registratorForename != null || registratorSurname != null) { buf.append(String.format("bearbeitet von %s %s\n", registratorForename, registratorSurname)); @@ -339,4 +344,22 @@ public class PersonRepository { } return buf.toString(); } + + /** + * get the price information of the camp that the person is registered for + * + * @param pkPerson the ID of the person + * @return the camp price information + */ + public String getCampprice(Integer pkPerson) { + SelectConditionStep> sql = jooq + // @formatter:off + .select(T_CAMP.PRICE) + .from(T_PERSON) + .leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_PERSON.FK_CAMP)) + .where(T_PERSON.PK.eq(pkPerson)); + // @formatter:on + LOGGER.trace(sql); + return sql.fetchOne(T_CAMP.PRICE); + } } diff --git a/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonService.java b/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonService.java index 33fdc1e..db8e675 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonService.java +++ b/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/PersonService.java @@ -33,4 +33,14 @@ public class PersonService { public String getAnnotations(Integer pk) { return gateway.getAnnotations(pk); } + + /** + * get the price of the camp + * + * @param pk the ID of the person, not the camp + * @return the camp price + */ + public String getCampPrice(Integer pk) { + return gateway.getCampprice(pk); + } } diff --git a/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/model/PersonBean.java b/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/model/PersonBean.java index d39ad1a..8e88362 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/model/PersonBean.java +++ b/src/main/java/de/jottyfan/camporganizer/module/confirmation/person/model/PersonBean.java @@ -1,6 +1,7 @@ package de.jottyfan.camporganizer.module.confirmation.person.model; import java.io.Serializable; +import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; @@ -8,6 +9,7 @@ import org.springframework.format.annotation.DateTimeFormat; import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole; import de.jottyfan.camporganizer.db.jooq.enums.EnumSex; +import jakarta.validation.constraints.DecimalMin; /** * @@ -15,7 +17,7 @@ import de.jottyfan.camporganizer.db.jooq.enums.EnumSex; * */ public class PersonBean implements Serializable { - private static final long serialVersionUID = 2L; + private static final long serialVersionUID = 3L; private Integer pk; private String forename; @@ -35,6 +37,8 @@ public class PersonBean implements Serializable { private EnumSex sex; private Integer fkRegistrator; private String comment; + @DecimalMin(value = "0") + private BigDecimal requiredPrice; /** * @return the forename @@ -273,4 +277,18 @@ public class PersonBean implements Serializable { public void setPk(Integer pk) { this.pk = pk; } + + /** + * @return the requiredPrice + */ + public BigDecimal getRequiredPrice() { + return requiredPrice; + } + + /** + * @param requiredPrice the requiredPrice to set + */ + public void setRequiredPrice(BigDecimal requiredPrice) { + this.requiredPrice = requiredPrice; + } } diff --git a/src/main/resources/templates/business/booker.html b/src/main/resources/templates/business/booker.html index 5de3451..593f3b3 100644 --- a/src/main/resources/templates/business/booker.html +++ b/src/main/resources/templates/business/booker.html @@ -43,6 +43,10 @@ Freizeitpreis + + davon für + + Kontostand diff --git a/src/main/resources/templates/confirmation/person.html b/src/main/resources/templates/confirmation/person.html index f3fad97..b9a6486 100644 --- a/src/main/resources/templates/confirmation/person.html +++ b/src/main/resources/templates/confirmation/person.html @@ -44,6 +44,7 @@
+ [[${error}]]
@@ -93,6 +94,16 @@
+
+ +
+ [[${error}]]
+ +
+
+ von offiziell  +
+