@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); } }
@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); } }
@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); } }