Skip to content

Commit 25e0a00

Browse files
Fix: After the first review
1 parent f597f45 commit 25e0a00

11 files changed

Lines changed: 34 additions & 28 deletions

File tree

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.PHONY: build
21
.DEFAULT_GOAL := build-run
32

43
clean:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Hexlet tests and linter status:
22
[![Actions Status](https://github.com/VictorGotsenko/java-project-72/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/VictorGotsenko/java-project-72/actions)
33
[![Page Validator](https://github.com/VictorGotsenko/java-project-72/actions/workflows/JavaCI.yml/badge.svg)](https://github.com/VictorGotsenko/java-project-72/actions/workflows/JavaCI.yml)
4+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=VictorGotsenko_java-project-72&metric=coverage)](https://sonarcloud.io/summary/new_code?id=VictorGotsenko_java-project-72)
45
## Description
56
#### Application for analyzing links for SEO suitability, is enable on <a href="https://pagesanalyzer.onrender.com" target="_blank">Link Page Analyzer</a>
67
Приложение – сайт, который анализирует указанные страницы на SEO пригодность.

app/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.PHONY: build
21
.DEFAULT_GOAL := build-run
32

43
clean:

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
22
import org.gradle.api.tasks.testing.logging.TestLogEvent
33

44
plugins {
5-
id("java")
65
application
76
checkstyle
87
jacoco

app/src/main/java/hexlet/code/controller/UrlCheckController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public static void check(Context ctx) throws SQLException {
4848
String title = document.title();
4949
String h1 = document.select("h1").text();
5050
String description = document.select("meta[name=description]").attr("content");
51-
LocalDateTime createdAt = LocalDateTime.now();
5251

53-
UrlCheck urlCheck = new UrlCheck(statusCode, title, h1, description, urlId, createdAt);
52+
UrlCheck urlCheck = new UrlCheck(statusCode, title, h1, description, urlId);
53+
urlCheck.setCreatedAt(LocalDateTime.now());
5454
log.info("urlCheck created");
5555
UrlCheckRepository.save(urlCheck);
5656
log.info("check saved");

app/src/main/java/hexlet/code/controller/UrlController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public static void create(Context ctx) throws SQLException, URISyntaxException,
7676
URL url = new URIBuilder().setScheme(protocol).setHost(host).setPort(port).build().toURL();
7777

7878
if (UrlRepository.findByName(String.valueOf(url)).isEmpty()) {
79-
Url newUrl = new Url(String.valueOf(url), LocalDateTime.now());
79+
Url newUrl = new Url(String.valueOf(url));
80+
newUrl.setCreatedAt(LocalDateTime.now());
8081
UrlRepository.save(newUrl);
8182
} else {
8283
ctx.sessionAttribute(FLASH, PAGE_EXIST);
@@ -92,7 +93,7 @@ public static void create(Context ctx) throws SQLException, URISyntaxException,
9293

9394
public static void index(Context ctx) throws SQLException {
9495
List<Url> urls = UrlRepository.getEntities();
95-
Map<Long, UrlCheck> latestChecks = UrlCheckRepository.getLastestChecks();
96+
Map<Long, UrlCheck> latestChecks = UrlCheckRepository.getLatestChecks();
9697

9798
UrlsPage page = new UrlsPage(urls, latestChecks);
9899
page.setFlash(ctx.consumeSessionAttribute(FLASH));

app/src/main/java/hexlet/code/model/Url.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ public class Url {
1717
private LocalDateTime createdAt;
1818
private List<UrlCheck> urlCheckList;
1919

20-
public Url(String name, LocalDateTime createdAt) {
20+
public Url(String name) {
2121
this.name = name;
22-
this.createdAt = createdAt;
2322
this.urlCheckList = new ArrayList<>();
2423
}
2524
}

app/src/main/java/hexlet/code/model/UrlCheck.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ public class UrlCheck {
1616
private Long urlId;
1717
private LocalDateTime createdAt;
1818

19-
public UrlCheck(int statusCode, String title, String h1, String description, Long urlId, LocalDateTime createdAt) {
19+
public UrlCheck(int statusCode, String title, String h1, String description, Long urlId) {
2020
this.urlId = urlId;
2121
this.title = title;
2222
this.h1 = h1;
2323
this.description = description;
2424
this.statusCode = statusCode;
25-
this.createdAt = createdAt;
2625
}
2726
}

app/src/main/java/hexlet/code/repository/UrlCheckRepository.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public static List<UrlCheck> findById(Long urlId) throws SQLException {
6060
resultSet.getString("title"),
6161
resultSet.getString("h1"),
6262
resultSet.getString("description"),
63-
urlId,
64-
resultSet.getTimestamp("created_at").toLocalDateTime());
63+
urlId);
64+
urlCheck.setCreatedAt(resultSet.getTimestamp("created_at").toLocalDateTime());
6565
urlCheck.setId(resultSet.getLong("id"));
6666
result.add(urlCheck);
6767
}
@@ -72,7 +72,7 @@ public static List<UrlCheck> findById(Long urlId) throws SQLException {
7272
return result;
7373
}
7474

75-
public static Map<Long, UrlCheck> getLastestChecks() throws SQLException {
75+
public static Map<Long, UrlCheck> getLatestChecks() throws SQLException {
7676
Map<Long, UrlCheck> result = new HashMap<>();
7777
String sql = "SELECT DISTINCT ON (url_id) * from url_checks order by url_id DESC, id DESC";
7878
try (Connection conn = BaseRepository.getDataSource().getConnection();
@@ -84,13 +84,13 @@ public static Map<Long, UrlCheck> getLastestChecks() throws SQLException {
8484
resultSet.getString("title"),
8585
resultSet.getString("h1"),
8686
resultSet.getString("description"),
87-
resultSet.getLong("url_id"),
88-
resultSet.getTimestamp("created_at").toLocalDateTime());
87+
resultSet.getLong("url_id"));
88+
urlCheck.setCreatedAt(resultSet.getTimestamp("created_at").toLocalDateTime());
8989
urlCheck.setId(resultSet.getLong("id"));
9090
result.put(resultSet.getLong("url_id"), urlCheck);
9191
}
9292
} catch (SQLException e) {
93-
log.info("Error in UrlCheckRepository.getLastestChecks ", e);
93+
log.info("Error in UrlCheckRepository.getLatestChecks ", e);
9494
e.printStackTrace();
9595
}
9696
return result;

app/src/main/java/hexlet/code/repository/UrlRepository.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ public static Optional<Url> find(Long id) throws SQLException {
4343
preparedStatement.setLong(1, id);
4444
ResultSet resultSet = preparedStatement.executeQuery();
4545
if (resultSet.next()) {
46-
Url url = new Url(
47-
resultSet.getString("name"),
48-
resultSet.getTimestamp(FIELD_CREATED_AT).toLocalDateTime());
46+
Url url = new Url(resultSet.getString("name"));
47+
url.setCreatedAt(resultSet.getTimestamp(FIELD_CREATED_AT).toLocalDateTime());
4948
url.setId(id);
5049
return Optional.of(url);
5150
}
@@ -60,9 +59,8 @@ public static Optional<Url> findByName(String name) throws SQLException {
6059
preparedStatement.setString(1, name);
6160
ResultSet resultSet = preparedStatement.executeQuery();
6261
if (resultSet.next()) {
63-
Url url = new Url(
64-
name,
65-
resultSet.getTimestamp(FIELD_CREATED_AT).toLocalDateTime());
62+
Url url = new Url(resultSet.getString("name"));
63+
url.setCreatedAt(resultSet.getTimestamp(FIELD_CREATED_AT).toLocalDateTime());
6664
url.setId(resultSet.getLong("id"));
6765
return Optional.of(url);
6866
}
@@ -78,9 +76,8 @@ public static List<Url> getEntities() throws SQLException {
7876
ResultSet resultSet = preparedStatement.executeQuery();
7977
List<Url> result = new ArrayList<>();
8078
while (resultSet.next()) {
81-
Url url = new Url(
82-
resultSet.getString("name"),
83-
resultSet.getTimestamp(FIELD_CREATED_AT).toLocalDateTime());
79+
Url url = new Url(resultSet.getString("name"));
80+
url.setCreatedAt(resultSet.getTimestamp(FIELD_CREATED_AT).toLocalDateTime());
8481
url.setId(resultSet.getLong("id"));
8582
result.add(url);
8683
}

0 commit comments

Comments
 (0)