コード例 #1
0
 @RequestMapping(value = "/remove/{chatId}", method = RequestMethod.GET)
 @PreAuthorize("permitAll")
 public ResponseEntity<ChatResource> remove(@PathVariable Long chatId) {
   Chat chat = chatService.remove(chatId);
   if (chat != null) {
     return new ResponseEntity<ChatResource>(
         new ChatResourceAsm().toResource(chat), HttpStatus.OK);
   } else {
     return new ResponseEntity<ChatResource>(HttpStatus.NOT_FOUND);
   }
 }
コード例 #2
0
 @RequestMapping(value = "/all", method = RequestMethod.GET)
 @PreAuthorize("permitAll")
 public ResponseEntity<ChatListResource> list() {
   Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
   if (principal instanceof UserDetails) {
     UserDetails user = (UserDetails) principal;
     Account account = accountService.find(user.getUsername());
     if (account == null) {
       throw new ForbiddenException();
     } else {
       List<Chat> chats = chatService.find4Account(account.getId());
       return new ResponseEntity<ChatListResource>(
           new ChatListResourceAsm().toResource(new ChatListResource.ChatList(chats)),
           HttpStatus.OK);
     }
   } else {
     throw new ForbiddenException();
   }
 }
コード例 #3
0
 @RequestMapping(method = RequestMethod.POST)
 @PreAuthorize("permitAll")
 public ResponseEntity<ChatResource> createChat(@RequestBody ChatResource sentChat) {
   Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
   if (principal instanceof UserDetails) {
     UserDetails user = (UserDetails) principal;
     Account account = accountService.find(user.getUsername());
     if (account == null) {
       throw new ForbiddenException();
     } else {
       Chat chat = sentChat.toChat();
       chatService.create(chat, account.getId());
       try {
         return new ResponseEntity<ChatResource>(
             new ChatResourceAsm().toResource(chat), HttpStatus.OK);
       } catch (Exception e) {
         return new ResponseEntity<ChatResource>(HttpStatus.NOT_FOUND);
       }
     }
   } else {
     throw new ForbiddenException();
   }
 }