basic registration feature

This commit is contained in:
Jottyfan
2024-12-01 19:16:05 +01:00
parent bf88306d85
commit 634c0d7b1c
32 changed files with 556 additions and 69 deletions

View File

@ -0,0 +1,74 @@
package de.jottyfan.bico.modules.camp;
import java.security.Principal;
import java.util.ArrayList;
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;
import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.bico.db.camp.enums.EnumSex;
import de.jottyfan.bico.modules.CommonController;
import de.jottyfan.bico.modules.camp.model.RegistrationBean;
import jakarta.validation.Valid;
/**
*
* @author jotty
*
*/
@Controller
public class RegistrationController extends CommonController {
@Autowired
private RegistrationService service;
@GetMapping("/camp/registration")
public String loadForm(Model model, Principal principal) {
model.addAttribute("registrations", service.getRegistrations(principal));
model.addAttribute("bean", new RegistrationBean());
model.addAttribute("sexes", EnumSex.values());
return "/camp/registration";
}
@PostMapping("/camp/registration/submit")
public String submitAddForm(@Valid @ModelAttribute("bean") RegistrationBean bean, BindingResult bindingResult,
Model model, Principal principal) {
if (bindingResult.hasErrors()) {
model.addAttribute("registrations", new ArrayList<RegistrationBean>()); // hack to make "Neue Anmeldung" appear
model.addAttribute("sexes", EnumSex.values());
return "/camp/registration";
}
service.save(bean, principal);
return "redirect:/camp/registration";
}
@GetMapping("/camp/registration/edit/{id}")
public String loadEditForm(@PathVariable("id") Integer id, Model model, Principal principal) {
model.addAttribute("bean", service.getBeanOfPrincipal(id, principal));
model.addAttribute("sexes", EnumSex.values());
return "/camp/edit";
}
@GetMapping("/camp/registration/delete/{id}")
public String delete(@PathVariable("id") Integer id, Model model, Principal principal) {
service.delete(id, principal);
return "redirect:/camp/registration";
}
@PostMapping("/camp/registration/correct")
public String submitEditForm(@Valid @ModelAttribute("bean") RegistrationBean bean, BindingResult bindingResult,
Model model, Principal principal) {
if (bindingResult.hasErrors()) {
model.addAttribute("sexes", EnumSex.values());
return "/camp/registration";
}
service.save(bean, principal);
return "redirect:/camp/registration";
}
}

View File

@ -0,0 +1,120 @@
package de.jottyfan.bico.modules.camp;
import static de.jottyfan.bico.db.camp.Tables.T_REGISTRATION;
import java.util.List;
import org.jooq.DSLContext;
import org.jooq.DeleteConditionStep;
import org.jooq.InsertValuesStep5;
import org.jooq.SelectConditionStep;
import org.jooq.UpdateConditionStep;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.Main;
import de.jottyfan.bico.db.camp.enums.EnumCamp;
import de.jottyfan.bico.db.camp.enums.EnumSex;
import de.jottyfan.bico.db.camp.tables.records.TRegistrationRecord;
import de.jottyfan.bico.modules.camp.model.RegistrationBean;
import jakarta.validation.Valid;
/**
*
* @author jotty
*
*/
@Repository
public class RegistrationRepository {
@Autowired
private DSLContext jooq;
/**
* save the validated bean
*
* @param bean the bean
* @param registrator the principal name
*/
public void save(@Valid RegistrationBean bean, String registrator) {
jooq.transaction(t -> {
if (bean.getPkRegistration() == null) {
InsertValuesStep5<TRegistrationRecord, EnumCamp, String, String, String, EnumSex> sql = DSL.using(t)
// @formatter:off
.insertInto(T_REGISTRATION,
T_REGISTRATION.CAMP,
T_REGISTRATION.REGISTRATOR,
T_REGISTRATION.FORENAME,
T_REGISTRATION.SURNAME,
T_REGISTRATION.SEX)
.values(EnumCamp.Gemeindefreizeit_2025, registrator, bean.getForename(), bean.getSurname(), EnumSex.lookupLiteral(bean.getSex()));
// @formatter:on
Main.LOGGER.trace(sql);
sql.execute();
} else {
UpdateConditionStep<TRegistrationRecord> sql = DSL.using(t)
// @formatter:off
.update(T_REGISTRATION)
.set(T_REGISTRATION.FORENAME, bean.getForename())
.set(T_REGISTRATION.SURNAME, bean.getSurname())
.set(T_REGISTRATION.SEX, EnumSex.lookupLiteral(bean.getSex()))
.set(T_REGISTRATION.REGISTRATOR, registrator)
.where(T_REGISTRATION.PK_REGISTRATION.eq(bean.getPkRegistration()));
// @formatter:on
Main.LOGGER.trace(sql);
sql.execute();
}
});
}
/**
* get all registrations of name
*
* @param name the name
* @return the registrations
*/
public List<RegistrationBean> getRegistrations(String name) {
SelectConditionStep<TRegistrationRecord> sql = jooq
// @formatter:off
.selectFrom(T_REGISTRATION)
.where(T_REGISTRATION.REGISTRATOR.eq(name));
// @formatter:on
Main.LOGGER.trace(sql);
return sql.fetchInto(RegistrationBean.class);
}
/**
* get the registration of id if the creator is the name; null else
*
* @param id the id
* @param name the name
* @return the bean or null
*/
public RegistrationBean getBean(Integer id, String name) {
SelectConditionStep<TRegistrationRecord> sql = jooq
// @formatter:off
.selectFrom(T_REGISTRATION)
.where(T_REGISTRATION.PK_REGISTRATION.eq(id))
.and(T_REGISTRATION.REGISTRATOR.eq(name));
// @formatter:on
Main.LOGGER.trace(sql);
return sql.fetchOneInto(RegistrationBean.class);
}
/**
* delete the registration if the name is the creator
*
* @param id the id
* @param name the name
*/
public void delete(Integer id, String name) {
DeleteConditionStep<TRegistrationRecord> sql = jooq
// @formatter:off
.deleteFrom(T_REGISTRATION)
.where(T_REGISTRATION.PK_REGISTRATION.eq(id))
.and(T_REGISTRATION.REGISTRATOR.eq(name));
// @formatter:on
Main.LOGGER.trace(sql);
sql.execute();
}
}

