add, edit, delete and assign themes to dates
This commit is contained in:
		| @@ -1,8 +1,14 @@ | ||||
| package de.jottyfan.bico.modules.subject; | ||||
|  | ||||
| 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.ModelAttribute; | ||||
| import org.springframework.web.bind.annotation.PathVariable; | ||||
| import org.springframework.web.bind.annotation.PostMapping; | ||||
|  | ||||
| import de.jottyfan.bico.db.tables.records.TSubjectRecord; | ||||
| import de.jottyfan.bico.modules.CommonController; | ||||
|  | ||||
| /** | ||||
| @@ -13,8 +19,44 @@ import de.jottyfan.bico.modules.CommonController; | ||||
| @Controller | ||||
| public class SubjectController extends CommonController { | ||||
|  | ||||
| 	@Autowired | ||||
| 	private SubjectService service; | ||||
|  | ||||
| 	@GetMapping("/subject/list") | ||||
| 	public String getSubjectList(Model model) { | ||||
| 		model.addAttribute("list", service.getSubjects()); | ||||
| 		return "/subject/list"; | ||||
| 	} | ||||
|  | ||||
| 	@GetMapping("/subject/{id}") | ||||
| 	public String getSubject(@PathVariable("id") Integer pkSubject, Model model) { | ||||
| 		model.addAttribute("bean", service.getSubject(pkSubject)); | ||||
| 		model.addAttribute("sources", service.getSources()); | ||||
| 		return "/subject/item"; | ||||
| 	} | ||||
|  | ||||
| 	@PostMapping("/subject/save") | ||||
| 	public String saveSubject(@ModelAttribute("bean") TSubjectRecord bean) { | ||||
| 		service.save(bean); | ||||
| 		return "redirect:/subject/list"; | ||||
| 	} | ||||
|  | ||||
| 	@GetMapping("/subject/{id}/delete") | ||||
| 	public String checkDeletionOfSubject(@PathVariable("id") Integer pkSubject, Model model) { | ||||
| 		model.addAttribute("bean", service.getBeanIfDeletable(pkSubject)); | ||||
| 		return "/subject/delete"; | ||||
| 	} | ||||
|  | ||||
| 	@GetMapping("/subject/{id}/remove") | ||||
| 	public String removeSubject(@PathVariable("id") Integer pkSubject, Model model) { | ||||
| 		service.removeSubject(pkSubject); | ||||
| 		return "redirect:/subject/list"; | ||||
| 	} | ||||
|  | ||||
| 	@GetMapping("/subject/new") | ||||
| 	public String loadNewSubjectForm() { | ||||
| 		return "/subject/new"; | ||||
| 	public String loadNewSubjectForm(Model model) { | ||||
| 		model.addAttribute("bean", new TSubjectRecord()); | ||||
| 		model.addAttribute("sources", service.getSources()); | ||||
| 		return "/subject/item"; | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,115 @@ | ||||
| package de.jottyfan.bico.modules.subject; | ||||
|  | ||||
| import static de.jottyfan.bico.db.Tables.T_LESSON_SUBJECT; | ||||
| import static de.jottyfan.bico.db.Tables.T_SOURCE; | ||||
| import static de.jottyfan.bico.db.Tables.T_SUBJECT; | ||||
| import static de.jottyfan.bico.db.Tables.V_LESSON; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import org.apache.logging.log4j.LogManager; | ||||
| import org.apache.logging.log4j.Logger; | ||||
| import org.jooq.DSLContext; | ||||
| import org.jooq.DeleteConditionStep; | ||||
| import org.jooq.InsertValuesStep8; | ||||
| import org.jooq.SelectConditionStep; | ||||
| import org.jooq.SelectOrderByStep; | ||||
| import org.jooq.SelectWhereStep; | ||||
| import org.jooq.UpdateConditionStep; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Repository; | ||||
|  | ||||
| import de.jottyfan.bico.db.tables.records.TSourceRecord; | ||||
| import de.jottyfan.bico.db.tables.records.TSubjectRecord; | ||||
| import de.jottyfan.bico.db.tables.records.VLessonRecord; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| @Repository | ||||
| public class SubjectRepository { | ||||
| 	private static final Logger LOGGER = LogManager.getLogger(SubjectRepository.class); | ||||
|  | ||||
| 	@Autowired | ||||
| 	private DSLContext jooq; | ||||
|  | ||||
| 	public List<VLessonRecord> getSubjects() { | ||||
| 		SelectWhereStep<VLessonRecord> sql = jooq.selectFrom(V_LESSON); | ||||
| 		LOGGER.trace(sql); | ||||
| 		return sql.fetch().stream().toList(); | ||||
| 	} | ||||
|  | ||||
| 	public List<TSourceRecord> getSources() { | ||||
| 		SelectWhereStep<TSourceRecord> sql = jooq.selectFrom(T_SOURCE); | ||||
| 		LOGGER.trace(sql); | ||||
| 		return sql.fetch().stream().toList(); | ||||
| 	} | ||||
|  | ||||
| 	public TSubjectRecord getSubject(Integer pkSubject) { | ||||
| 		SelectConditionStep<TSubjectRecord> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.selectFrom(T_SUBJECT) | ||||
| 			.where(T_SUBJECT.PK_SUBJECT.eq(pkSubject)); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		return sql.fetchOne(); | ||||
| 	} | ||||
|  | ||||
| 	public void addSubject(TSubjectRecord bean) { | ||||
| 		InsertValuesStep8<TSubjectRecord, Integer, String, String, String, String, String, String, Integer> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.insertInto(T_SUBJECT, | ||||
| 									T_SUBJECT.FK_SOURCE, | ||||
| 									T_SUBJECT.THEME, | ||||
| 									T_SUBJECT.SUBTHEME, | ||||
| 									T_SUBJECT.BOOK_PAGES, | ||||
| 									T_SUBJECT.WORKSHEETS, | ||||
| 									T_SUBJECT.BIBLEVERSE, | ||||
| 									T_SUBJECT.NOTES, | ||||
| 									T_SUBJECT.ORDER_NR) | ||||
| 			.values(bean.getFkSource(), bean.getTheme(), bean.getSubtheme(), bean.getBookPages(), bean.getWorksheets(), | ||||
| 					    bean.getBibleverse(), bean.getNotes(), bean.getOrderNr()); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		sql.execute(); | ||||
| 	} | ||||
|  | ||||
| 	public void updateSubject(TSubjectRecord bean) { | ||||
| 		UpdateConditionStep<TSubjectRecord> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.update(T_SUBJECT) | ||||
| 			.set(T_SUBJECT.FK_SOURCE, bean.getFkSource()) | ||||
| 			.set(T_SUBJECT.THEME, bean.getTheme()) | ||||
| 			.set(T_SUBJECT.SUBTHEME, bean.getSubtheme()) | ||||
| 			.set(T_SUBJECT.BOOK_PAGES, bean.getBookPages()) | ||||
| 			.set(T_SUBJECT.WORKSHEETS, bean.getWorksheets()) | ||||
| 			.set(T_SUBJECT.BIBLEVERSE, bean.getBibleverse()) | ||||
| 			.set(T_SUBJECT.NOTES, bean.getNotes()) | ||||
| 			.set(T_SUBJECT.ORDER_NR, bean.getOrderNr()) | ||||
| 			.where(T_SUBJECT.PK_SUBJECT.eq(bean.getPkSubject())); | ||||
| 		// @formatter:on | ||||
| 		LOGGER.trace(sql); | ||||
| 		sql.execute(); | ||||
| 	} | ||||
|  | ||||
| 	public TSubjectRecord getBeanIfDeletable(Integer pkSubject) { | ||||
| 		SelectOrderByStep<TSubjectRecord> sql = jooq | ||||
| 		// @formatter:off | ||||
| 			.selectFrom(T_SUBJECT) | ||||
| 			.where(T_SUBJECT.PK_SUBJECT.notIn(jooq | ||||
| 				.select(T_LESSON_SUBJECT.FK_SUBJECT) | ||||
| 				.from(T_LESSON_SUBJECT))) | ||||
| 			.and(T_SUBJECT.PK_SUBJECT.eq(pkSubject)); | ||||
| 		// @formatter:off | ||||
| 		LOGGER.trace(sql); | ||||
| 		return sql.fetchOne(); | ||||
| 	} | ||||
|  | ||||
| 	public void removeSubject(Integer pkSubject) { | ||||
| 		DeleteConditionStep<TSubjectRecord> sql = jooq.deleteFrom(T_SUBJECT).where(T_SUBJECT.PK_SUBJECT.eq(pkSubject)); | ||||
| 		LOGGER.trace(sql); | ||||
| 		sql.execute(); | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,50 @@ | ||||
| package de.jottyfan.bico.modules.subject; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import de.jottyfan.bico.db.tables.records.TSourceRecord; | ||||
| import de.jottyfan.bico.db.tables.records.TSubjectRecord; | ||||
| import de.jottyfan.bico.db.tables.records.VLessonRecord; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| @Service | ||||
| public class SubjectService { | ||||
|  | ||||
| 	@Autowired | ||||
| 	private SubjectRepository repository; | ||||
|  | ||||
| 	public List<VLessonRecord> getSubjects() { | ||||
| 		return repository.getSubjects(); | ||||
| 	} | ||||
|  | ||||
| 	public TSubjectRecord getSubject(Integer pkSubject) { | ||||
| 		return repository.getSubject(pkSubject); | ||||
| 	} | ||||
|  | ||||
| 	public List<TSourceRecord> getSources() { | ||||
| 		return repository.getSources(); | ||||
| 	} | ||||
|  | ||||
| 	public void save(TSubjectRecord bean) { | ||||
| 		if (bean.getPkSubject() == null) { | ||||
| 			repository.addSubject(bean); | ||||
| 		} else { | ||||
| 			repository.updateSubject(bean); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	public TSubjectRecord getBeanIfDeletable(Integer pkSubject) { | ||||
| 		return repository.getBeanIfDeletable(pkSubject); | ||||
| 	} | ||||
|  | ||||
| 	public void removeSubject(Integer pkSubject) { | ||||
| 		repository.removeSubject(pkSubject); | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,164 @@ | ||||
| package de.jottyfan.bico.modules.subject.model; | ||||
|  | ||||
| import java.io.Serializable; | ||||
|  | ||||
| import de.jottyfan.bico.db.tables.records.TSubjectRecord; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author jotty | ||||
|  * | ||||
|  */ | ||||
| public class SubjectBean implements Serializable { | ||||
| 	private static final long serialVersionUID = 1L; | ||||
|  | ||||
| 	private Integer pkSubject; | ||||
| 	private Integer fkSource; | ||||
| 	private String theme; | ||||
| 	private String subtheme; | ||||
| 	private String bookPages; | ||||
| 	private String worksheets; | ||||
| 	private String bibleverse; | ||||
| 	private String notes; | ||||
| 	private Integer orderNr; | ||||
|  | ||||
| 	public static final SubjectBean of(TSubjectRecord r) { | ||||
| 		SubjectBean bean = new SubjectBean(); | ||||
| 		bean.setPkSubject(r.getPkSubject()); | ||||
| 		bean.setFkSource(r.getFkSource()); | ||||
| 		bean.setTheme(r.getTheme()); | ||||
| 		bean.setSubtheme(r.getSubtheme()); | ||||
| 		bean.setBookPages(r.getBookPages()); | ||||
| 		bean.setWorksheets(r.getWorksheets()); | ||||
| 		bean.setBibleverse(r.getBibleverse()); | ||||
| 		bean.setNotes(r.getNotes()); | ||||
| 		bean.setOrderNr(r.getOrderNr()); | ||||
| 		return bean; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the pkSubject | ||||
| 	 */ | ||||
| 	public Integer getPkSubject() { | ||||
| 		return pkSubject; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param pkSubject the pkSubject to set | ||||
| 	 */ | ||||
| 	public void setPkSubject(Integer pkSubject) { | ||||
| 		this.pkSubject = pkSubject; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the fkSource | ||||
| 	 */ | ||||
| 	public Integer getFkSource() { | ||||
| 		return fkSource; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param fkSource the fkSource to set | ||||
| 	 */ | ||||
| 	public void setFkSource(Integer fkSource) { | ||||
| 		this.fkSource = fkSource; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @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 notes | ||||
| 	 */ | ||||
| 	public String getNotes() { | ||||
| 		return notes; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param notes the notes to set | ||||
| 	 */ | ||||
| 	public void setNotes(String notes) { | ||||
| 		this.notes = notes; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the orderNr | ||||
| 	 */ | ||||
| 	public Integer getOrderNr() { | ||||
| 		return orderNr; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param orderNr the orderNr to set | ||||
| 	 */ | ||||
| 	public void setOrderNr(Integer orderNr) { | ||||
| 		this.orderNr = orderNr; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user