prepared editing locations
This commit is contained in:
@@ -116,4 +116,38 @@ public class AdminController extends CommonController {
|
||||
model.addAttribute("locations", service.getLocations());
|
||||
return "/admin/location";
|
||||
}
|
||||
|
||||
@GetMapping("/admin/location/add")
|
||||
public String prepareAddLocation(Model model, HttpServletRequest request) {
|
||||
super.setupSession(model, request);
|
||||
model.addAttribute("bean", new LocationBean());
|
||||
return "/admin/location_edit";
|
||||
}
|
||||
|
||||
@GetMapping("/admin/location/edit/{id}")
|
||||
public String prepareAddLocation(@PathVariable Integer id, Model model, HttpServletRequest request) {
|
||||
super.setupSession(model, request);
|
||||
model.addAttribute("bean", service.getLocation(id));
|
||||
return "/admin/location_edit";
|
||||
}
|
||||
|
||||
@PostMapping("/admin/location/update")
|
||||
public String updateDocument(@Valid @ModelAttribute("bean") LocationBean bean,
|
||||
final BindingResult bindingResult, Model model, HttpServletRequest request) {
|
||||
super.setupSession(model, request);
|
||||
if (bindingResult.hasErrors()) {
|
||||
for (ObjectError error : bindingResult.getAllErrors())
|
||||
LOGGER.error("error {}: {}", error.getCode(), error.getDefaultMessage());
|
||||
return "/admin/location_edit";
|
||||
}
|
||||
service.updateLocation(bean);
|
||||
return "redirect:/admin/location";
|
||||
}
|
||||
|
||||
@GetMapping("/admin/location/delete/{id}")
|
||||
public String deleteLocation(@PathVariable Integer id, Model model, HttpServletRequest request) {
|
||||
super.setupSession(model, request);
|
||||
service.deleteLocation(id);
|
||||
return "redirect:/admin/location";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jooq.Field;
|
||||
import org.jooq.InsertResultStep;
|
||||
import org.jooq.InsertReturningStep;
|
||||
import org.jooq.Record5;
|
||||
import org.jooq.SelectConditionStep;
|
||||
import org.jooq.SelectSeekStep1;
|
||||
import org.jooq.SelectWhereStep;
|
||||
import org.jooq.UpdateConditionStep;
|
||||
@@ -255,7 +256,19 @@ public class AdminRepository {
|
||||
for (TLocationRecord r : sql.fetch()) {
|
||||
list.add(LocationBean.of(r));
|
||||
}
|
||||
return null;
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the location from the database
|
||||
*
|
||||
* @param id the ID
|
||||
* @return the location bean or null
|
||||
*/
|
||||
public LocationBean getLocation(Integer id) {
|
||||
SelectConditionStep<TLocationRecord> sql = jooq.selectFrom(T_LOCATION).where(T_LOCATION.PK.eq(id));
|
||||
LOGGER.debug(sql.toString());
|
||||
return LocationBean.of(sql.fetchOne());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.validation.Valid;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -84,4 +85,22 @@ public class AdminService {
|
||||
public List<LocationBean> getLocations() {
|
||||
return adminRepository.getLocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the location of id
|
||||
*
|
||||
* @param id the id
|
||||
* @return the location or null
|
||||
*/
|
||||
public LocationBean getLocation(Integer id) {
|
||||
return adminRepository.getLocation(id);
|
||||
}
|
||||
|
||||
public void updateLocation(@Valid LocationBean bean) {
|
||||
throw new DataAccessException("not yet implemented");
|
||||
}
|
||||
|
||||
public void deleteLocation(Integer id) {
|
||||
throw new DataAccessException("not yet implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ public class LocationBean implements Serializable {
|
||||
private String url;
|
||||
|
||||
public static LocationBean of(TLocationRecord r) {
|
||||
if (r == null) {
|
||||
return null;
|
||||
}
|
||||
LocationBean bean = new LocationBean();
|
||||
bean.setPk(r.getPk());
|
||||
bean.setName(r.getName());
|
||||
|
||||
Reference in New Issue
Block a user