Skip to content

Commit

Permalink
Merge pull request #30 from LimdaeIl/feature/#27-ch15
Browse files Browse the repository at this point in the history
15๊ฐ•. ์œ ์ € ์—…๋ฐ์ดํŠธ API, ์‚ญ์ œ API ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ํ•˜๊ธฐ
  • Loading branch information
LimdaeIl authored Feb 21, 2024
2 parents 14e4b47 + 0193cf9 commit d9ab4d5
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,23 @@ public UserResponse mapRow(ResultSet rs, int rowNum) throws SQLException {

@PutMapping("/user")
public void updateUser(@RequestBody UserUpdateRequest request) {
String readSql = "select * from user where id=?";
boolean isUserNotExist = jdbcTemplate.query(readSql, (rs, rowNum) -> 0, request.getId()).isEmpty();
if (isUserNotExist) {
throw new IllegalArgumentException();
}

String sql = "update user set name = ? where id = ?";
jdbcTemplate.update(sql, request.getName(), request.getId());
}

@DeleteMapping("/user")
public void deleteUser(@RequestParam String name) {
String readSql = "select * from user where name=?";
boolean isUserNotExist = jdbcTemplate.query(readSql, (rs, rowNum) -> 0, name).isEmpty();
if (isUserNotExist) {
throw new IllegalArgumentException();
}
String sql = "delete from user where name = ?";
jdbcTemplate.update(sql, name);
}
Expand Down

0 comments on commit d9ab4d5

Please sign in to comment.