View File

@ -0,0 +1,62 @@
package de.jottyfan.bico.modules.camp;
import java.security.Principal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.bico.modules.camp.model.RegistrationBean;
import jakarta.validation.Valid;
/**
*
* @author jotty
*
*/
@Service
public class RegistrationService {
@Autowired
private RegistrationRepository repository;
/**
* save the bean content
*
* @param bean the bean
*/
public void save(@Valid RegistrationBean bean, Principal principal) {
repository.save(bean, principal.getName());
}
/**
* get the registrations of principal
*
* @param principal the principal
* @return the registrations
*/
public List<RegistrationBean> getRegistrations(Principal principal) {
return repository.getRegistrations(principal.getName());
}
/**
* get the registration if the principal was the creator
*
* @param id the ID of the registration
* @param principal the principal
* @return the bean or null if not found or allowed
*/
public RegistrationBean getBeanOfPrincipal(Integer id, Principal principal) {
return repository.getBean(id, principal.getName());
}
/**
* delete the registration if the principal was the creator
*
* @param id the ID of the registration
* @param principal the principal
*/
public void delete(Integer id, Principal principal) {
repository.delete(id, principal.getName());
}
}

View File

@ -0,0 +1,78 @@
package de.jottyfan.bico.modules.camp.model;
import java.io.Serializable;
import jakarta.validation.constraints.NotBlank;
/**
*
* @author jotty
*
*/
public class RegistrationBean implements Serializable {
private static final long serialVersionUID = 1L;
private Integer pkRegistration;
@NotBlank
private String forename;
@NotBlank
private String surname;
@NotBlank
private String sex;
/**
* @return the forename
*/
public String getForename() {
return forename;
}
/**
* @param forename the forename to set
*/
public void setForename(String forename) {
this.forename = forename;
}
/**
* @return the surname
*/
public String getSurname() {
return surname;
}
/**
* @param surname the surname to set
*/
public void setSurname(String surname) {
this.surname = surname;
}
/**
* @return the sex
*/
public String getSex() {
return sex;
}
/**
* @param sex the sex to set
*/
public void setSex(String sex) {
this.sex = sex;
}
/**
* @return the pkRegistration
*/
public Integer getPkRegistration() {
return pkRegistration;
}
/**
* @param pkRegistration the pkRegistration to set
*/
public void setPkRegistration(Integer pkRegistration) {
this.pkRegistration = pkRegistration;
}
}

View File

