From 62ec7e0fb49835288187828a8f8fe1e9f3eecc43 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Tue, 28 Feb 2023 11:35:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/ipLab/IpLabApplication.java | 3 +- .../com/example/ipLab/WebConfiguration.java | 13 ++++ .../ipLab/controllers/CalcController.java | 39 +++++++++++ frontend/index.html | 25 +++++++ frontend/package.json | 19 +++++ frontend/scripts/calc.js | 70 +++++++++++++++++++ frontend/style.css | 6 ++ 7 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 backend/ipLab/src/main/java/com/example/ipLab/WebConfiguration.java create mode 100644 backend/ipLab/src/main/java/com/example/ipLab/controllers/CalcController.java create mode 100644 frontend/index.html create mode 100644 frontend/package.json create mode 100644 frontend/scripts/calc.js create mode 100644 frontend/style.css 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 @@ + + +
+ + + + + + +