29 lines
933 B
Java
29 lines
933 B
Java
package demo.event;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
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 java.util.Optional;
|
|
|
|
@RestController
|
|
@RequestMapping("/v1")
|
|
public class EventController {
|
|
|
|
private EventService eventService;
|
|
|
|
public EventController(EventService eventService) {
|
|
this.eventService = eventService;
|
|
}
|
|
|
|
@PostMapping(path = "/events")
|
|
public ResponseEntity handleEvent(@RequestBody PaymentEvent event) {
|
|
return Optional.ofNullable(eventService.apply(event))
|
|
.map(e -> new ResponseEntity<>(e, HttpStatus.CREATED))
|
|
.orElseThrow(() -> new RuntimeException("Apply event failed"));
|
|
}
|
|
}
|