@ -1,6 +1,6 @@
package de.jottyfan.bico.modules.download;
import static de.jottyfan.bico.db.Tables.V_CALENDAR;
import static de.jottyfan.bico.db.public_.Tables.V_CALENDAR;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -9,7 +9,7 @@ import org.jooq.SelectWhereStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.VCalendarRecord;
import de.jottyfan.bico.db.public_.tables.records.VCalendarRecord;
/**
*

View File

@ -20,7 +20,7 @@ public class IcalController extends CommonController{
@GetMapping("/ical")
public void getIcalExport(HttpServletResponse response) throws Exception {
response.setHeader("Content-Disposition", "attachment; filename=bico.ical");
response.setHeader("Content-Disposition", "attachment; filename=bico.ics");
response.setContentType("application/octet-stream");
response.setHeader("Content-Transfer-Encoding", "binary");
response.setHeader("Accept-Ranges", "bytes");

View File

@ -1,6 +1,6 @@
package de.jottyfan.bico.modules.ical;
import static de.jottyfan.bico.db.Tables.V_CALENDAR;
import static de.jottyfan.bico.db.public_.Tables.V_CALENDAR;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -9,7 +9,7 @@ import org.jooq.SelectWhereStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.VCalendarRecord;
import de.jottyfan.bico.db.public_.tables.records.VCalendarRecord;
/**
*

View File

@ -8,7 +8,7 @@ import java.time.LocalTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.bico.db.tables.records.VCalendarRecord;
import de.jottyfan.bico.db.public_.tables.records.VCalendarRecord;
import net.fortuna.ical4j.data.CalendarOutputter;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.component.VEvent;

View File

@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import de.jottyfan.bico.db.tables.records.TLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TLessonRecord;
import de.jottyfan.bico.modules.CommonController;
/**
*

View File

@ -1,8 +1,8 @@
package de.jottyfan.bico.modules.lesson;
import static de.jottyfan.bico.db.Tables.T_LESSON;
import static de.jottyfan.bico.db.Tables.T_PERSON;
import static de.jottyfan.bico.db.Tables.T_SLOT;
import static de.jottyfan.bico.db.public_.Tables.T_LESSON;
import static de.jottyfan.bico.db.public_.Tables.T_PERSON;
import static de.jottyfan.bico.db.public_.Tables.T_SLOT;
import java.time.LocalDate;
import java.util.List;
@ -19,8 +19,8 @@ import org.jooq.UpdateConditionStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.TLessonRecord;
import de.jottyfan.bico.db.tables.records.TPersonRecord;
import de.jottyfan.bico.db.public_.tables.records.TLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TPersonRecord;
/**
*

View File

@ -6,8 +6,8 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.bico.db.tables.records.TLessonRecord;
import de.jottyfan.bico.db.tables.records.TPersonRecord;
import de.jottyfan.bico.db.public_.tables.records.TLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TPersonRecord;
/**
*

View File

@ -1,6 +1,6 @@
package de.jottyfan.bico.modules.next;
import static de.jottyfan.bico.db.Tables.V_CALENDAR;
import static de.jottyfan.bico.db.public_.Tables.V_CALENDAR;
import java.time.LocalDate;
import java.util.ArrayList;
@ -18,9 +18,9 @@ import org.springframework.stereotype.Repository;
import de.jottyfan.bico.modules.next.model.NextBean;
/**
*
*
* @author jotty
*
*
*/
@Repository
public class NextRepository {
@ -31,7 +31,7 @@ public class NextRepository {
/**
* get the next dates from date on
*
*
* @param date the date
* @return the next dates as beans in a list; an empty list at least
*/

View File

@ -1,6 +1,6 @@
package de.jottyfan.bico.modules.profile;
import static de.jottyfan.bico.db.Tables.T_PROFILE;
import static de.jottyfan.bico.db.public_.Tables.T_PROFILE;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -10,7 +10,7 @@ import org.jooq.SelectConditionStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.TProfileRecord;
import de.jottyfan.bico.db.public_.tables.records.TProfileRecord;
import de.jottyfan.bico.modules.profile.model.ProfileBean;
/**

View File

@ -1,6 +1,6 @@
package de.jottyfan.bico.modules.sheet;
import static de.jottyfan.bico.db.Tables.V_CALENDAR;
import static de.jottyfan.bico.db.public_.Tables.V_CALENDAR;
import java.util.List;
@ -11,7 +11,7 @@ import org.jooq.SelectWhereStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.VCalendarRecord;
import de.jottyfan.bico.db.public_.tables.records.VCalendarRecord;
/**
*

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.bico.db.tables.records.VCalendarRecord;
import de.jottyfan.bico.db.public_.tables.records.VCalendarRecord;
/**
*

View File

@ -1,7 +1,7 @@
package de.jottyfan.bico.modules.slot;
import static de.jottyfan.bico.db.Tables.T_LESSON;
import static de.jottyfan.bico.db.Tables.T_SLOT;
import static de.jottyfan.bico.db.public_.Tables.T_LESSON;
import static de.jottyfan.bico.db.public_.Tables.T_SLOT;
import java.util.Iterator;
@ -15,8 +15,8 @@ import org.jooq.UpdateConditionStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.TLessonRecord;
import de.jottyfan.bico.db.tables.records.TSlotRecord;
import de.jottyfan.bico.db.public_.tables.records.TLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TSlotRecord;
import de.jottyfan.bico.modules.slot.model.SlotBean;
/**

View File

@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import de.jottyfan.bico.db.tables.records.TSubjectRecord;
import de.jottyfan.bico.db.public_.tables.records.TSubjectRecord;
import de.jottyfan.bico.modules.CommonController;
/**

View File

@ -1,9 +1,9 @@
package de.jottyfan.bico.modules.subject;
import static de.jottyfan.bico.db.Tables.T_LESSON_SUBJECT;
import static de.jottyfan.bico.db.Tables.T_SOURCE;
import static de.jottyfan.bico.db.Tables.T_SUBJECT;
import static de.jottyfan.bico.db.Tables.V_LESSON;
import static de.jottyfan.bico.db.public_.Tables.T_LESSON_SUBJECT;
import static de.jottyfan.bico.db.public_.Tables.T_SOURCE;
import static de.jottyfan.bico.db.public_.Tables.T_SUBJECT;
import static de.jottyfan.bico.db.public_.Tables.V_LESSON;
import java.util.List;
@ -19,9 +19,9 @@ import org.jooq.UpdateConditionStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.TSourceRecord;
import de.jottyfan.bico.db.tables.records.TSubjectRecord;
import de.jottyfan.bico.db.tables.records.VLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TSourceRecord;
import de.jottyfan.bico.db.public_.tables.records.TSubjectRecord;
import de.jottyfan.bico.db.public_.tables.records.VLessonRecord;
/**
*

View File

@ -5,9 +5,9 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.bico.db.tables.records.TSourceRecord;
import de.jottyfan.bico.db.tables.records.TSubjectRecord;
import de.jottyfan.bico.db.tables.records.VLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TSourceRecord;
import de.jottyfan.bico.db.public_.tables.records.TSubjectRecord;
import de.jottyfan.bico.db.public_.tables.records.VLessonRecord;
/**
*

View File

@ -2,7 +2,7 @@ package de.jottyfan.bico.modules.subject.model;
import java.io.Serializable;
import de.jottyfan.bico.db.tables.records.TSubjectRecord;
import de.jottyfan.bico.db.public_.tables.records.TSubjectRecord;
/**
*

View File

@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import de.jottyfan.bico.db.tables.records.TLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TLessonRecord;
import de.jottyfan.bico.modules.CommonController;
import jakarta.servlet.http.HttpServletRequest;

View File

@ -1,10 +1,10 @@
package de.jottyfan.bico.modules.theme;
import static de.jottyfan.bico.db.Tables.T_LESSON;
import static de.jottyfan.bico.db.Tables.T_LESSON_SUBJECT;
import static de.jottyfan.bico.db.Tables.T_SLOT;
import static de.jottyfan.bico.db.Tables.T_SOURCE;
import static de.jottyfan.bico.db.Tables.T_SUBJECT;
import static de.jottyfan.bico.db.public_.Tables.T_LESSON;
import static de.jottyfan.bico.db.public_.Tables.T_LESSON_SUBJECT;
import static de.jottyfan.bico.db.public_.Tables.T_SLOT;
import static de.jottyfan.bico.db.public_.Tables.T_SOURCE;
import static de.jottyfan.bico.db.public_.Tables.T_SUBJECT;
import java.time.LocalDate;
import java.util.ArrayList;
@ -25,8 +25,8 @@ import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.jottyfan.bico.db.tables.records.TLessonRecord;
import de.jottyfan.bico.db.tables.records.TLessonSubjectRecord;
import de.jottyfan.bico.db.public_.tables.records.TLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TLessonSubjectRecord;
import de.jottyfan.bico.modules.theme.model.KeyValueBean;
import de.jottyfan.bico.modules.theme.model.ThemeBean;

View File

@ -6,7 +6,7 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.jottyfan.bico.db.tables.records.TLessonRecord;
import de.jottyfan.bico.db.public_.tables.records.TLessonRecord;
import de.jottyfan.bico.modules.theme.model.KeyValueBean;
import de.jottyfan.bico.modules.theme.model.ThemeBean;