diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..6b89df2 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,41 @@ + + + + + + + + Document + + +
+

Калькулятор

+
+
+ + +
+
+ + + +
+
+ + +
+
+ +
+ +

+ + + + + \ No newline at end of file diff --git a/frontend/js/script.js b/frontend/js/script.js new file mode 100644 index 0000000..633182d --- /dev/null +++ b/frontend/js/script.js @@ -0,0 +1,39 @@ +let form = document.getElementById("form"); +let info = document.getElementById("res"); + + +form.onsubmit = async (e) => { + e.preventDefault(); + + if(form.num1.value === "") return; + if(form.num2.value === "") return; + + let index = form.selected.selectedIndex; + + let op = form.selected.options[index].textContent; + let res = ""; + + switch(op) { + case "+": + res = await fetch(`http://localhost:8080/sum?num1=${form.num1.value}&num2=${form.num2.value}`) + res = await res.text(); + break; + case "-": + res = await fetch(`http://localhost:8080/diff?num1=${form.num1.value}&num2=${form.num2.value}`) + res = await res.text(); + break; + + case "*": + res = await fetch(`http://localhost:8080/multiply?num1=${form.num1.value}&num2=${form.num2.value}`) + res = await res.text(); + break; + + case "/": + if(form.num2.value == 0) return; + res = await fetch(`http://localhost:8080/divide?num1=${form.num1.value}&num2=${form.num2.value}`) + res = await res.text(); + break; + } + + info.textContent = res; +} \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..956baa8 --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,15 @@ +{ + "name": "frontend", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "http-server -p 3000 -c-1 -o ./" + }, + "author": "", + "license": "ISC", + "dependencies": { + "bootstrap": "^5.2.3", + "http-server": "^14.1.1" + } +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/is/sbapp/SbappApplication.java b/src/main/java/ru/ulstu/is/sbapp/SbappApplication.java index db0ba78..236ecb0 100644 --- a/src/main/java/ru/ulstu/is/sbapp/SbappApplication.java +++ b/src/main/java/ru/ulstu/is/sbapp/SbappApplication.java @@ -14,25 +14,28 @@ public class SbappApplication { SpringApplication.run(SbappApplication.class, args); } - @GetMapping("/hello") - public String hello() { - return "Hello, i'm working!"; - } - - @GetMapping("/ToUpper") - public String ToUpper(@RequestParam(value = "", defaultValue = "default") String text) { - return String.format(text).toUpperCase(); - } - - @GetMapping("/calc") - public Integer calc(@RequestParam(defaultValue = "10") Integer num1, - @RequestParam(defaultValue = "10") Integer num2) { + @GetMapping("/sum") + public Integer sum(@RequestParam Integer num1, + @RequestParam Integer num2) { return num1 + num2; } - @GetMapping("/concate") - public String concate(@RequestParam String text) { - return "Word-"+ text; + @GetMapping("/diff") + public Integer diff(@RequestParam Integer num1, + @RequestParam Integer num2) { + return num1 - num2; + } + + @GetMapping("/multiply") + public Integer multiply(@RequestParam Integer num1, + @RequestParam Integer num2) { + return num1 * num2; + } + + @GetMapping("/divide") + public Integer divide(@RequestParam Integer num1, + @RequestParam Integer num2) { + return num1 / num2; } @GetMapping("/divider") diff --git a/src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java b/src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java new file mode 100644 index 0000000..64d729a --- /dev/null +++ b/src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java @@ -0,0 +1,13 @@ +package ru.ulstu.is.sbapp; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfiguration implements WebMvcConfigurer { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedMethods("*"); + } +} \ No newline at end of file diff --git a/src/main/resources/static/styles.css b/src/main/resources/static/styles.css deleted file mode 100644 index b8b619f..0000000 --- a/src/main/resources/static/styles.css +++ /dev/null @@ -1,3 +0,0 @@ -h1 { -color: red; -} \ No newline at end of file diff --git a/src/main/resources/static/test.js b/src/main/resources/static/test.js deleted file mode 100644 index 6933143..0000000 --- a/src/main/resources/static/test.js +++ /dev/null @@ -1,7 +0,0 @@ -function test() { - fetch("http://localhost:8080/hello", { - mode: - } -} - -test(); \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html deleted file mode 100644 index eb314d5..0000000 --- a/src/main/resources/templates/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - -

IA WORK!

- - - \ No newline at end of file