Skip to content

Commit

Permalink
[BE/#56] Feat : 마일스톤 DAO 쿼리 추가
Browse files Browse the repository at this point in the history
- NamedParameterJdbcTemplate으로 구현
- updateDateTime을 갱신하도록 구현
  • Loading branch information
MuseopKim committed Jun 18, 2020
1 parent 59ed010 commit 80be55c
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.codesquad.issuetracker.ragdoll.domain.Milestone;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
Expand All @@ -15,8 +18,11 @@ public class MilestoneDao_Ragdoll {

private final JdbcTemplate jdbcTemplate;

private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;

public MilestoneDao_Ragdoll(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

public Milestone findMilestoneById(Integer milestoneId) {
Expand Down Expand Up @@ -57,4 +63,16 @@ public void createNewMilestone(String title, LocalDate dueDate, String descripti
"VALUES (?, ?, ?, ?, ?)";
jdbcTemplate.update(sql, new Object[]{title, description, dueDate, LocalDateTime.now(), LocalDateTime.now()});
}

public void updateMilestone(Integer milestoneId, String title, LocalDate dueDate, String description) {
SqlParameterSource namedParameters = new MapSqlParameterSource()
.addValue("milestoneId", milestoneId)
.addValue("title", title)
.addValue("dueDate", dueDate)
.addValue("description", description)
.addValue("updatedDateTime", LocalDateTime.now());
String sql = "UPDATE milestone SET title = :title, due_date = :dueDate, description = :description, updated_date_time = :updatedDateTime " +
"WHERE id = :milestoneId";
namedParameterJdbcTemplate.update(sql, namedParameters);
}
}

0 comments on commit 80be55c

Please sign in to comment.