Jottyfan
2022-11-05 21:50:54 +01:00
parent f8521095f7
commit e223118a75
6 changed files with 282 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package de.jottyfan.camporganizer.module.registration;
import java.io.Serializable;
/**
*
* @author jotty
*
*/
public class CampBean implements Serializable {
private static final long serialVersionUID = 1L;
private Integer pk;
private String name;
private Integer year;
/**
* @return the pk
*/
public Integer getPk() {
return pk;
}
/**
* @param pk the pk to set
*/
public void setPk(Integer pk) {
this.pk = pk;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the year
*/
public Integer getYear() {
return year;
}
/**
* @param year the year to set
*/
public void setYear(Integer year) {
this.year = year;
}
}

View File

@@ -0,0 +1,35 @@
package de.jottyfan.camporganizer.module.registration;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import de.jottyfan.camporganizer.module.common.CommonController;
/**
*
* @author jotty
*
*/
@Controller
public class RegistrationController extends CommonController {
@Autowired
private HttpServletRequest request;
@Autowired
private RegistrationService service;
@GetMapping("/registration/{fkCamp}")
public String index(@PathVariable(name = "fkCamp", required = true) Integer fkCamp, Model model) {
super.setupSession(model, request);
model.addAttribute("camp", service.getCamp(fkCamp));
// TODO: prepare a bean for the form variables; use model.getAttribute("camp").getPk() for the fk_camp
return "/registration";
}
}

View File

@@ -0,0 +1,52 @@
package de.jottyfan.camporganizer.module.registration;
import static de.jottyfan.camporganizer.db.jooq.Tables.T_CAMP;
import java.time.LocalDateTime;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jooq.DSLContext;
import org.jooq.SelectConditionStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import de.jottyfan.camporganizer.db.jooq.tables.records.TCampRecord;
/**
*
* @author jotty
*
*/
@Repository
@Transactional(transactionManager = "transactionManager")
public class RegistrationGateway {
private static final Logger LOGGER = LogManager.getLogger(RegistrationGateway.class);
@Autowired
private DSLContext jooq;
/**
* get the camp
*
* @param pk the ID of the camp
* @return the camp bean or null
*/
public CampBean getCamp(Integer pk) {
SelectConditionStep<TCampRecord> sql = jooq.selectFrom(T_CAMP).where(T_CAMP.PK.eq(pk));
LOGGER.debug(sql.toString());
TCampRecord r = sql.fetchOne();
if (r != null) {
CampBean bean = new CampBean();
bean.setPk(r.getPk());
bean.setName(r.getName());
LocalDateTime arrive = r.getArrive();
bean.setYear(arrive == null ? null : arrive.getYear());
return bean;
} else {
return null;
}
}
}

View File

@@ -0,0 +1,27 @@
package de.jottyfan.camporganizer.module.registration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
* @author jotty
*
*/
@Service
public class RegistrationService {
@Autowired
private RegistrationGateway gateway;
/**
* get the camp
*
* @param fkCamp the ID of the camp
* @return the camp bean or null
*/
public CampBean getCamp(Integer fkCamp) {
return gateway.getCamp(fkCamp);
}
}