From df4fd6d0ff7811cd3a3ca65e78e94c1eb341aee8 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 26 Sep 2023 21:58:00 +0400 Subject: [PATCH] #3 -- Add models and pages --- .../fc/rule/controller/RuleController.java | 47 ++++++++++++++++++- .../ulstu/fc/rule/model/AddVariableForm.java | 13 +++++ .../fc/rule/repository/RuleRepository.java | 7 +++ .../fc/rule/repository/TermRepository.java | 7 +++ .../rule/repository/VariableRepository.java | 7 +++ .../ru/ulstu/fc/rule/service/RuleService.java | 20 ++++++++ .../ru/ulstu/fc/rule/service/TermService.java | 20 ++++++++ .../ulstu/fc/rule/service/TermsService.java | 20 ++++++++ .../fc/rule/service/VariableService.java | 21 +++++++++ src/main/resources/templates/addVariable.html | 41 ++++++++++++++++ src/main/resources/templates/default.html | 7 ++- src/main/resources/templates/listTerms.html | 35 ++++++++++++++ src/main/resources/templates/listVars.html | 35 ++++++++++++++ 13 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/fc/rule/model/AddVariableForm.java create mode 100644 src/main/java/ru/ulstu/fc/rule/repository/RuleRepository.java create mode 100644 src/main/java/ru/ulstu/fc/rule/repository/TermRepository.java create mode 100644 src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java create mode 100644 src/main/java/ru/ulstu/fc/rule/service/RuleService.java create mode 100644 src/main/java/ru/ulstu/fc/rule/service/TermService.java create mode 100644 src/main/java/ru/ulstu/fc/rule/service/TermsService.java create mode 100644 src/main/java/ru/ulstu/fc/rule/service/VariableService.java create mode 100644 src/main/resources/templates/addVariable.html create mode 100644 src/main/resources/templates/listTerms.html create mode 100644 src/main/resources/templates/listVars.html diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java index 788568c..ef6f365 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java @@ -7,16 +7,47 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import ru.ulstu.fc.rule.model.AddRuleForm; import ru.ulstu.fc.rule.model.AddTermForm; +import ru.ulstu.fc.rule.model.AddVariableForm; import ru.ulstu.fc.rule.service.RuleParseService; +import ru.ulstu.fc.rule.service.RuleService; +import ru.ulstu.fc.rule.service.TermsService; +import ru.ulstu.fc.rule.service.VariableService; import java.util.List; @Controller public class RuleController { private final RuleParseService ruleParseService; + private final RuleService ruleService; + private final TermsService termService; + private final VariableService variableService; - public RuleController(RuleParseService ruleParseService) { + public RuleController(RuleParseService ruleParseService, + RuleService ruleService, + TermsService termService, + VariableService variableService) { this.ruleParseService = ruleParseService; + this.ruleService = ruleService; + this.termService = termService; + this.variableService = variableService; + } + + @GetMapping("listRules") + public String listRules(Model model) { + model.addAttribute("rules", ruleService.getRules()); + return "listRules"; + } + + @GetMapping("listTerms") + public String listTerms(Model model) { + model.addAttribute("terms", termService.getTerms()); + return "listTerms"; + } + + @GetMapping("listVars") + public String listVariables(Model model) { + model.addAttribute("vars", variableService.getVars()); + return "listVars"; } @GetMapping("addRule") @@ -36,6 +67,18 @@ public class RuleController { return "listRules"; } + @GetMapping("addVariable") + public String addVariable(Model model) { + model.addAttribute("addVariableForm", new AddVariableForm()); + return "addVariable"; + } + + @PostMapping("addVariable") + public String addVariable(@ModelAttribute AddVariableForm addVariableForm, Model model) { + model.addAttribute("addVariableForm", addVariableForm); + return "listVars"; + } + @GetMapping("addTerm") public String addTerm(Model model) { model.addAttribute("addTermForm", new AddTermForm()); @@ -43,7 +86,7 @@ public class RuleController { } @PostMapping("addTerm") - public String parse(@ModelAttribute AddTermForm addTermForm, Model model) { + public String addTerm(@ModelAttribute AddTermForm addTermForm, Model model) { model.addAttribute("addTermForm", addTermForm); return "listTerms"; } diff --git a/src/main/java/ru/ulstu/fc/rule/model/AddVariableForm.java b/src/main/java/ru/ulstu/fc/rule/model/AddVariableForm.java new file mode 100644 index 0000000..2058006 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/model/AddVariableForm.java @@ -0,0 +1,13 @@ +package ru.ulstu.fc.rule.model; + +public class AddVariableForm { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/ru/ulstu/fc/rule/repository/RuleRepository.java b/src/main/java/ru/ulstu/fc/rule/repository/RuleRepository.java new file mode 100644 index 0000000..eeac0e9 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/repository/RuleRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.fc.rule.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.fc.rule.model.Rule; + +public interface RuleRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/fc/rule/repository/TermRepository.java b/src/main/java/ru/ulstu/fc/rule/repository/TermRepository.java new file mode 100644 index 0000000..00efd09 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/repository/TermRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.fc.rule.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.fc.rule.model.Term; + +public interface TermRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java b/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java new file mode 100644 index 0000000..29d1231 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.fc.rule.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.fc.rule.model.Variable; + +public interface VariableRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/fc/rule/service/RuleService.java b/src/main/java/ru/ulstu/fc/rule/service/RuleService.java new file mode 100644 index 0000000..0969087 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/service/RuleService.java @@ -0,0 +1,20 @@ +package ru.ulstu.fc.rule.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.fc.rule.model.Rule; +import ru.ulstu.fc.rule.repository.RuleRepository; + +import java.util.List; + +@Service +public class RuleService { + private final RuleRepository ruleRepository; + + public RuleService(RuleRepository ruleRepository) { + this.ruleRepository = ruleRepository; + } + + public List getRules() { + return ruleRepository.findAll(); + } +} diff --git a/src/main/java/ru/ulstu/fc/rule/service/TermService.java b/src/main/java/ru/ulstu/fc/rule/service/TermService.java new file mode 100644 index 0000000..a475aab --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/service/TermService.java @@ -0,0 +1,20 @@ +package ru.ulstu.fc.rule.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.fc.rule.model.Term; +import ru.ulstu.fc.rule.repository.TermRepository; + +import java.util.List; + +@Service +public class TermService { + private final TermRepository termRepository; + + public TermService(TermRepository termRepository) { + this.termRepository = termRepository; + } + + public List getTerms() { + return termRepository.findAll(); + } +} diff --git a/src/main/java/ru/ulstu/fc/rule/service/TermsService.java b/src/main/java/ru/ulstu/fc/rule/service/TermsService.java new file mode 100644 index 0000000..273e0fa --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/service/TermsService.java @@ -0,0 +1,20 @@ +package ru.ulstu.fc.rule.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.fc.rule.model.Term; +import ru.ulstu.fc.rule.repository.TermRepository; + +import java.util.List; + +@Service +public class TermsService { + private final TermRepository termRepository; + + public TermsService(TermRepository termRepository) { + this.termRepository = termRepository; + } + + public List getTerms() { + return termRepository.findAll(); + } +} diff --git a/src/main/java/ru/ulstu/fc/rule/service/VariableService.java b/src/main/java/ru/ulstu/fc/rule/service/VariableService.java new file mode 100644 index 0000000..0a9890c --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/service/VariableService.java @@ -0,0 +1,21 @@ +package ru.ulstu.fc.rule.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.fc.rule.model.Variable; +import ru.ulstu.fc.rule.repository.VariableRepository; + +import java.util.List; + +@Service +public class VariableService { + private final VariableRepository variableRepository; + + public VariableService(VariableRepository variableRepository) { + this.variableRepository = variableRepository; + } + + + public List getVars() { + return variableRepository.findAll(); + } +} diff --git a/src/main/resources/templates/addVariable.html b/src/main/resources/templates/addVariable.html new file mode 100644 index 0000000..bfb1cee --- /dev/null +++ b/src/main/resources/templates/addVariable.html @@ -0,0 +1,41 @@ + + + + Добавить терм + + +
+
+
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 916fa56..a3b330d 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -22,10 +22,13 @@ diff --git a/src/main/resources/templates/listTerms.html b/src/main/resources/templates/listTerms.html new file mode 100644 index 0000000..d35960e --- /dev/null +++ b/src/main/resources/templates/listTerms.html @@ -0,0 +1,35 @@ + + + + Список термов + + +
+ + + + + + + + + + + + + +
Термы
+ + + + + + + +
+ Добавить терм +
+ diff --git a/src/main/resources/templates/listVars.html b/src/main/resources/templates/listVars.html new file mode 100644 index 0000000..705ac4e --- /dev/null +++ b/src/main/resources/templates/listVars.html @@ -0,0 +1,35 @@ + + + + Список переменных + + +
+ + + + + + + + + + + + + +
Переменные
+ + + + + + + +
+ Добавить переменную +
+