Пример #1
0
 @RequestMapping(method = RequestMethod.POST)
 public ResponseEntity newStory(@RequestBody FrameRequest frameRequest) {
   Story story = storiesRepository.save(new Story());
   Frame frame = framesRepository.save(FrameMapper.fromFrameRequest(frameRequest));
   storiesRepository.save(story.addFrame(frame));
   logger.info("new game started");
   return ResponseEntity.created(URI.create("/stories/" + story.getId())).build();
 }
Пример #2
0
 @RequestMapping(value = "/{storyId}/frame", method = RequestMethod.POST)
 public ResponseEntity newFrame(
     @PathVariable String storyId, @RequestBody FrameRequest frameRequest) {
   Frame savedFrame = framesRepository.save(FrameMapper.fromFrameRequest(frameRequest));
   Story story = storiesRepository.findOne(storyId);
   storiesRepository.save(story.addFrame(savedFrame));
   logger.info("new frame created for {}", storyId);
   return ResponseEntity.created(URI.create("/stories/" + storyId + "/" + savedFrame.getId()))
       .build();
 }
Пример #3
0
 // TODO: only for migration
 @Deprecated
 @RequestMapping(value = "/{storyId}", method = RequestMethod.PUT)
 public ResponseEntity newStoryWithFrames(
     @PathVariable String storyId,
     @RequestParam long creationDate,
     @RequestBody List<FrameRequest> framesRequests) {
   Story story =
       storiesRepository.save(
           new Story(
               storyId,
               LocalDateTime.ofInstant(Instant.ofEpochMilli(creationDate), ZoneOffset.UTC),
               new ArrayList<>()));
   Stream<Frame> frameStream = framesRequests.stream().map(FrameMapper::fromFrameRequest);
   frameStream.forEach(
       frame -> {
         framesRepository.save(frame);
         storiesRepository.save(story.addFrame(frame));
       });
   logger.info("new game with predefined frames started");
   return ResponseEntity.created(URI.create("/stories/" + story.getId())).build();
 }