first steps of items
This commit is contained in:
		| @@ -0,0 +1,27 @@ | ||||
| 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"; | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,93 @@ | ||||
| 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; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										22
									
								
								src/main/java/de/jottyfan/bico/modules/item/ItemService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/main/java/de/jottyfan/bico/modules/item/ItemService.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| 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); | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,73 @@ | ||||
| package de.jottyfan.bico.modules.item.model; | ||||
|  | ||||
| import java.io.Serializable; | ||||
| import java.time.LocalDate; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public class ItemBean 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<>(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the pkSlot | ||||
| 	 */ | ||||
| 	public Integer getPkSlot() { | ||||
| 		return pkSlot; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param pkSlot the pkSlot to set | ||||
| 	 */ | ||||
| 	public void setPkSlot(Integer pkSlot) { | ||||
| 		this.pkSlot = pkSlot; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the slotDay | ||||
| 	 */ | ||||
| 	public LocalDate getSlotDay() { | ||||
| 		return slotDay; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param slotDay the slotDay to set | ||||
| 	 */ | ||||
| 	public void setSlotDay(LocalDate slotDay) { | ||||
| 		this.slotDay = slotDay; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the slotNote | ||||
| 	 */ | ||||
| 	public String getSlotNote() { | ||||
| 		return slotNote; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param slotNote the slotNote to set | ||||
| 	 */ | ||||
| 	public void setSlotNote(String slotNote) { | ||||
| 		this.slotNote = slotNote; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the lessons | ||||
| 	 */ | ||||
| 	public List<LessonBean> getLessons() { | ||||
| 		return lessons; | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,59 @@ | ||||
| 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; | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,9 @@ | ||||
| package de.jottyfan.bico.modules.item.model; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public record PersonBean(Integer pkPerson, String forename, String surname, String abbreviation) { | ||||
| } | ||||
| @@ -0,0 +1,10 @@ | ||||
| package de.jottyfan.bico.modules.item.model; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public record SourceBean(Integer pkSource, String name) { | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,11 @@ | ||||
| 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) { | ||||
|  | ||||
| } | ||||
| @@ -35,6 +35,8 @@ public class SheetRepository { | ||||
| 		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()); | ||||
|   | ||||
| @@ -23,6 +23,8 @@ public class SheetBean implements Serializable { | ||||
| 	private String subjectNotes; | ||||
| 	private String lessonNotes; | ||||
| 	private String slotNotes; | ||||
| 	private Integer pkSlot; | ||||
| 	private Integer pkSubject; | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the slotDay | ||||
| @@ -191,4 +193,32 @@ public class SheetBean implements Serializable { | ||||
| 	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; | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user