Skip to content

Commit

Permalink
[BE/#17] Feat : MilestoneDao 로직 설계
Browse files Browse the repository at this point in the history
- SQL을 최대한 작은 단위로 활용
  • Loading branch information
MuseopKim committed Jun 12, 2020
1 parent b740458 commit 21e6cfa
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Milestone> 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());
}
}

0 comments on commit 21e6cfa

Please sign in to comment.