From 93a1289629fcb21488b1ac031c834429c914241a Mon Sep 17 00:00:00 2001 From: Jottyfan Date: Sun, 26 Mar 2023 21:18:57 +0200 Subject: [PATCH] https://gitlab.com/jottyfan/camporganizer2/-/issues/39 --- build.gradle | 4 +- .../module/admin/AdminRepository.java | 61 ++++++++++++++++--- .../camporganizer/module/admin/CampBean.java | 52 +++++++++++++--- .../business/bookings/impl/BookerBean.java | 15 +++++ .../bookings/impl/BookingsRepository.java | 20 +++++- .../business/business/BusinessController.java | 1 - .../business/business/impl/BusinessBean.java | 18 +++++- .../business/impl/BusinessRepository.java | 12 ++-- .../business/privileges/impl/ProfileBean.java | 11 ---- .../module/camplist/BookingBean.java | 4 ++ .../confirmation/impl/BookingBean.java | 2 + .../resources/templates/admin/camp_edit.html | 36 +++++++++-- .../resources/templates/admin/document.html | 1 + .../templates/admin/document_edit.html | 3 +- .../resources/templates/business/booker.html | 8 ++- .../templates/confirmation/person.html | 1 + src/main/resources/templates/dashboard.html | 2 +- .../templates/registration/registration.html | 1 + src/main/resources/templates/template.html | 4 +- 19 files changed, 208 insertions(+), 48 deletions(-) diff --git a/build.gradle b/build.gradle index 2f5d8bb..c0c4759 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: 'war' apply plugin: 'application' group = 'de.jottyfan.camporganizer' -version = '0.3.9' +version = '0.4.0' sourceCompatibility = 17 mainClassName = "de.jottyfan.camporganizer.Main" @@ -79,7 +79,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' - implementation 'de.jottyfan:COJooq:2021.02' + implementation 'de.jottyfan:COJooq:2023.03' implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.0.0' runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat' testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/src/main/java/de/jottyfan/camporganizer/module/admin/AdminRepository.java b/src/main/java/de/jottyfan/camporganizer/module/admin/AdminRepository.java index 1c81160..7d9c33d 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/admin/AdminRepository.java +++ b/src/main/java/de/jottyfan/camporganizer/module/admin/AdminRepository.java @@ -7,6 +7,8 @@ import static de.jottyfan.camporganizer.db.jooq.Tables.T_LOCATION; import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSON; import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -23,6 +25,7 @@ import org.jooq.DeleteConditionStep; import org.jooq.Field; import org.jooq.InsertResultStep; import org.jooq.InsertReturningStep; +import org.jooq.InsertValuesStep11; import org.jooq.InsertValuesStep3; import org.jooq.Record4; import org.jooq.Record5; @@ -401,7 +404,8 @@ public class AdminRepository { LOGGER.debug(sql2.toString()); sql2.execute(); } else { - lrw.putString("error", String.format("Es gibt bereits %d Anmeldungen. Die Freizeit kann daher nicht gelöscht werden.", registrations)); + lrw.putString("error", String + .format("Es gibt bereits %d Anmeldungen. Die Freizeit kann daher nicht gelöscht werden.", registrations)); } }); return lrw.getString("error"); @@ -411,14 +415,57 @@ public class AdminRepository { * upsert the camp * * @param bean the bean + * @return an error message, if any */ public String upsertCamp(@Valid CampBean bean) { - if (bean.getPk() == null) { - // TODO: insert - } else { - // TODO: update - } - return "not yet implemented"; + jooq.transaction(t -> { + LocalDate arriveDate = bean.getArrive(); + LocalDate departDate = bean.getDepart(); + LocalDateTime arrive = arriveDate == null ? null : arriveDate.atStartOfDay(); + LocalDateTime depart = departDate == null ? null : departDate.atStartOfDay(); + if (bean.getPk() == null) { + InsertValuesStep11 sql = DSL + .using(t) + // @formatter:off + .insertInto(T_CAMP, + T_CAMP.ARRIVE, + T_CAMP.COUNTRIES, + T_CAMP.DEPART, + T_CAMP.FK_DOCUMENT, + T_CAMP.FK_LOCATION, + T_CAMP.FK_PROFILE, + T_CAMP.LOCK_SALES, + T_CAMP.MAX_AGE, + T_CAMP.MIN_AGE, + T_CAMP.NAME, + T_CAMP.PRICE) + .values(arrive, bean.getCountries(), depart, bean.getFkDocument(), bean.getFkLocation(), bean.getFkProfile(), + bean.getLockSales() != null ? bean.getLockSales() : false, bean.getMaxAge(), bean.getMinAge(), bean.getName(), bean.getPrice()); + // @formatter:on + LOGGER.debug(sql.toString()); + sql.execute(); + } else { + UpdateConditionStep sql = DSL.using(t) + // @formatter:off + .update(T_CAMP) + .set(T_CAMP.ARRIVE, arrive) + .set(T_CAMP.COUNTRIES, bean.getCountries()) + .set(T_CAMP.DEPART, depart) + .set(T_CAMP.FK_DOCUMENT, bean.getFkDocument()) + .set(T_CAMP.FK_LOCATION, bean.getFkLocation()) + .set(T_CAMP.FK_PROFILE, bean.getFkProfile()) + .set(T_CAMP.LOCK_SALES, bean.getLockSales() != null ? bean.getLockSales() : false) + .set(T_CAMP.MAX_AGE, bean.getMaxAge()) + .set(T_CAMP.MIN_AGE, bean.getMinAge()) + .set(T_CAMP.NAME, bean.getName()) + .set(T_CAMP.PRICE, bean.getPrice()) + .where(T_CAMP.PK.eq(bean.getPk())); + // @formatter:on + LOGGER.debug(sql.toString()); + sql.execute(); + } + }); + return null; } /** diff --git a/src/main/java/de/jottyfan/camporganizer/module/admin/CampBean.java b/src/main/java/de/jottyfan/camporganizer/module/admin/CampBean.java index ee38390..4946330 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/admin/CampBean.java +++ b/src/main/java/de/jottyfan/camporganizer/module/admin/CampBean.java @@ -1,11 +1,16 @@ package de.jottyfan.camporganizer.module.admin; import java.io.Serializable; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import org.springframework.format.annotation.DateTimeFormat; + import de.jottyfan.camporganizer.db.jooq.tables.records.TCampRecord; /** @@ -31,9 +36,11 @@ public class CampBean implements Serializable { @NotNull private Integer minAge; @NotNull - private LocalDateTime arrive; + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate arrive; @NotNull - private LocalDateTime depart; + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate depart; private String countries; @NotNull private String price; @@ -49,9 +56,11 @@ public class CampBean implements Serializable { return null; } CampBean bean = new CampBean(); - bean.setArrive(r.getArrive()); + LocalDateTime arrive = r.getArrive(); + LocalDateTime depart = r.getDepart(); + bean.setArrive(arrive == null ? null : arrive.toLocalDate()); bean.setCountries(r.getCountries()); - bean.setDepart(r.getDepart()); + bean.setDepart(depart == null ? null : depart.toLocalDate()); bean.setFkDocument(r.getFkDocument()); bean.setFkLocation(r.getFkLocation()); bean.setFkProfile(r.getFkProfile()); @@ -179,28 +188,28 @@ public class CampBean implements Serializable { /** * @return the arrive */ - public LocalDateTime getArrive() { + public LocalDate getArrive() { return arrive; } /** * @param arrive the arrive to set */ - public void setArrive(LocalDateTime arrive) { + public void setArrive(LocalDate arrive) { this.arrive = arrive; } /** * @return the depart */ - public LocalDateTime getDepart() { + public LocalDate getDepart() { return depart; } /** * @param depart the depart to set */ - public void setDepart(LocalDateTime depart) { + public void setDepart(LocalDate depart) { this.depart = depart; } @@ -231,4 +240,31 @@ public class CampBean implements Serializable { public void setPrice(String price) { this.price = price; } + + /** + * @return the countriesList + */ + public List getCountriesList() { + String[] splitted = countries == null ? null : countries.split(","); + List list = new ArrayList<>(); + if (splitted != null && splitted.length > 0) { + for (String s : splitted) { + list.add(s.trim()); + } + } + return list; + } + + /** + * @param countriesList the countriesList to set + */ + public void setCountriesList(List countriesList) { + StringBuilder buf = new StringBuilder(); + boolean first = true; + for (String s : countriesList) { + buf.append(first ? "" : ", ").append(s); + first = false; + } + this.countries = buf.toString(); + } } diff --git a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/impl/BookerBean.java b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/impl/BookerBean.java index 15d5d9b..3b5531d 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/impl/BookerBean.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/impl/BookerBean.java @@ -22,6 +22,7 @@ public class BookerBean implements Serializable { private String camp; private String price; private Integer campId; + private BigDecimal requiredPrice; /** * @return the accept @@ -126,4 +127,18 @@ public class BookerBean implements Serializable { public void setCampId(Integer campId) { this.campId = campId; } + + /** + * @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/java/de/jottyfan/camporganizer/module/business/bookings/impl/BookingsRepository.java b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/impl/BookingsRepository.java index 2eb0355..f6023c8 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/bookings/impl/BookingsRepository.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/bookings/impl/BookingsRepository.java @@ -15,7 +15,7 @@ import org.apache.logging.log4j.Logger; import org.jooq.DSLContext; import org.jooq.Record; import org.jooq.Record10; -import org.jooq.Record12; +import org.jooq.Record13; import org.jooq.SelectConditionStep; import org.jooq.SelectSeekStep4; import org.jooq.UpdateConditionStep; @@ -89,9 +89,21 @@ public class BookingsRepository { * @return the booker bean or null */ public BookerBean getBooking(Integer id, String username) { - SelectConditionStep> sql = jooq + SelectConditionStep> sql = jooq // @formatter:off - .select(T_PERSON.PK, T_PERSON.ACCEPT, T_PERSON.PAID, T_PERSON.FORENAME, T_PERSON.SURNAME, T_PERSON.CAMPROLE, T_PERSON.SEX, T_PERSON.CREATED, V_CAMP.NAME, V_CAMP.YEAR, V_CAMP.PRICE, V_CAMP.PK) + .select(T_PERSON.PK, + T_PERSON.ACCEPT, + T_PERSON.PAID, + T_PERSON.FORENAME, + T_PERSON.SURNAME, + T_PERSON.CAMPROLE, + T_PERSON.SEX, + T_PERSON.CREATED, + T_PERSON.REQUIRED_PRICE, + V_CAMP.NAME, + V_CAMP.YEAR, + V_CAMP.PRICE, + V_CAMP.PK) .from(T_PERSON) .leftJoin(V_CAMP).on(V_CAMP.PK.eq(T_PERSON.FK_CAMP)) .leftJoin(T_SALESPROFILE).on(T_SALESPROFILE.FK_CAMP.eq(T_PERSON.FK_CAMP)) @@ -108,6 +120,7 @@ public class BookingsRepository { String surname = r.get(T_PERSON.SURNAME); EnumCamprole role = r.get(T_PERSON.CAMPROLE); EnumSex sex = r.get(T_PERSON.SEX); + BigDecimal requiredPrice = r.get(T_PERSON.REQUIRED_PRICE); String campName = r.get(V_CAMP.NAME); Double campYear = r.get(V_CAMP.YEAR); Integer campId = r.get(V_CAMP.PK); @@ -122,6 +135,7 @@ public class BookingsRepository { bean.setCamp(String.format("%s %4.0f", campName, campYear)); bean.setCampId(campId); bean.setPrice(r.get(V_CAMP.PRICE)); + bean.setRequiredPrice(requiredPrice); return bean; } } diff --git a/src/main/java/de/jottyfan/camporganizer/module/business/business/BusinessController.java b/src/main/java/de/jottyfan/camporganizer/module/business/business/BusinessController.java index 5352d56..1201e42 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/business/BusinessController.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/business/BusinessController.java @@ -26,7 +26,6 @@ public class BusinessController extends CommonController { @GetMapping("/business") public String getIndex(Model model) { String username = indexService.getCurrentUser(request); - model.addAttribute("currentUser", username); model.addAttribute("campBudgets", indexService.getCampBudgets(username)); return "business/business"; } diff --git a/src/main/java/de/jottyfan/camporganizer/module/business/business/impl/BusinessBean.java b/src/main/java/de/jottyfan/camporganizer/module/business/business/impl/BusinessBean.java index 5e8f367..bce06d8 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/business/impl/BusinessBean.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/business/impl/BusinessBean.java @@ -21,9 +21,10 @@ public class BusinessBean implements Serializable { private final String locationName; private BigDecimal paid; private boolean changed; + private BigDecimal requiredPrice; public BusinessBean(Integer fkPerson, String forename, String surname, String campName, String campPrice, - LocalDateTime campArrive, String locationName, BigDecimal paid) { + LocalDateTime campArrive, String locationName, BigDecimal paid, BigDecimal requiredPrice) { super(); this.fkPerson = fkPerson; this.forename = forename; @@ -34,6 +35,7 @@ public class BusinessBean implements Serializable { this.locationName = locationName; this.paid = paid; this.changed = false; + this.requiredPrice = requiredPrice; } /** @@ -103,4 +105,18 @@ public class BusinessBean implements Serializable { public boolean isChanged() { return changed; } + + /** + * @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/java/de/jottyfan/camporganizer/module/business/business/impl/BusinessRepository.java b/src/main/java/de/jottyfan/camporganizer/module/business/business/impl/BusinessRepository.java index 63a85df..fcf5e58 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/business/impl/BusinessRepository.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/business/impl/BusinessRepository.java @@ -16,7 +16,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jooq.DSLContext; import org.jooq.Record4; -import org.jooq.Record8; +import org.jooq.Record9; import org.jooq.SelectConditionStep; import org.jooq.SelectSeekStep1; import org.jooq.UpdateConditionStep; @@ -80,7 +80,7 @@ public class BusinessRepository { * @return a list of business beans; an empty one at least */ public List getAllRegistrations(String username) { - SelectConditionStep> sql = jooq + SelectConditionStep> sql = jooq // @formatter:off .select(T_PERSON.PK, T_PERSON.FORENAME, @@ -89,7 +89,8 @@ public class BusinessRepository { T_CAMP.PRICE, T_CAMP.ARRIVE, T_LOCATION.NAME, - T_PERSON.PAID) + T_PERSON.PAID, + T_PERSON.REQUIRED_PRICE) .from(T_PERSON) .leftJoin(T_CAMP).on(T_CAMP.PK.eq(T_PERSON.FK_CAMP)) .leftJoin(T_LOCATION).on(T_LOCATION.PK.eq(T_CAMP.FK_LOCATION)) @@ -99,7 +100,7 @@ public class BusinessRepository { // @formatter:on LOGGER.debug(sql.toString()); List list = new ArrayList<>(); - for (Record8 r : sql.fetch()) { + for (Record9 r : sql.fetch()) { Integer fkPerson = r.get(T_PERSON.PK); String forename = r.get(T_PERSON.FORENAME); String surname = r.get(T_PERSON.SURNAME); @@ -108,7 +109,8 @@ public class BusinessRepository { LocalDateTime campArrive = r.get(T_CAMP.ARRIVE); String locationName = r.get(T_CAMP.NAME); BigDecimal paid = r.get(T_PERSON.PAID); - list.add(new BusinessBean(fkPerson, forename, surname, campName, campPrice, campArrive, locationName, paid)); + BigDecimal requiredPrice = r.get(T_PERSON.REQUIRED_PRICE); + list.add(new BusinessBean(fkPerson, forename, surname, campName, campPrice, campArrive, locationName, paid, requiredPrice)); } return list; } diff --git a/src/main/java/de/jottyfan/camporganizer/module/business/privileges/impl/ProfileBean.java b/src/main/java/de/jottyfan/camporganizer/module/business/privileges/impl/ProfileBean.java index 179d1ef..7ba82eb 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/business/privileges/impl/ProfileBean.java +++ b/src/main/java/de/jottyfan/camporganizer/module/business/privileges/impl/ProfileBean.java @@ -2,7 +2,6 @@ package de.jottyfan.camporganizer.module.business.privileges.impl; import java.io.Serializable; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; /** * @@ -22,16 +21,6 @@ public class ProfileBean implements Serializable { return new StringBuilder().append(forename).append(" ").append(surname).toString(); } - public String dropdown() { - StringBuilder buf = new StringBuilder(); - buf.append(forename).append(" "); - buf.append(surname).append(" ("); - buf.append(username).append(", "); - buf.append(duedate == null ? "" : duedate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"))); - buf.append(")"); - return buf.toString(); - } - @Override public String toString() { StringBuilder buf = new StringBuilder(); diff --git a/src/main/java/de/jottyfan/camporganizer/module/camplist/BookingBean.java b/src/main/java/de/jottyfan/camporganizer/module/camplist/BookingBean.java index 9ab7f29..9920048 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/camplist/BookingBean.java +++ b/src/main/java/de/jottyfan/camporganizer/module/camplist/BookingBean.java @@ -74,6 +74,10 @@ public class BookingBean implements Serializable { return EnumCamprole.feeder.equals(camprole); } + public Boolean isObserver() { + return EnumCamprole.observer.equals(camprole); + } + /** * @return the forename */ diff --git a/src/main/java/de/jottyfan/camporganizer/module/confirmation/confirmation/impl/BookingBean.java b/src/main/java/de/jottyfan/camporganizer/module/confirmation/confirmation/impl/BookingBean.java index 01d6895..fce9947 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/confirmation/confirmation/impl/BookingBean.java +++ b/src/main/java/de/jottyfan/camporganizer/module/confirmation/confirmation/impl/BookingBean.java @@ -47,6 +47,8 @@ public class BookingBean implements Serializable, Comparable { return "Leiter"; } else if (EnumCamprole.feeder.getLiteral().equals(role)) { return "Küchenteam"; + } else if (EnumCamprole.observer.getLiteral().equals(role)) { + return "Mitarbeiterkind"; } else { return role; } diff --git a/src/main/resources/templates/admin/camp_edit.html b/src/main/resources/templates/admin/camp_edit.html index 7d89a76..a6b1007 100644 --- a/src/main/resources/templates/admin/camp_edit.html +++ b/src/main/resources/templates/admin/camp_edit.html @@ -62,10 +62,32 @@
-
- [[${error}]]
+
+ [[${error}]]
+
+
@@ -97,7 +119,13 @@
- +
+ +
+ + +
+
diff --git a/src/main/resources/templates/admin/document.html b/src/main/resources/templates/admin/document.html index 233669e..cccf1f4 100644 --- a/src/main/resources/templates/admin/document.html +++ b/src/main/resources/templates/admin/document.html @@ -23,6 +23,7 @@ Mitarbeiter Leiter Küche + Mitarbeiterkind diff --git a/src/main/resources/templates/admin/document_edit.html b/src/main/resources/templates/admin/document_edit.html index b827d33..03d65d8 100644 --- a/src/main/resources/templates/admin/document_edit.html +++ b/src/main/resources/templates/admin/document_edit.html @@ -34,7 +34,8 @@ - + +
diff --git a/src/main/resources/templates/business/booker.html b/src/main/resources/templates/business/booker.html index 7d3afae..5de3451 100644 --- a/src/main/resources/templates/business/booker.html +++ b/src/main/resources/templates/business/booker.html @@ -40,12 +40,16 @@ - Preis + Freizeitpreis Kontostand - + + + + zu zahlen + diff --git a/src/main/resources/templates/confirmation/person.html b/src/main/resources/templates/confirmation/person.html index 06d3996..17cf84e 100644 --- a/src/main/resources/templates/confirmation/person.html +++ b/src/main/resources/templates/confirmation/person.html @@ -91,6 +91,7 @@ + diff --git a/src/main/resources/templates/dashboard.html b/src/main/resources/templates/dashboard.html index 8742e07..c479c87 100644 --- a/src/main/resources/templates/dashboard.html +++ b/src/main/resources/templates/dashboard.html @@ -83,7 +83,7 @@
Rolle:
Mitarbeiter Teilnehmer Leiter Küchenteam + th:if="${b.isFeeder()}">Küchenteam Mitarbeiterkind
diff --git a/src/main/resources/templates/registration/registration.html b/src/main/resources/templates/registration/registration.html index fea5cc2..615c9f9 100644 --- a/src/main/resources/templates/registration/registration.html +++ b/src/main/resources/templates/registration/registration.html @@ -74,6 +74,7 @@ +
diff --git a/src/main/resources/templates/template.html b/src/main/resources/templates/template.html index d7c4dcd..96a0f4b 100644 --- a/src/main/resources/templates/template.html +++ b/src/main/resources/templates/template.html @@ -108,9 +108,9 @@
  • Testmail
  • Dokumente
  • Freizeitheime
  • -
  • Freizeiten - --> +