Skip to content

Commit

Permalink
chore: 코드 컨벤션
Browse files Browse the repository at this point in the history
  • Loading branch information
dooboocookie committed Sep 28, 2023
1 parent 994cf36 commit cc88421
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/src/main/java/com/techcourse/dao/UserDao.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.techcourse.dao;

import com.techcourse.domain.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import javax.sql.DataSource;
Expand All @@ -28,11 +28,14 @@ public UserDao(final DataSource dataSource) {
}

public void insert(final User user) {
final var sql = "insert into users (account, password, email) values (?, ?, ?)";
final String sql = "insert into users (account, password, email) values (?, ?, ?)";

final String account = user.getAccount();
final String password = user.getPassword();
final String email = user.getEmail();

log.debug("sql={}", sql);

jdbcTemplate.update(sql, account, password, email);
}

Expand All @@ -43,24 +46,34 @@ public void update(final User user) {
final String password = user.getPassword();
final String email = user.getEmail();
final Long id = user.getId();

log.debug("sql={}", sql);

jdbcTemplate.update(sql, account, password, email, id);
}

public List<User> findAll() {
final String sql = "SELECT id, account, password, email FROM users";

log.debug("sql={}", sql);

return jdbcTemplate.query(sql, rowMapper);
}

public User findById(final Long id) {
final var sql = "select id, account, password, email from users where id = ?";
final String sql = "select id, account, password, email from users where id = ?";

log.debug("sql={}", sql);

Optional<User> user = jdbcTemplate.querySingleRow(sql, rowMapper, id);

return user.orElseThrow(() -> new IllegalArgumentException("해당 아이디로 조회되는 유저가 없습니다."));
}

public User findByAccount(final String account) {
final var sql = "select id, account, password, email from users where account = ?";
final String sql = "select id, account, password, email from users where account = ?";

log.debug("sql={}", sql);

Optional<User> user = jdbcTemplate.querySingleRow(sql, rowMapper, account);

Expand Down

0 comments on commit cc88421

Please sign in to comment.