diff --git a/backend/ipLab/src/main/java/com/example/ipLab/IpLabApplication.java b/backend/ipLab/src/main/java/com/example/ipLab/IpLabApplication.java
index 03ec120..c872368 100644
--- a/backend/ipLab/src/main/java/com/example/ipLab/IpLabApplication.java
+++ b/backend/ipLab/src/main/java/com/example/ipLab/IpLabApplication.java
@@ -2,6 +2,8 @@ package com.example.ipLab;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class IpLabApplication {
@@ -9,5 +11,4 @@ public class IpLabApplication {
public static void main(String[] args) {
SpringApplication.run(IpLabApplication.class, args);
}
-
}
diff --git a/backend/ipLab/src/main/java/com/example/ipLab/WebConfiguration.java b/backend/ipLab/src/main/java/com/example/ipLab/WebConfiguration.java
new file mode 100644
index 0000000..7e79574
--- /dev/null
+++ b/backend/ipLab/src/main/java/com/example/ipLab/WebConfiguration.java
@@ -0,0 +1,13 @@
+package com.example.ipLab;
+
+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("*");
+ }
+}
diff --git a/backend/ipLab/src/main/java/com/example/ipLab/controllers/CalcController.java b/backend/ipLab/src/main/java/com/example/ipLab/controllers/CalcController.java
new file mode 100644
index 0000000..9c624de
--- /dev/null
+++ b/backend/ipLab/src/main/java/com/example/ipLab/controllers/CalcController.java
@@ -0,0 +1,39 @@
+package com.example.ipLab.controllers;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class CalcController {
+
+ @GetMapping("/second")
+ public int second(@RequestParam(value = "num") int num){
+ return num*num;
+ }
+
+ @GetMapping("/root")
+ public double root(@RequestParam(value = "num") int num){
+ return Math.sqrt(num);
+ }
+
+ @GetMapping("/fact")
+ public int fact(@RequestParam(value = "num") int num){
+ int res = 1;
+ for (int i = 2; i <= num; i++) {
+ res *= i;
+ }
+ return res;
+ }
+
+ @GetMapping("/digit")
+ public int digit(@RequestParam(value = "num") int num){
+ if (num < 0) num *= -1;
+ int sum = 0;
+ while (num > 0) {
+ sum += num % 10;
+ num /= 10;
+ }
+ return sum;
+ }
+}
diff --git a/frontend/index.html b/frontend/index.html
new file mode 100644
index 0000000..5e6fdca
--- /dev/null
+++ b/frontend/index.html
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/frontend/package.json b/frontend/package.json
new file mode 100644
index 0000000..d1692fe
--- /dev/null
+++ b/frontend/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "ip_lab",
+ "version": "1.0.0",
+ "description": "My project for IP lab",
+ "main": "index.html",
+ "scripts": {
+ "start": "http-server -p 3000 ./",
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "Abazov Andrey",
+ "license": "ISC",
+ "dependencies": {
+ "bootstrap": "5.2.1",
+ "@fortawesome/fontawesome-free": "6.2.0"
+ },
+ "devDependencies": {
+ "http-server": "14.1.1"
+ }
+ }
\ No newline at end of file
diff --git a/frontend/scripts/calc.js b/frontend/scripts/calc.js
new file mode 100644
index 0000000..091f711
--- /dev/null
+++ b/frontend/scripts/calc.js
@@ -0,0 +1,70 @@
+function calcSecond(){
+ var num = document.getElementById("numberInput").value;
+ fetch("http://127.0.0.1:8080/second?num=" + num)
+ .then(function(response) {
+ if (response.status != 200){
+ return response.text().then(text => {throw new Error(text)});
+ }
+ return response.text();
+ })
+ .then((response) => {
+ document.getElementById("responseField").innerHTML = "Результат: " + response;
+ })
+ .catch(err => {document.getElementById("responseField").innerHTML = "Ошибка: " + err;})
+}
+
+function calcRoot(){
+ var num = document.getElementById("numberInput").value;
+ if (num < 0) {
+ document.getElementById("responseField").innerHTML = "Результат: введите НЕОТРИЦАТЕЛЬНОЕ число";
+ return;
+ }
+ fetch("http://127.0.0.1:8080/root?num=" + num)
+ .then((response) => {
+ if (response.status != 200){
+ return response.text().then(text => {throw new Error(text)});
+ }
+ return response.text();
+ })
+ .then((response) => {
+ console.log(response);
+ document.getElementById("responseField").innerHTML = "Результат: " + response;
+ })
+ .catch(err => {document.getElementById("responseField").innerHTML = "Ошибка: " + err;})
+}
+
+function calcFact(){
+ var num = document.getElementById("numberInput").value;
+ if (num < 0) {
+ document.getElementById("responseField").innerHTML = "Результат: введите НЕОТРИЦАТЕЛЬНОЕ число";
+ return;
+ }
+ fetch("http://127.0.0.1:8080/fact?num=" + num)
+ .then((response) => {
+ if (response.status != 200){
+ return response.text().then(text => {throw new Error(text)});
+ }
+ return response.text();
+ })
+ .then((response) => {
+ console.log(response);
+ document.getElementById("responseField").innerHTML = "Результат: " + response;
+ })
+ .catch(err => {document.getElementById("responseField").innerHTML = "Ошибка: " + err;})
+}
+
+function calcDigit(){
+ var num = document.getElementById("numberInput").value;
+ fetch("http://127.0.0.1:8080/digit?num=" + num)
+ .then((response) => {
+ if (response.status != 200){
+ return response.text().then(text => {throw new Error(text)});
+ }
+ return response.text();
+ })
+ .then((response) => {
+ console.log(response);
+ document.getElementById("responseField").innerHTML = "Результат: " + response;
+ })
+ .catch(err => {document.getElementById("responseField").innerHTML = "Ошибка: " + err;})
+}
\ No newline at end of file
diff --git a/frontend/style.css b/frontend/style.css
new file mode 100644
index 0000000..a4a8155
--- /dev/null
+++ b/frontend/style.css
@@ -0,0 +1,6 @@
+#responseField{
+ font-family: Segoe UI;
+ font-size: 24px;
+ color: black;
+ text-decoration: none;
+}