From 21e6cfa18b6a31c9f0bdcdd63512f56e6a5d3dc8 Mon Sep 17 00:00:00 2001 From: ragdoll Date: Fri, 12 Jun 2020 12:27:21 +0900 Subject: [PATCH] =?UTF-8?q?[BE/#17]=20Feat=20:=20MilestoneDao=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=84=A4=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SQL을 최대한 작은 단위로 활용 --- .../ragdoll/dao/MilestoneDao.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 BE/src/main/java/com/codesquad/issuetracker/ragdoll/dao/MilestoneDao.java diff --git a/BE/src/main/java/com/codesquad/issuetracker/ragdoll/dao/MilestoneDao.java b/BE/src/main/java/com/codesquad/issuetracker/ragdoll/dao/MilestoneDao.java new file mode 100644 index 0000000..0e2e748 --- /dev/null +++ b/BE/src/main/java/com/codesquad/issuetracker/ragdoll/dao/MilestoneDao.java @@ -0,0 +1,46 @@ +package com.codesquad.issuetracker.ragdoll.dao; + +import com.codesquad.issuetracker.ragdoll.domain.Milestone; +import com.codesquad.issuetracker.ragdoll.dto.milestoneVO.MilestoneSummary; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.util.List; +import java.util.Set; + +@Repository +public class MilestoneDao { + + private JdbcTemplate jdbcTemplate; + + public MilestoneDao(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + public Milestone findMilestoneById(Integer milestoneId) { + String sql = "SELECT id, title, description, due_date, created_date_time, updated_date_time " + + "FROM milestone WHERE id = ?"; + return jdbcTemplate.queryForObject(sql, new Object[]{milestoneId}, + (rs, rowNum) -> new Milestone.Builder() + .id(rs.getInt("id")) + .title(rs.getString("title")) + .description(rs.getString("description")) + .dueDate(rs.getDate("due_date").toLocalDate()) + .createdDateTime(rs.getTimestamp("created_date_time").toLocalDateTime()) + .updatedDateTime(rs.getTimestamp("updated_date_time").toLocalDateTime()) + .build()); + } + + public List findAllMilestones() { + String sql = "SELECT id, title, description, due_date, created_date_time, updated_date_time " + + "FROM milestone"; + return jdbcTemplate.query(sql, (rs, rowNum) -> new Milestone.Builder() + .id(rs.getInt("id")) + .title(rs.getString("title")) + .dueDate(rs.getDate("due_date").toLocalDate()) + .createdDateTime(rs.getTimestamp("created_date_time").toLocalDateTime()) + .updatedDateTime(rs.getTimestamp("updated_date_time").toLocalDateTime()) + .build()); + } +}