done
This commit is contained in:
parent
7330e6e550
commit
edbbe4d2b1
@ -9,38 +9,41 @@
|
||||
<h2>Конвертр текста!</h2>
|
||||
<form class="needs-validation" novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="input" class="form-label">Ваш текст</label>
|
||||
<input type="text" class="form-control" id="input" required>
|
||||
<label for="input1" class="form-label">Значение 1</label>
|
||||
<input type="text" class="form-control" id="input1" required>
|
||||
<div class="invalid-feedback">Пожалуйста, введите текст</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="radio" id="radioUppercase" checked>
|
||||
<label class="form-check-label" for="radioUppercase">Undercase</label>
|
||||
</div>
|
||||
<label for="input2" class="form-label">Значение 2</label>
|
||||
<input type="text" class="form-control" id="input2" required>
|
||||
<div class="invalid-feedback">Пожалуйста, введите текст</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<select class="form-select" id="selectType" required>
|
||||
<option selected disabled>Тип</option>
|
||||
<option value="int">int</option>
|
||||
<option value="string">string</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="radio" id="radioLowcase">
|
||||
<label class="form-check-label" for="radioLowcase">Lowcase</label>
|
||||
<input class="form-check-input" type="radio" name="radio" id="radioPlus">
|
||||
<label class="form-check-label" for="radioPlus">Plus</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="radio" id="radioMinus">
|
||||
<label class="form-check-label" for="radioMinus">Minus</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="radio" id="radioMultiply">
|
||||
<label class="form-check-label" for="radioMultiply">Multiply</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="radio" id="radioDivide">
|
||||
<label class="form-check-label" for="radioDivide">Divide</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="radio" id="radioSplit">
|
||||
<label class="form-check-label" for="radioSplit">Split</label>
|
||||
<input type="text" class="form-control" id="inputSplitBy">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="radio" id="radioReplace">
|
||||
<label class="form-check-label" for="radioReplace">Replace</label>
|
||||
<input type="text" class="form-control" id="inputReplaceOld" maxlength="1">
|
||||
<input type="text" class="form-control" id="inputReplaceNew" maxlength="1">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Обработать</button>
|
||||
<button type="submit" class="btn btn-primary">Выполнить</button>
|
||||
</form>
|
||||
<h2>Результат:</h2>
|
||||
<p id="result"></p>
|
||||
|
@ -15,23 +15,24 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
document.getElementsByClassName("needs-validation")[0].addEventListener('submit', async function(event) {
|
||||
event.preventDefault();
|
||||
url = ""
|
||||
if (document.getElementById("radioUppercase").checked) {
|
||||
url = "http://localhost:8080/uppercase?value=" + document.getElementById("input").value
|
||||
url = "http://localhost:8080/"
|
||||
if (document.getElementById("radioPlus").checked) {
|
||||
url += "plus"
|
||||
}
|
||||
if (document.getElementById("radioLowcase").checked) {
|
||||
url = "http://localhost:8080/lowercase?value=" + document.getElementById("input").value
|
||||
if (document.getElementById("radioMinus").checked) {
|
||||
url += "minus"
|
||||
}
|
||||
if (document.getElementById("radioSplit").checked) {
|
||||
url = "http://localhost:8080/split?value=" + document.getElementById("input").value + "&splitBy=" + document.getElementById("inputSplitBy").value
|
||||
if (document.getElementById("radioMultiply").checked) {
|
||||
url += "multiply"
|
||||
}
|
||||
if (document.getElementById("radioReplace").checked) {
|
||||
url = "http://localhost:8080/replace?value=" + document.getElementById("input").value + "&old=" + document.getElementById("inputReplaceOld").value + "&new=" + document.getElementById("inputReplaceNew").value
|
||||
if (document.getElementById("radioDivide").checked) {
|
||||
url += "divide"
|
||||
}
|
||||
if (url == "") {
|
||||
if (url == "http://localhost:8080/") {
|
||||
document.getElementById("result").innerHTML = "Выберите действие!"
|
||||
return
|
||||
}
|
||||
// performFetch(url).then(data => {document.getElementById("result").innerHTML = data})
|
||||
url += "?value1=" + document.getElementById("input1").value + "&value2=" + document.getElementById("input2").value + "&type=" + document.getElementById("selectType").value
|
||||
document.getElementById("result").innerHTML = await performFetch(url)
|
||||
});
|
||||
|
||||
|
13
src/main/java/com/kalyshev/yan/WebConfiguration.java
Normal file
13
src/main/java/com/kalyshev/yan/WebConfiguration.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.kalyshev.yan;
|
||||
|
||||
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("*");
|
||||
}
|
||||
}
|
@ -13,19 +13,20 @@ public class MakerString implements Maker<String> {
|
||||
}
|
||||
@Override
|
||||
public String minus(String value1, String value2) {
|
||||
String res = "";
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char val1: value1.toCharArray()) {
|
||||
Boolean flag = true;
|
||||
boolean flag = true;
|
||||
for (char val2: value2.toCharArray()) {
|
||||
if (val1 == val2) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
res += val1;
|
||||
res.append(val1);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return res.toString();
|
||||
}
|
||||
@Override
|
||||
public String multiply(String value1, Integer value2) {
|
||||
|
@ -2,6 +2,7 @@ package com.kalyshev.yan.maker.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.kalyshev.yan.maker.domain.Maker;
|
||||
@ -22,9 +23,6 @@ public class MakerService {
|
||||
} else if (type.equals("string")) {
|
||||
return maker.plus(value1.toString(), value2.toString());
|
||||
}
|
||||
else {
|
||||
return "Ошибка типа";
|
||||
}
|
||||
}
|
||||
public Object minus(Object value1, Object value2, String type) {
|
||||
final Maker maker = (Maker) applicationContext.getBean(type);
|
||||
@ -33,9 +31,6 @@ public class MakerService {
|
||||
} else if (type.equals("string")) {
|
||||
return maker.minus(value1.toString(), value2.toString());
|
||||
}
|
||||
else {
|
||||
return "Ошибка типа";
|
||||
}
|
||||
}
|
||||
public Object multiply(Object value1, Object value2, String type) {
|
||||
final Maker maker = (Maker) applicationContext.getBean(type);
|
||||
@ -44,9 +39,6 @@ public class MakerService {
|
||||
} else if (type.equals("string")) {
|
||||
return maker.multiply(value1.toString(), Integer.valueOf(value2.toString()));
|
||||
}
|
||||
else {
|
||||
return "Ошибка типа";
|
||||
}
|
||||
}
|
||||
public Object divide(Object value1, Object value2, String type) {
|
||||
final Maker maker = (Maker) applicationContext.getBean(type);
|
||||
@ -55,8 +47,5 @@ public class MakerService {
|
||||
} else if (type.equals("string")) {
|
||||
return maker.divide(value1.toString(), Integer.valueOf(value2.toString()));
|
||||
}
|
||||
else {
|
||||
return "Ошибка типа";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,65 @@
|
||||
package com.kalyshev.yan;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import com.kalyshev.yan.maker.service.MakerService;
|
||||
|
||||
@SpringBootTest
|
||||
class YanApplicationTests {
|
||||
@Autowired
|
||||
MakerService makerService;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
void testMakerIntegerPlus() {
|
||||
final Object res = makerService.plus(1, 2, "int");
|
||||
Assertions.assertEquals(3, res);
|
||||
}
|
||||
@Test
|
||||
void testMakerIntegerMinus() {
|
||||
final Object res = makerService.minus(3, 1, "int");
|
||||
Assertions.assertEquals(2, res);
|
||||
}
|
||||
@Test
|
||||
void testMakerIntegerMultiply() {
|
||||
final Object res = makerService.multiply(3, 2, "int");
|
||||
Assertions.assertEquals(6, res);
|
||||
}
|
||||
@Test
|
||||
void testMakerIntegerDivide() {
|
||||
final Object res = makerService.divide(6, 2, "int");
|
||||
Assertions.assertEquals(3, res);
|
||||
}
|
||||
@Test
|
||||
void testMakerStringPlus() {
|
||||
final Object res = makerService.plus("str1", "str2", "string");
|
||||
Assertions.assertEquals("str1str2", res);
|
||||
}
|
||||
@Test
|
||||
void testMakerStringMinus() {
|
||||
final Object res = makerService.minus("sas", "s", "string");
|
||||
Assertions.assertEquals("a", res);
|
||||
}
|
||||
@Test
|
||||
void testMakerStringMultiply() {
|
||||
final Object res = makerService.multiply("sas", 2, "string");
|
||||
Assertions.assertEquals("sassas", res);
|
||||
}
|
||||
@Test
|
||||
void testMakerStringDivide() {
|
||||
final Object res = makerService.divide("12345678", 4, "string");
|
||||
Assertions.assertEquals("12 ; 34 ; 56 ; 78 ; ", res);
|
||||
}
|
||||
@Test
|
||||
void testMakerStringDivideFalse() {
|
||||
final Object res = makerService.divide("12345678", 4, "string");
|
||||
Assertions.assertEquals("12 ; 34 ; 56 ; 78 ;", res);
|
||||
}
|
||||
@Test
|
||||
void testSpeakerFalseBean() {
|
||||
Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> makerService.plus("Мир", "труд", "double"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user