package com.cloudnative.reference;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import java.net.URI;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import org.axonframework.commandhandling.gateway.CommandGateway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

@RestController
@RequestMapping(value = "/order", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public class OrderRestController {

	private final CommandGateway commandGateway;

	@Autowired
	OrderRestController(CommandGateway cg) {
		this.commandGateway = cg;
	}

	@PostMapping
	CompletableFuture<ResponseEntity<?>> createOrder(@RequestBody Map<String, String> body) {

		String id = UUID.randomUUID().toString();
		CreateOrderCommand orderCommand = new CreateOrderCommand(id, body.get("description"));
		return null;
	}

	private static URI uri(String uri, Map<String, String> template) {
		UriComponents uriComponents = UriComponentsBuilder.newInstance().path(uri).build().expand(template);
		return uriComponents.toUri();
	}

}

@@ -107,29 +107,8 @@
 E;%0A%0A
-import java.net.URI;%0A
 impo
@@ -148,16 +148,17 @@
 l.UUID;%0A
+%0A
 import j
@@ -164,41 +164,41 @@
 java
-.util.concurrent.CompletableFutur
+x.servlet.http.HttpServletRespons
 e;%0A%0A
@@ -329,56 +329,8 @@
 ed;%0A
-import org.springframework.http.ResponseEntity;%0A
 impo
@@ -574,117 +574,8 @@
 ler;
-%0Aimport org.springframework.web.util.UriComponents;%0Aimport org.springframework.web.util.UriComponentsBuilder;
 %0A%0A@R
@@ -880,44 +880,19 @@
 ng%0A%09
-CompletableFuture%3CResponseEntity%3C?%3E%3E
+public void
  cre
@@ -941,13 +941,42 @@
 body
+, HttpServletResponse response
 ) %7B%0A
-%0A
 %09%09St
@@ -1040,14 +1040,9 @@
 and 
-orderC
+c
 omma
@@ -1102,229 +1102,129 @@
 %22));
-%0A%09%09return null;%0A%09%7D%0A%0A%09private static URI uri(String uri, Map%3CString, String%3E template) %7B%0A%09%09UriComponents uriComponents = UriComponentsBuilder.newInstance().path(uri).build().expand(template);%0A%09%09return uriComponents.toUri()
+%09%0A        commandGateway.sendAndWait(command);%0A        response.setStatus(HttpServletResponse.SC_CREATED);%0A        return
 ;%0A%09%7D

order service controller implementation