diff --git a/Frontend/index.html b/Frontend/index.html index a4b7c9d..6851fc3 100644 --- a/Frontend/index.html +++ b/Frontend/index.html @@ -13,20 +13,26 @@
diff --git a/Frontend/script.js b/Frontend/script.js index 09a7f36..1aab2c5 100644 --- a/Frontend/script.js +++ b/Frontend/script.js @@ -1,40 +1,41 @@ -let buttonUpper = document.getElementById("buttonUpper"); -let buttonLower = document.getElementById("buttonLower"); +let buttonSum = document.getElementById("buttonSum"); +let buttonMinus = document.getElementById("buttonMinus"); let buttonReverse = document.getElementById("buttonReverse"); -let buttonCount = document.getElementById("buttonCount"); -let buttonDel = document.getElementById("buttonDel"); -let stringInput = document.getElementById("string"); -let placeInput = document.getElementById("place"); +let buttonComparison = document.getElementById("buttonComparison"); +let numberOneInput = document.getElementById("first"); +let numberTwoInput = document.getElementById("second"); +let typeInput = document.getElementById("type"); let resultInput = document.getElementById("res"); -buttonUpper.onclick = function(event) { - let str = stringInput.value; - fetch(`http://localhost:8080/toUpperCase?string=${str}`) +buttonSum.onclick = function(event) { + let num_1 = numberOneInput.value; + let num_2 = numberTwoInput.value; + let type = typeInput.value; + fetch(`http://localhost:8080/sum?first=${num_1}&second=${num_2}&type=${type}`) .then(response => response.text()) .then(res => resultInput.value = res); } -buttonLower.onclick = function(event) { - let str = stringInput.value; - fetch(`http://localhost:8080/toLowerCase?string=${str}`) +buttonMinus.onclick = function(event) { + let num_1 = numberOneInput.value; + let num_2 = numberTwoInput.value; + let type = typeInput.value; + fetch(`http://localhost:8080/minus?first=${num_1}&second=${num_2}&type=${type}`) .then(response => response.text()) .then(res => resultInput.value = res); } buttonReverse.onclick = function(event) { - let str = stringInput.value; - fetch(`http://localhost:8080/reverse?string=${str}`) + let num_1 = numberOneInput.value; + let num_2 = numberTwoInput.value; + let type = typeInput.value; + fetch(`http://localhost:8080/reverse?first=${num_1}&second=${num_2}&type=${type}`) .then(response => response.text()) .then(res => resultInput.value = res); } -buttonCount.onclick = function(event) { - let str = stringInput.value; - fetch(`http://localhost:8080/count?string=${str}`) - .then(response => response.text()) - .then(res => resultInput.value = res); -} -buttonDel.onclick = function(event) { - let str = stringInput.value; - let plc = placeInput.value; - fetch(`http://localhost:8080/del?string=${str}&place=${plc}`) +buttonComparison.onclick = function(event) { + let num_1 = numberOneInput.value; + let num_2 = numberTwoInput.value; + let type = typeInput.value; + fetch(`http://localhost:8080/comparison?first=${num_1}&second=${num_2}&type=${type}`) .then(response => response.text()) .then(res => resultInput.value = res); } diff --git a/src/main/java/ru/ulstu/is/lab1/Lab1.java b/src/main/java/ru/ulstu/is/lab1/Lab1.java index 5d856db..fb8823a 100644 --- a/src/main/java/ru/ulstu/is/lab1/Lab1.java +++ b/src/main/java/ru/ulstu/is/lab1/Lab1.java @@ -13,32 +13,4 @@ public class Lab1 { public static void main(String[] args) { SpringApplication.run(Lab1.class, args); } - @GetMapping("/hello") - public String hello(@RequestParam(value = "name", defaultValue = "World") String name) { - return String.format("Hello %s!", name); - } - @GetMapping("/toUpperCase") - public String toUpperCase(@RequestParam(defaultValue = "word") String string){ - return string.toUpperCase(); - } - @GetMapping("/toLowerCase") - public String toLowerCase(@RequestParam(defaultValue = "word") String string){ - return string.toLowerCase(); - } - @GetMapping("/reverse") - public String reverse(@RequestParam(defaultValue = "word") String string){ - String newStr=""; - for(int i = string.length() - 1; i >= 0; i--){ - newStr += string.charAt(i); - } - return newStr; - } - @GetMapping("/count") - public String count(@RequestParam(defaultValue = "word") String string){ - return Integer.toString(string.length()); - } - @GetMapping("/del") - public String del(@RequestParam(defaultValue = "word") String string, String place){ - return String.join(" ", string.split(place)); - } } \ No newline at end of file diff --git a/src/main/java/ru/ulstu/is/lab1/speaker/controller/MethodController.java b/src/main/java/ru/ulstu/is/lab1/speaker/controller/MethodController.java new file mode 100644 index 0000000..3078f46 --- /dev/null +++ b/src/main/java/ru/ulstu/is/lab1/speaker/controller/MethodController.java @@ -0,0 +1,43 @@ +package ru.ulstu.is.lab1.speaker.controller; + +import ru.ulstu.is.lab1.speaker.service.MethodService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MethodController { + private final MethodService speakerService; + + public MethodController(MethodService speakerService) { + this.speakerService = speakerService; + } + + @GetMapping("/sum") + public String Sum(@RequestParam(value = "first", defaultValue = "1") Object first, + @RequestParam(value = "second", defaultValue = "1") Object second, + @RequestParam(value = "type", defaultValue = "int") String type) { + return speakerService.Sum(first, second, type); + } + + @GetMapping("/minus") + public String Ras(@RequestParam(value = "first", defaultValue = "1") Object first, + @RequestParam(value = "second", defaultValue = "1") Object second, + @RequestParam(value = "type", defaultValue = "int") String type) { + return speakerService.Ras(first, second, type); + } + + @GetMapping("/reverse") + public String Pros(@RequestParam(value = "first", defaultValue = "1") Object first, + @RequestParam(value = "second", defaultValue = "1") Object second, + @RequestParam(value = "type", defaultValue = "int") String type) { + return speakerService.Rev(first, second, type); + } + + @GetMapping("/comparison") + public String Del(@RequestParam(value = "first", defaultValue = "1") Object first, + @RequestParam(value = "second", defaultValue = "1") Object second, + @RequestParam(value = "type", defaultValue = "int") String type) { + return speakerService.Com(first, second, type); + } +} diff --git a/src/main/java/ru/ulstu/is/lab1/speaker/domain/IMethod.java b/src/main/java/ru/ulstu/is/lab1/speaker/domain/IMethod.java new file mode 100644 index 0000000..da3db8e --- /dev/null +++ b/src/main/java/ru/ulstu/is/lab1/speaker/domain/IMethod.java @@ -0,0 +1,11 @@ +package ru.ulstu.is.lab1.speaker.domain; + +public interface IMethod