|
@@ -0,0 +1,59 @@
|
|
|
+package com.superb.deliveryapi.dao;
|
|
|
+
|
|
|
+import com.superb.deliveryapi.domain.Point;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.stereotype.Repository;
|
|
|
+
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Repository
|
|
|
+public class PointDAOImpl implements PointDAO {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ private static final String INSERT_SQL = "INSERT INTO point (user_id, point, point_time, point_status, point_change) VALUES (?, ?, ?, ?, ?)";
|
|
|
+ private static final String SELECT_ALL_SQL = "SELECT * FROM point";
|
|
|
+ private static final String SELECT_BY_ID_SQL = "SELECT * FROM point WHERE point_id = ?";
|
|
|
+ private static final String UPDATE_SQL = "UPDATE point SET user_id = ?, point = ?, point_time = ?, point_status = ?, point_change = ? WHERE point_id = ?";
|
|
|
+ private static final String DELETE_SQL = "DELETE FROM point WHERE point_id = ?";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addPoint(Point point) {
|
|
|
+ jdbcTemplate.update(INSERT_SQL, point.getUserId(), point.getPoint(), point.getPointTime(), point.getPointStatus(), point.getPointChange());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Point> getAllPoints() {
|
|
|
+ return jdbcTemplate.query(SELECT_ALL_SQL, this::mapRowTo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Point getPointById(int pointId) {
|
|
|
+ return jdbcTemplate.queryForObject(SELECT_BY_ID_SQL, this::mapRowTo, pointId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updatePoint(Point point) {
|
|
|
+ jdbcTemplate.update(UPDATE_SQL, point.getUserId(), point.getPoint(), point.getPointTime(), point.getPointStatus(), point.getPointChange(), point.getPointId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deletePoint(int pointId) {
|
|
|
+ jdbcTemplate.update(DELETE_SQL, pointId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Point mapRowTo(ResultSet rs, int rowNum) throws SQLException {
|
|
|
+ Point point = new Point();
|
|
|
+ point.setPointId(rs.getInt("point_id"));
|
|
|
+ point.setUserId(rs.getInt("user_id"));
|
|
|
+ point.setPoint(rs.getInt("point"));
|
|
|
+ point.setPointTime(rs.getTimestamp("point_time").toLocalDateTime());
|
|
|
+ point.setPointStatus(rs.getString("point_status"));
|
|
|
+ point.setPointChange(rs.getInt("point_change"));
|
|
|
+ return point;
|
|
|
+ }
|
|
|
+}
|