예제 #1
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();
   }
 }
예제 #2
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();
   }
 }