Skip to content

Commit

Permalink
#588 asMap()
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Mar 29, 2019
1 parent 24bc7cf commit 23065ce
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import javax.servlet.http.HttpServletRequest;
import java.util.Locale;
import java.util.Map;


@RestController
Expand All @@ -41,23 +42,23 @@ public class EventApiV2Controller {


@GetMapping("events")
public ResponseEntity<Model> listEvents(Model model, Locale locale, HttpServletRequest request) {
public ResponseEntity<Map<String, ?>> listEvents(Model model, Locale locale, HttpServletRequest request) {
eventController.listEvents(model, locale);
return new ResponseEntity<>(model, getCorsHeaders(), HttpStatus.OK);
return new ResponseEntity<>(model.asMap(), getCorsHeaders(), HttpStatus.OK);
}

@GetMapping("/event/{eventName}")
public ResponseEntity<Model> getEvent(@PathVariable("eventName") String eventName,
public ResponseEntity<Map<String, ?>> getEvent(@PathVariable("eventName") String eventName,
Model model, HttpServletRequest request, Locale locale) {
if ("/event/show-event".equals(eventController.showEvent(eventName, model, request, locale))) {
return new ResponseEntity<>(model, getCorsHeaders(), HttpStatus.OK);
return new ResponseEntity<>(model.asMap(), getCorsHeaders(), HttpStatus.OK);
} else {
return ResponseEntity.notFound().headers(getCorsHeaders()).build();
}
}

@PostMapping(value = "/event/{eventName}/reserve-tickets")
public ResponseEntity<Model> reserveTicket(@PathVariable("eventName") String eventName,
public ResponseEntity<Map<String, ?>> reserveTicket(@PathVariable("eventName") String eventName,
@RequestBody ReservationForm reservation,
BindingResult bindingResult,
ServletWebRequest request,
Expand All @@ -67,11 +68,11 @@ public ResponseEntity<Model> reserveTicket(@PathVariable("eventName") String eve
String redirectResult = eventController.reserveTicket(eventName, reservation, bindingResult, request, redirectAttributes, locale);

if (bindingResult.hasErrors()) {
return new ResponseEntity<>(redirectAttributes, getCorsHeaders(), HttpStatus.OK);
return new ResponseEntity<>(redirectAttributes.asMap(), getCorsHeaders(), HttpStatus.OK);
} else {
String reservationIdentifier = redirectResult.substring(redirectResult.length()).replace("/book", "");
redirectAttributes.addAttribute("reservationIdentifier", reservationIdentifier);
return new ResponseEntity<>(redirectAttributes, getCorsHeaders(), HttpStatus.OK);
return new ResponseEntity<>(redirectAttributes.asMap(), getCorsHeaders(), HttpStatus.OK);
}

}
Expand Down

0 comments on commit 23065ce

Please sign in to comment.