Skip to content

Commit

Permalink
move init the createdAt from the UrlCheckController to UrlCheckReposi…
Browse files Browse the repository at this point in the history
…tory
  • Loading branch information
kitdim committed Feb 7, 2024
1 parent 8a3cbf7 commit 06c34d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.jsoup.nodes.Document;

import java.sql.SQLException;
import java.sql.Timestamp;

public class UrlCheckController {
private static final String INCORRECT_URL = "Incorrect URL";
Expand All @@ -35,14 +34,11 @@ public static void createCheck(Context ctx) throws SQLException {
var descriptionTemp = doc.selectFirst("meta[name=description]");
var description = descriptionTemp == null ? "" : descriptionTemp.attr("content");

var createdAt = new Timestamp(System.currentTimeMillis());

var urlCheck = UrlCheck.builder()
.statusCode(statusCode)
.title(title)
.h1(h1)
.urlId(urlId)
.createdAt(createdAt)
.description(description)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -14,14 +15,15 @@ public class UrlsCheckRepository {
public static void save(UrlCheck urlCheck) throws SQLException {
String sql = "INSERT INTO url_checks (url_id, status_code, h1, title, description, created_at) "
+ "VALUES (?, ?, ?, ?, ?, ?)";
var createdAt = new Timestamp(System.currentTimeMillis());
try (var conn = dataSource.getConnection();
var stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
stmt.setLong(1, urlCheck.getUrlId());
stmt.setInt(2, urlCheck.getStatusCode());
stmt.setString(3, urlCheck.getH1());
stmt.setString(4, urlCheck.getTitle());
stmt.setString(5, urlCheck.getDescription());
stmt.setTimestamp(6, urlCheck.getCreatedAt());
stmt.setTimestamp(6, createdAt);
stmt.executeUpdate();

var generatedKeys = stmt.getGeneratedKeys();
Expand Down

0 comments on commit 06c34d4

Please sign in to comment.