From 48525b7e20d090e9f2b79f5f863b400c2b3162be Mon Sep 17 00:00:00 2001 From: Jottyfan Date: Sat, 18 Nov 2023 19:29:35 +0100 Subject: [PATCH] manipulate slots --- .../bico/modules/item/ItemController.java | 27 --- .../bico/modules/item/ItemRepository.java | 93 -------- .../bico/modules/item/ItemService.java | 22 -- .../bico/modules/item/model/LessonBean.java | 59 ----- .../bico/modules/item/model/PersonBean.java | 9 - .../bico/modules/item/model/SourceBean.java | 10 - .../bico/modules/item/model/SubjectBean.java | 11 - .../bico/modules/sheet/SheetRepository.java | 32 +-- .../bico/modules/sheet/SheetService.java | 4 +- .../bico/modules/sheet/model/SheetBean.java | 224 ------------------ .../bico/modules/slot/SlotController.java | 58 +++++ .../bico/modules/slot/SlotRepository.java | 129 ++++++++++ .../bico/modules/slot/SlotService.java | 39 +++ .../model/SlotBean.java} | 45 ++-- src/main/resources/static/css/style.css | 10 + src/main/resources/templates/item.html | 41 ---- src/main/resources/templates/sheet.html | 29 ++- src/main/resources/templates/slot/delete.html | 16 ++ src/main/resources/templates/slot/item.html | 30 +++ src/main/resources/templates/template.html | 1 - 20 files changed, 331 insertions(+), 558 deletions(-) delete mode 100644 src/main/java/de/jottyfan/bico/modules/item/ItemController.java delete mode 100644 src/main/java/de/jottyfan/bico/modules/item/ItemRepository.java delete mode 100644 src/main/java/de/jottyfan/bico/modules/item/ItemService.java delete mode 100644 src/main/java/de/jottyfan/bico/modules/item/model/LessonBean.java delete mode 100644 src/main/java/de/jottyfan/bico/modules/item/model/PersonBean.java delete mode 100644 src/main/java/de/jottyfan/bico/modules/item/model/SourceBean.java delete mode 100644 src/main/java/de/jottyfan/bico/modules/item/model/SubjectBean.java delete mode 100644 src/main/java/de/jottyfan/bico/modules/sheet/model/SheetBean.java create mode 100644 src/main/java/de/jottyfan/bico/modules/slot/SlotController.java create mode 100644 src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java create mode 100644 src/main/java/de/jottyfan/bico/modules/slot/SlotService.java rename src/main/java/de/jottyfan/bico/modules/{item/model/ItemBean.java => slot/model/SlotBean.java} (50%) delete mode 100644 src/main/resources/templates/item.html create mode 100644 src/main/resources/templates/slot/delete.html create mode 100644 src/main/resources/templates/slot/item.html diff --git a/src/main/java/de/jottyfan/bico/modules/item/ItemController.java b/src/main/java/de/jottyfan/bico/modules/item/ItemController.java deleted file mode 100644 index 615b7f3..0000000 --- a/src/main/java/de/jottyfan/bico/modules/item/ItemController.java +++ /dev/null @@ -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"; - } -} diff --git a/src/main/java/de/jottyfan/bico/modules/item/ItemRepository.java b/src/main/java/de/jottyfan/bico/modules/item/ItemRepository.java deleted file mode 100644 index 5e316b5..0000000 --- a/src/main/java/de/jottyfan/bico/modules/item/ItemRepository.java +++ /dev/null @@ -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> 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> i = sql - .fetch().iterator(); - ItemBean bean = new ItemBean(); - while (i.hasNext()) { - Record17 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; - } -} diff --git a/src/main/java/de/jottyfan/bico/modules/item/ItemService.java b/src/main/java/de/jottyfan/bico/modules/item/ItemService.java deleted file mode 100644 index ef65b96..0000000 --- a/src/main/java/de/jottyfan/bico/modules/item/ItemService.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/de/jottyfan/bico/modules/item/model/LessonBean.java b/src/main/java/de/jottyfan/bico/modules/item/model/LessonBean.java deleted file mode 100644 index 16ded8b..0000000 --- a/src/main/java/de/jottyfan/bico/modules/item/model/LessonBean.java +++ /dev/null @@ -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 persons; - private List 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 getPersons() { - return persons; - } - - /** - * @return the subjects - */ - public List getSubjects() { - return subjects; - } -} diff --git a/src/main/java/de/jottyfan/bico/modules/item/model/PersonBean.java b/src/main/java/de/jottyfan/bico/modules/item/model/PersonBean.java deleted file mode 100644 index 114f420..0000000 --- a/src/main/java/de/jottyfan/bico/modules/item/model/PersonBean.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.jottyfan.bico.modules.item.model; - -/** - * - * @author jotty - * - */ -public record PersonBean(Integer pkPerson, String forename, String surname, String abbreviation) { -} diff --git a/src/main/java/de/jottyfan/bico/modules/item/model/SourceBean.java b/src/main/java/de/jottyfan/bico/modules/item/model/SourceBean.java deleted file mode 100644 index 726b27b..0000000 --- a/src/main/java/de/jottyfan/bico/modules/item/model/SourceBean.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.jottyfan.bico.modules.item.model; - -/** - * - * @author jotty - * - */ -public record SourceBean(Integer pkSource, String name) { - -} diff --git a/src/main/java/de/jottyfan/bico/modules/item/model/SubjectBean.java b/src/main/java/de/jottyfan/bico/modules/item/model/SubjectBean.java deleted file mode 100644 index ff3d2de..0000000 --- a/src/main/java/de/jottyfan/bico/modules/item/model/SubjectBean.java +++ /dev/null @@ -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) { - -} diff --git a/src/main/java/de/jottyfan/bico/modules/sheet/SheetRepository.java b/src/main/java/de/jottyfan/bico/modules/sheet/SheetRepository.java index 80aadb9..d46149a 100644 --- a/src/main/java/de/jottyfan/bico/modules/sheet/SheetRepository.java +++ b/src/main/java/de/jottyfan/bico/modules/sheet/SheetRepository.java @@ -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 getList() { - SelectSeekStep1 sql = jooq.selectFrom(V_CALENDAR).orderBy(V_CALENDAR.SLOT_DAY); - LOGGER.trace(sql.toString()); - List 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 getList() { + SelectWhereStep sql = jooq.selectFrom(V_CALENDAR); + LOGGER.trace(sql); + return sql.fetch().stream().toList(); } } diff --git a/src/main/java/de/jottyfan/bico/modules/sheet/SheetService.java b/src/main/java/de/jottyfan/bico/modules/sheet/SheetService.java index 8c7cbe6..be06ed0 100644 --- a/src/main/java/de/jottyfan/bico/modules/sheet/SheetService.java +++ b/src/main/java/de/jottyfan/bico/modules/sheet/SheetService.java @@ -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 getList() { + public List getList() { return repository.getList(); } diff --git a/src/main/java/de/jottyfan/bico/modules/sheet/model/SheetBean.java b/src/main/java/de/jottyfan/bico/modules/sheet/model/SheetBean.java deleted file mode 100644 index 696037d..0000000 --- a/src/main/java/de/jottyfan/bico/modules/sheet/model/SheetBean.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/de/jottyfan/bico/modules/slot/SlotController.java b/src/main/java/de/jottyfan/bico/modules/slot/SlotController.java new file mode 100644 index 0000000..76c95ef --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/slot/SlotController.java @@ -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"; + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java b/src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java new file mode 100644 index 0000000..be6dae6 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/slot/SlotRepository.java @@ -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 sql = jooq + // @formatter:off + .selectFrom(T_SLOT) + .where(T_SLOT.PK_SLOT.eq(id)); + // @formatter:on + LOGGER.trace(sql); + Iterator 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 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 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 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 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; + } + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/slot/SlotService.java b/src/main/java/de/jottyfan/bico/modules/slot/SlotService.java new file mode 100644 index 0000000..8171f53 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/slot/SlotService.java @@ -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); + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/item/model/ItemBean.java b/src/main/java/de/jottyfan/bico/modules/slot/model/SlotBean.java similarity index 50% rename from src/main/java/de/jottyfan/bico/modules/item/model/ItemBean.java rename to src/main/java/de/jottyfan/bico/modules/slot/model/SlotBean.java index 9ec0532..ce9ff27 100644 --- a/src/main/java/de/jottyfan/bico/modules/item/model/ItemBean.java +++ b/src/main/java/de/jottyfan/bico/modules/slot/model/SlotBean.java @@ -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 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 getLessons() { - return lessons; + public void setNote(String note) { + this.note = note; } } diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index eaee66c..3996ef7 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -1,7 +1,9 @@ +/* html { width: 100%; height: 100%; } +*/ body { background-color: #abc; @@ -12,5 +14,13 @@ body { } .borderdist { + border-radius: 4px; + border: 1px solid gray; + padding: 8px; margin: 8px; + background-color: #eee; +} + +[data-bs-theme=dark] .borderdist { + background-color: #333; } \ No newline at end of file diff --git a/src/main/resources/templates/item.html b/src/main/resources/templates/item.html deleted file mode 100644 index 2bfcf61..0000000 --- a/src/main/resources/templates/item.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - -
-
-
-
Tag
-
-
Lehreinheiten
-
-
-
Dozent
-
-
-
-
Themen
-
-
-
Thema
-
-
Unterthema
-
-
Buchseiten
-
-
Arbeitsblätter
-
-
Bibelvers
-
-
Quelle
-
-
-
-
-
-
-
-
-
- - \ No newline at end of file diff --git a/src/main/resources/templates/sheet.html b/src/main/resources/templates/sheet.html index c374e23..c743509 100644 --- a/src/main/resources/templates/sheet.html +++ b/src/main/resources/templates/sheet.html @@ -8,35 +8,44 @@ Tag Kürzel - Quelle Thema - Unterthema - Tag-Anmerkungen + Notiz - - - + + + - - - + + + + + + einen neues Datum anlegen + + - diff --git a/src/main/resources/templates/slot/delete.html b/src/main/resources/templates/slot/delete.html new file mode 100644 index 0000000..f841753 --- /dev/null +++ b/src/main/resources/templates/slot/delete.html @@ -0,0 +1,16 @@ + + + + +
+
+ Wollen Sie den Slot wirklich löschen?
+ Ja, definitiv +
+
+ Leider wurde das Datum bereits für einen Termin gebucht. Daher kann der Slot nicht gelöscht werden. +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/slot/item.html b/src/main/resources/templates/slot/item.html new file mode 100644 index 0000000..487810a --- /dev/null +++ b/src/main/resources/templates/slot/item.html @@ -0,0 +1,30 @@ + + + + +
+
+
+ +
+
Tag
+
+ +
+
+
Notiz
+
+ +
+
+
+ + Löschen +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/template.html b/src/main/resources/templates/template.html index 1cff495..34aa871 100644 --- a/src/main/resources/templates/template.html +++ b/src/main/resources/templates/template.html @@ -23,7 +23,6 @@