start hw3

This commit is contained in:
2018-10-07 16:23:51 +03:00
parent a6d3851bb3
commit e8260b1700
4 changed files with 27 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
plugins {
id 'war'
id 'org.gretty' version '2.2.0'
id 'io.franzbecker.gradle-lombok' version '1.14'
}
repositories {
@@ -11,9 +12,17 @@ repositories {
sourceCompatibility = 10
dependencies {
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'
compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
}
gretty {
contextPath = '/'
}
lombok {
version = '1.18.2'
sha256 = ""
}

View File

@@ -0,0 +1,9 @@
package DTO;
import lombok.Data;
import java.util.List;
public @Data class Order {
private String orderNumber;
private List<OrderItem> orderRows;
}

View File

@@ -0,0 +1,9 @@
package DTO;
import lombok.Data;
public @Data class OrderItem {
private String itemName;
private Integer quantity;
private Integer price;
}

View File

@@ -25,17 +25,7 @@ public class Orders extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/json");
String order = req.getReader().lines().collect(Collectors.joining(" "));
int orderId = lastOrderId++;
Matcher matcher = orderPattern.matcher(order);
boolean matches = matcher.matches();
if (matches && matcher.groupCount() > 0) {
String orderNumber = matcher.group(1);
System.out.format("request data: %s, orderNumber: %s\n", order, orderNumber);
resp.getWriter().printf("{\"id\": %d, \"orderNumber\": \"%s\"}", orderId, orderNumber);
} else {
resp.getWriter().print("\"Invalid request\"");
}
}