Exemplo n.º 1
0
 @RequestMapping(value = "/{accountId}", method = RequestMethod.GET)
 public ResponseEntity<AccountResource> getAccount(@PathVariable Long accountId) {
   Account account = accountService.findAccount(accountId);
   getClass().getGenericSuperclass();
   if (account != null) {
     AccountResource res = new AccountResourceAsm().toResource(account);
     return new ResponseEntity<AccountResource>(res, HttpStatus.OK);
   } else {
     return new ResponseEntity<AccountResource>(HttpStatus.NOT_FOUND);
   }
 }
Exemplo n.º 2
0
 @RequestMapping(method = RequestMethod.POST)
 public ResponseEntity<AccountResource> createAccount(@RequestBody AccountResource sentAccount) {
   try {
     Account createdAccount = accountService.createAccount(sentAccount.toAccount());
     AccountResource res = new AccountResourceAsm().toResource(createdAccount);
     HttpHeaders headers = new HttpHeaders();
     headers.setLocation(URI.create(res.getLink("self").getHref()));
     return new ResponseEntity<AccountResource>(res, headers, HttpStatus.CREATED);
   } catch (AccountExistsException exception) {
     throw new ConflictException(exception);
   }
 }
Exemplo n.º 3
0
 @RequestMapping(value = "/{accountId}/blogs", method = RequestMethod.POST)
 public ResponseEntity<BlogResource> createBlog(
     @PathVariable Long accountId, @RequestBody BlogResource res) {
   try {
     Blog createdBlog = accountService.createBlog(accountId, res.toBlog());
     BlogResource createdBlogRes = new BlogResourceAsm().toResource(createdBlog);
     HttpHeaders headers = new HttpHeaders();
     headers.setLocation(URI.create(createdBlogRes.getLink("self").getHref()));
     return new ResponseEntity<BlogResource>(createdBlogRes, headers, HttpStatus.CREATED);
   } catch (AccountDoesNotExistException exception) {
     throw new BadRequestException(exception);
   }
 }