manipulate slots
This commit is contained in:
		| @@ -1,27 +0,0 @@ | ||||
| package de.jottyfan.bico.modules.item; | ||||
|  | ||||
| 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.bico.modules.CommonController; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| @Controller | ||||
| public class ItemController  extends CommonController { | ||||
|  | ||||
| 	@Autowired | ||||
| 	private ItemService service; | ||||
|  | ||||
| 	@GetMapping("/item/{slot}") | ||||
| 	public String getItem(@PathVariable Integer slot, Model model) { | ||||
| 		model.addAttribute("bean", service.getItem(slot)); | ||||
| 		return "/item"; | ||||
| 	} | ||||
| } | ||||
| @@ -1,93 +0,0 @@ | ||||
| package de.jottyfan.bico.modules.item; | ||||
|  | ||||
| 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_PERSON; | ||||
| 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 java.time.LocalDate; | ||||
| import java.util.Iterator; | ||||
|  | ||||
| import org.apache.logging.log4j.LogManager; | ||||
| import org.apache.logging.log4j.Logger; | ||||
| import org.jooq.DSLContext; | ||||
| import org.jooq.Record17; | ||||
| import org.jooq.SelectConditionStep; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Repository; | ||||
|  | ||||
| import de.jottyfan.bico.modules.item.model.ItemBean; | ||||
| import de.jottyfan.bico.modules.item.model.LessonBean; | ||||
| import de.jottyfan.bico.modules.item.model.PersonBean; | ||||
| import de.jottyfan.bico.modules.item.model.SourceBean; | ||||
| import de.jottyfan.bico.modules.item.model.SubjectBean; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| @Repository | ||||
| public class ItemRepository { | ||||
| 	private static final Logger LOGGER = LogManager.getLogger(ItemRepository.class); | ||||
|  | ||||
| 	@Autowired | ||||
| 	private DSLContext jooq; | ||||
|  | ||||
| 	/** | ||||
| 	 * get the item of slot | ||||
| 	 * | ||||
| 	 * @param slot the ID of the slot | ||||
| 	 * @return the bean | ||||
| 	 */ | ||||
| 	public ItemBean getItem(Integer slot) { | ||||
| 		SelectConditionStep<Record17<Integer, LocalDate, String, String, Integer, String, String, String, Integer, String, Integer, String, String, String, String, String, String>> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.select(T_SLOT.PK_SLOT, | ||||
| 					    T_SLOT.SLOT_DAY, | ||||
| 					    T_SLOT.NOTE, | ||||
| 					    T_LESSON.NOTES, | ||||
| 					    T_PERSON.PK_PERSON, | ||||
| 					    T_PERSON.FORENAME, | ||||
| 					    T_PERSON.SURNAME, | ||||
| 					    T_PERSON.ABBREVIATION, | ||||
| 					    T_SOURCE.PK_SOURCE, | ||||
| 					    T_SOURCE.NAME, | ||||
| 					    T_SUBJECT.PK_SUBJECT, | ||||
| 					    T_SUBJECT.THEME, | ||||
| 					    T_SUBJECT.SUBTHEME, | ||||
| 					    T_SUBJECT.WORKSHEETS, | ||||
| 					    T_SUBJECT.BIBLEVERSE, | ||||
| 					    T_SUBJECT.BOOK_PAGES, | ||||
| 					    T_SOURCE.NAME) | ||||
| 			.from(T_SLOT) | ||||
| 			.leftJoin(T_LESSON).on(T_LESSON.FK_SLOT.eq(T_SLOT.PK_SLOT)) | ||||
| 			.leftJoin(T_PERSON).on(T_PERSON.PK_PERSON.eq(T_LESSON.FK_PERSON)) | ||||
| 			.leftJoin(T_LESSON_SUBJECT).on(T_LESSON_SUBJECT.FK_LESSON.eq(T_LESSON.PK_LESSON)) | ||||
| 			.leftJoin(T_SUBJECT).on(T_SUBJECT.PK_SUBJECT.eq(T_LESSON_SUBJECT.FK_SUBJECT)) | ||||
| 			.leftJoin(T_SOURCE).on(T_SOURCE.PK_SOURCE.eq(T_SUBJECT.FK_SOURCE)) | ||||
| 			.where(T_SLOT.PK_SLOT.eq(slot)); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		Iterator<Record17<Integer, LocalDate, String, String, Integer, String, String, String, Integer, String, Integer, String, String, String, String, String, String>> i = sql | ||||
| 				.fetch().iterator(); | ||||
| 		ItemBean bean = new ItemBean(); | ||||
| 		while (i.hasNext()) { | ||||
| 			Record17<Integer, LocalDate, String, String, Integer, String, String, String, Integer, String, Integer, String, String, String, String, String, String> r = i | ||||
| 					.next(); | ||||
| 			bean.setPkSlot(r.get(T_SLOT.PK_SLOT)); | ||||
| 			bean.setSlotDay(r.get(T_SLOT.SLOT_DAY)); | ||||
| 			bean.setSlotNote(r.get(T_SLOT.NOTE)); | ||||
| 			bean.getLessons() | ||||
| 					.add(LessonBean.of( | ||||
| 							r.get(T_LESSON.NOTES), new PersonBean(r.get(T_PERSON.PK_PERSON), r.get(T_PERSON.FORENAME), | ||||
| 									r.get(T_PERSON.SURNAME), r.get(T_PERSON.ABBREVIATION)), | ||||
| 							new SubjectBean(new SourceBean(r.get(T_SOURCE.PK_SOURCE), r.get(T_SOURCE.NAME)), r.get(T_SUBJECT.PK_SUBJECT), r.get(T_SUBJECT.THEME), | ||||
| 									r.get(T_SUBJECT.SUBTHEME), r.get(T_SUBJECT.WORKSHEETS), r.get(T_SUBJECT.BIBLEVERSE), | ||||
| 									r.get(T_SUBJECT.BOOK_PAGES)))); | ||||
| 		} | ||||
| 		return bean; | ||||
| 	} | ||||
| } | ||||
| @@ -1,22 +0,0 @@ | ||||
| package de.jottyfan.bico.modules.item; | ||||
|  | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import de.jottyfan.bico.modules.item.model.ItemBean; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| @Service | ||||
| public class ItemService { | ||||
|  | ||||
| 	@Autowired | ||||
| 	private ItemRepository repository; | ||||
|  | ||||
| 	public ItemBean getItem(Integer slot) { | ||||
| 		return repository.getItem(slot); | ||||
| 	} | ||||
| } | ||||
| @@ -1,59 +0,0 @@ | ||||
| package de.jottyfan.bico.modules.item.model; | ||||
|  | ||||
| import java.io.Serializable; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public class LessonBean implements Serializable { | ||||
|  | ||||
| 	private static final long serialVersionUID = 1L; | ||||
|  | ||||
| 	private String lessonNote; | ||||
| 	private List<PersonBean> persons; | ||||
| 	private List<SubjectBean> subjects; | ||||
|  | ||||
| 	public LessonBean() { | ||||
| 		persons = new ArrayList<>(); | ||||
| 		subjects = new ArrayList<>(); | ||||
| 	} | ||||
|  | ||||
| 	public static final LessonBean of(String lessonNote, PersonBean persons, SubjectBean subject) { | ||||
| 		LessonBean bean = new LessonBean(); | ||||
| 		bean.getPersons().add(persons); | ||||
| 		bean.getSubjects().add(subject); | ||||
| 		return bean; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the lessonNote | ||||
| 	 */ | ||||
| 	public String getLessonNote() { | ||||
| 		return lessonNote; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param lessonNote the lessonNote to set | ||||
| 	 */ | ||||
| 	public void setLessonNote(String lessonNote) { | ||||
| 		this.lessonNote = lessonNote; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the persons | ||||
| 	 */ | ||||
| 	public List<PersonBean> getPersons() { | ||||
| 		return persons; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the subjects | ||||
| 	 */ | ||||
| 	public List<SubjectBean> getSubjects() { | ||||
| 		return subjects; | ||||
| 	} | ||||
| } | ||||
| @@ -1,9 +0,0 @@ | ||||
| package de.jottyfan.bico.modules.item.model; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public record PersonBean(Integer pkPerson, String forename, String surname, String abbreviation) { | ||||
| } | ||||
| @@ -1,10 +0,0 @@ | ||||
| package de.jottyfan.bico.modules.item.model; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public record SourceBean(Integer pkSource, String name) { | ||||
|  | ||||
| } | ||||
| @@ -1,11 +0,0 @@ | ||||
| package de.jottyfan.bico.modules.item.model; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public record SubjectBean(SourceBean source, Integer pkSubject, String theme, String subtheme, String worksheets, | ||||
| 		String bibleverse, String bookPages) { | ||||
|  | ||||
| } | ||||
| @@ -2,19 +2,16 @@ package de.jottyfan.bico.modules.sheet; | ||||
|  | ||||
| import static de.jottyfan.bico.db.Tables.V_CALENDAR; | ||||
|  | ||||
| import java.time.LocalDate; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| import org.apache.logging.log4j.LogManager; | ||||
| import org.apache.logging.log4j.Logger; | ||||
| import org.jooq.DSLContext; | ||||
| import org.jooq.SelectSeekStep1; | ||||
| 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.modules.sheet.model.SheetBean; | ||||
|  | ||||
| /** | ||||
|  * | ||||
| @@ -29,28 +26,9 @@ public class SheetRepository { | ||||
| 	@Autowired | ||||
| 	private DSLContext jooq; | ||||
|  | ||||
| 	public List<SheetBean> getList() { | ||||
| 		SelectSeekStep1<VCalendarRecord, LocalDate> sql = jooq.selectFrom(V_CALENDAR).orderBy(V_CALENDAR.SLOT_DAY); | ||||
| 		LOGGER.trace(sql.toString()); | ||||
| 		List<SheetBean> list = new ArrayList<>(); | ||||
| 		for (VCalendarRecord r : sql.fetch()) { | ||||
| 			SheetBean bean = new SheetBean(); | ||||
| 			bean.setPkSlot(r.getPkSlot()); | ||||
| 			bean.setPkSubject(r.getPkSubject()); | ||||
| 			bean.setAbbreviation(r.getAbbreviation()); | ||||
| 			bean.setBibleverse(r.getBibleverse()); | ||||
| 			bean.setBookPages(r.getBookPages()); | ||||
| 			bean.setFullname(r.getFullname()); | ||||
| 			bean.setLessonNotes(r.getLessonNotes()); | ||||
| 			bean.setSlotDay(r.getSlotDay()); | ||||
| 			bean.setSlotNotes(r.getSlotNotes()); | ||||
| 			bean.setSourceName(r.getSourceName()); | ||||
| 			bean.setSubjectNotes(r.getSubjectNotes()); | ||||
| 			bean.setSubtheme(r.getSubtheme()); | ||||
| 			bean.setTheme(r.getTheme()); | ||||
| 			bean.setWorksheets(r.getWorksheets()); | ||||
| 			list.add(bean); | ||||
| 		} | ||||
| 		return list; | ||||
| 	public List<VCalendarRecord> getList() { | ||||
| 		 SelectWhereStep<VCalendarRecord> sql = jooq.selectFrom(V_CALENDAR); | ||||
| 		LOGGER.trace(sql); | ||||
| 		return sql.fetch().stream().toList(); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import java.util.List; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import de.jottyfan.bico.modules.sheet.model.SheetBean; | ||||
| import de.jottyfan.bico.db.tables.records.VCalendarRecord; | ||||
|  | ||||
| /** | ||||
|  * | ||||
| @@ -18,7 +18,7 @@ public class SheetService { | ||||
| 	@Autowired | ||||
| 	private SheetRepository repository; | ||||
|  | ||||
| 	public List<SheetBean> getList() { | ||||
| 	public List<VCalendarRecord> getList() { | ||||
| 		return repository.getList(); | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -1,224 +0,0 @@ | ||||
| package de.jottyfan.bico.modules.sheet.model; | ||||
|  | ||||
| import java.io.Serializable; | ||||
| import java.time.LocalDate; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public class SheetBean implements Serializable { | ||||
| 	private static final long serialVersionUID = 1L; | ||||
|  | ||||
| 	private LocalDate slotDay; | ||||
| 	private String fullname; | ||||
| 	private String abbreviation; | ||||
| 	private String sourceName; | ||||
| 	private String theme; | ||||
| 	private String subtheme; | ||||
| 	private String bookPages; | ||||
| 	private String worksheets; | ||||
| 	private String bibleverse; | ||||
| 	private String subjectNotes; | ||||
| 	private String lessonNotes; | ||||
| 	private String slotNotes; | ||||
| 	private Integer pkSlot; | ||||
| 	private Integer pkSubject; | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the slotDay | ||||
| 	 */ | ||||
| 	public LocalDate getSlotDay() { | ||||
| 		return slotDay; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param slotDay the slotDay to set | ||||
| 	 */ | ||||
| 	public void setSlotDay(LocalDate slotDay) { | ||||
| 		this.slotDay = slotDay; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the fullname | ||||
| 	 */ | ||||
| 	public String getFullname() { | ||||
| 		return fullname; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param fullname the fullname to set | ||||
| 	 */ | ||||
| 	public void setFullname(String fullname) { | ||||
| 		this.fullname = fullname; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the abbreviation | ||||
| 	 */ | ||||
| 	public String getAbbreviation() { | ||||
| 		return abbreviation; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param abbreviation the abbreviation to set | ||||
| 	 */ | ||||
| 	public void setAbbreviation(String abbreviation) { | ||||
| 		this.abbreviation = abbreviation; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the sourceName | ||||
| 	 */ | ||||
| 	public String getSourceName() { | ||||
| 		return sourceName; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param sourceName the sourceName to set | ||||
| 	 */ | ||||
| 	public void setSourceName(String sourceName) { | ||||
| 		this.sourceName = sourceName; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the theme | ||||
| 	 */ | ||||
| 	public String getTheme() { | ||||
| 		return theme; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param theme the theme to set | ||||
| 	 */ | ||||
| 	public void setTheme(String theme) { | ||||
| 		this.theme = theme; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the subtheme | ||||
| 	 */ | ||||
| 	public String getSubtheme() { | ||||
| 		return subtheme; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param subtheme the subtheme to set | ||||
| 	 */ | ||||
| 	public void setSubtheme(String subtheme) { | ||||
| 		this.subtheme = subtheme; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the bookPages | ||||
| 	 */ | ||||
| 	public String getBookPages() { | ||||
| 		return bookPages; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param bookPages the bookPages to set | ||||
| 	 */ | ||||
| 	public void setBookPages(String bookPages) { | ||||
| 		this.bookPages = bookPages; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the worksheets | ||||
| 	 */ | ||||
| 	public String getWorksheets() { | ||||
| 		return worksheets; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param worksheets the worksheets to set | ||||
| 	 */ | ||||
| 	public void setWorksheets(String worksheets) { | ||||
| 		this.worksheets = worksheets; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the bibleverse | ||||
| 	 */ | ||||
| 	public String getBibleverse() { | ||||
| 		return bibleverse; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param bibleverse the bibleverse to set | ||||
| 	 */ | ||||
| 	public void setBibleverse(String bibleverse) { | ||||
| 		this.bibleverse = bibleverse; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the subjectNotes | ||||
| 	 */ | ||||
| 	public String getSubjectNotes() { | ||||
| 		return subjectNotes; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param subjectNotes the subjectNotes to set | ||||
| 	 */ | ||||
| 	public void setSubjectNotes(String subjectNotes) { | ||||
| 		this.subjectNotes = subjectNotes; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the lessonNotes | ||||
| 	 */ | ||||
| 	public String getLessonNotes() { | ||||
| 		return lessonNotes; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param lessonNotes the lessonNotes to set | ||||
| 	 */ | ||||
| 	public void setLessonNotes(String lessonNotes) { | ||||
| 		this.lessonNotes = lessonNotes; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the slotNotes | ||||
| 	 */ | ||||
| 	public String getSlotNotes() { | ||||
| 		return slotNotes; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param slotNotes the slotNotes to set | ||||
| 	 */ | ||||
| 	public void setSlotNotes(String slotNotes) { | ||||
| 		this.slotNotes = slotNotes; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the pkSlot | ||||
| 	 */ | ||||
| 	public Integer getPkSlot() { | ||||
| 		return pkSlot; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param pkSlot the pkSlot to set | ||||
| 	 */ | ||||
| 	public void setPkSlot(Integer pkSlot) { | ||||
| 		this.pkSlot = pkSlot; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the pkSubject | ||||
| 	 */ | ||||
| 	public Integer getPkSubject() { | ||||
| 		return pkSubject; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param pkSubject the pkSubject to set | ||||
| 	 */ | ||||
| 	public void setPkSubject(Integer pkSubject) { | ||||
| 		this.pkSubject = pkSubject; | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,58 @@ | ||||
| package de.jottyfan.bico.modules.slot; | ||||
|  | ||||
| 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.modules.CommonController; | ||||
| import de.jottyfan.bico.modules.slot.model.SlotBean; | ||||
| import jakarta.validation.Valid; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| @Controller | ||||
| public class SlotController extends CommonController { | ||||
|  | ||||
| 	@Autowired | ||||
| 	private SlotService service; | ||||
|  | ||||
| 	@GetMapping("/slot") | ||||
| 	public String generate(Model model) { | ||||
| 		return load(null, model); | ||||
| 	} | ||||
|  | ||||
| 	@GetMapping("/slot/{id}") | ||||
| 	public String load(@PathVariable Integer id, Model model) { | ||||
| 		model.addAttribute("bean", id == null ? new SlotBean() : service.loadSlot(id)); | ||||
| 		return "/slot/item"; | ||||
| 	} | ||||
|  | ||||
| 	@GetMapping("/slot/{id}/delete") | ||||
| 	public String loadEnsurance(@PathVariable Integer id, Model model) { | ||||
| 		model.addAttribute("bean", service.loadDeletableSlot(id)); | ||||
| 		return "/slot/delete"; | ||||
| 	} | ||||
|  | ||||
| 	@GetMapping("/slot/{id}/destroy") | ||||
| 	public String destroy(@PathVariable Integer id, Model model) { | ||||
| 		service.removeSlot(id); | ||||
| 		return "redirect:/"; | ||||
| 	} | ||||
|  | ||||
| 	@PostMapping("/slot/save") | ||||
| 	public String save(@Valid @ModelAttribute("bean") SlotBean bean, BindingResult bindingResult, Model model) { | ||||
| 		if (bindingResult.hasErrors()) { | ||||
| 			return "/slot/item"; | ||||
| 		} | ||||
| 		service.saveSlot(bean); | ||||
| 		return "redirect:/sheet"; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										129
									
								
								src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,129 @@ | ||||
| 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 java.util.Iterator; | ||||
|  | ||||
| import org.apache.logging.log4j.LogManager; | ||||
| import org.apache.logging.log4j.Logger; | ||||
| import org.jooq.DSLContext; | ||||
| import org.jooq.DeleteConditionStep; | ||||
| import org.jooq.InsertResultStep; | ||||
| import org.jooq.SelectConditionStep; | ||||
| 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.modules.slot.model.SlotBean; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| @Repository | ||||
| public class SlotRepository { | ||||
| 	private static final Logger LOGGER = LogManager.getLogger(SlotRepository.class); | ||||
|  | ||||
| 	@Autowired | ||||
| 	private DSLContext jooq; | ||||
|  | ||||
| 	/** | ||||
| 	 * get the slot referenced by id | ||||
| 	 * | ||||
| 	 * @param id the pkSlot value | ||||
| 	 * @return the slot or null | ||||
| 	 */ | ||||
| 	public SlotBean getSlot(Integer id) { | ||||
| 		SelectConditionStep<TSlotRecord> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.selectFrom(T_SLOT) | ||||
| 			.where(T_SLOT.PK_SLOT.eq(id)); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		Iterator<TSlotRecord> i = sql.fetch().iterator(); | ||||
| 		SlotBean bean = null; | ||||
| 		while (i.hasNext()) { | ||||
| 			TSlotRecord r = i.next(); | ||||
| 			bean = new SlotBean(); | ||||
| 			bean.setPkSlot(r.getPkSlot()); | ||||
| 			bean.setSlotDay(r.getSlotDay()); | ||||
| 			bean.setNote(r.getNote()); | ||||
| 		} | ||||
| 		return bean; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * add a slot and return is new ID | ||||
| 	 * | ||||
| 	 * @param slot the slot | ||||
| 	 * @return the ID of the slot | ||||
| 	 */ | ||||
| 	public Integer addSlot(SlotBean slot) { | ||||
| 		InsertResultStep<TSlotRecord> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.insertInto(T_SLOT, | ||||
| 					        T_SLOT.SLOT_DAY, | ||||
| 					        T_SLOT.NOTE) | ||||
| 			.values(slot.getSlotDay(), slot.getNote()) | ||||
| 			.returning(T_SLOT.PK_SLOT); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		return sql.fetchOne().getPkSlot(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * update the slot | ||||
| 	 * | ||||
| 	 * @param slot the slot | ||||
| 	 */ | ||||
| 	public void changeSlot(SlotBean slot) { | ||||
| 		UpdateConditionStep<TSlotRecord> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.update(T_SLOT) | ||||
| 			.set(T_SLOT.SLOT_DAY, slot.getSlotDay()) | ||||
| 			.set(T_SLOT.NOTE, slot.getNote()) | ||||
| 			.where(T_SLOT.PK_SLOT.eq(slot.getPkSlot())); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		sql.execute(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * remove slot | ||||
| 	 * | ||||
| 	 * @param id the ID of the slot | ||||
| 	 */ | ||||
| 	public void deleteSlot(Integer id) { | ||||
| 		DeleteConditionStep<TSlotRecord> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.deleteFrom(T_SLOT) | ||||
| 			.where(T_SLOT.PK_SLOT.eq(id)); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		sql.execute(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * get the slot only if it is not yet used by another table | ||||
| 	 * | ||||
| 	 * @param id the ID of the slot | ||||
| 	 * @return the slot or null | ||||
| 	 */ | ||||
| 	public SlotBean getSlotIfDeletable(Integer id) { | ||||
| 		SelectConditionStep<TLessonRecord> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.selectFrom(T_LESSON) | ||||
| 			.where(T_LESSON.FK_SLOT.eq(id)); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		if (sql.fetchOne() == null) { | ||||
| 			return getSlot(id); | ||||
| 		} else { | ||||
| 			return null; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										39
									
								
								src/main/java/de/jottyfan/bico/modules/slot/SlotService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/main/java/de/jottyfan/bico/modules/slot/SlotService.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| package de.jottyfan.bico.modules.slot; | ||||
|  | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import de.jottyfan.bico.modules.slot.model.SlotBean; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| @Service | ||||
| public class SlotService { | ||||
|  | ||||
| 	@Autowired | ||||
| 	private SlotRepository repository; | ||||
|  | ||||
| 	public SlotBean loadSlot(Integer id) { | ||||
| 		return repository.getSlot(id); | ||||
| 	} | ||||
|  | ||||
| 	public Integer saveSlot(SlotBean slot) { | ||||
| 		if (slot.getPkSlot() == null) { | ||||
| 			return repository.addSlot(slot); | ||||
| 		} else { | ||||
| 			repository.changeSlot(slot); | ||||
| 			return slot.getPkSlot(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	public void removeSlot(Integer id) { | ||||
| 		repository.deleteSlot(id); | ||||
| 	} | ||||
|  | ||||
| 	public SlotBean loadDeletableSlot(Integer id) { | ||||
| 		return repository.getSlotIfDeletable(id); | ||||
| 	} | ||||
| } | ||||
| @@ -1,25 +1,33 @@ | ||||
| package de.jottyfan.bico.modules.item.model; | ||||
| package de.jottyfan.bico.modules.slot.model; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| import java.time.LocalDate; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.springframework.format.annotation.DateTimeFormat; | ||||
| 
 | ||||
| import jakarta.validation.constraints.NotNull; | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public class ItemBean implements Serializable { | ||||
| // TODO: not exists validator that checks for another pkSlot not to have that slotDay | ||||
| public class SlotBean implements Serializable { | ||||
| 
 | ||||
| 	private static final long serialVersionUID = 1L; | ||||
| 
 | ||||
| 	private Integer pkSlot; | ||||
| 	private LocalDate slotDay; | ||||
| 	private String slotNote; | ||||
| 	private List<LessonBean> lessons; | ||||
| 
 | ||||
| 	public ItemBean() { | ||||
| 		lessons = new ArrayList<>(); | ||||
| 	@DateTimeFormat(pattern = "yyyy-MM-dd") | ||||
| 	@NotNull(message = "Das Datum muss ausgefüllt werden.") | ||||
| 	private LocalDate slotDay; | ||||
| 
 | ||||
| 	private String note; | ||||
| 
 | ||||
| 	public SlotBean withNote(String note) { | ||||
| 		this.note = note; | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| @@ -51,23 +59,16 @@ public class ItemBean implements Serializable { | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @return the slotNote | ||||
| 	 * @return the note | ||||
| 	 */ | ||||
| 	public String getSlotNote() { | ||||
| 		return slotNote; | ||||
| 	public String getNote() { | ||||
| 		return note; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param slotNote the slotNote to set | ||||
| 	 * @param note the note to set | ||||
| 	 */ | ||||
| 	public void setSlotNote(String slotNote) { | ||||
| 		this.slotNote = slotNote; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @return the lessons | ||||
| 	 */ | ||||
| 	public List<LessonBean> getLessons() { | ||||
| 		return lessons; | ||||
| 	public void setNote(String note) { | ||||
| 		this.note = note; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user