示例#1
0
  // 부분 업데이트 : PATCH
  // - (username:"******")
  // - (passowrd:"pass")
  // - (fullName:"seokgon lee")
  @RequestMapping(value = "/accounts/{id}", method = PUT)
  public ResponseEntity updateAccount(
      @PathVariable Long id,
      @RequestBody @Valid AccountDto.Update updateDto,
      BindingResult result) {
    if (result.hasErrors()) {
      return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

    Account updateAccount = service.updateAccount(id, updateDto);
    return new ResponseEntity<>(
        modelMapper.map(updateAccount, AccountDto.Response.class), HttpStatus.OK);
  }
示例#2
0
  @RequestMapping(value = "/accounts", method = POST)
  public ResponseEntity createAccount(
      @RequestBody @Valid AccountDto.Create create, BindingResult result) {
    if (result.hasErrors()) {
      ErrorResponse errorResponse = new ErrorResponse();
      errorResponse.setMessage("잘못된 요청입니다.");
      errorResponse.setCode("bad.request");
      // TODO bindingResult 안에 들어있는 에러 정보 사용하기.
      return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
    }

    // 1.리턴 타임으로 판단.
    // 2.파라미터 이용.
    Account newAccount = service.createAccount(create);
    return new ResponseEntity<>(
        modelMapper.map(newAccount, AccountDto.Response.class), HttpStatus.CREATED);
  }
示例#3
0
 @RequestMapping(value = "/accounts/{id}", method = DELETE)
 public ResponseEntity deleteAccount(@PathVariable Long id) {
   service.deleteAccount(id);
   return new ResponseEntity<>(HttpStatus.NO_CONTENT);
 }
示例#4
0
 @RequestMapping(value = "accounts/{id}", method = GET)
 @ResponseStatus(HttpStatus.OK)
 public AccountDto.Response getAccount(@PathVariable Long id) {
   Account account = service.getAccount(id);
   return modelMapper.map(account, AccountDto.Response.class);
 }