Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homework-5 (with bonus) #5

Merged
merged 156 commits into from
May 4, 2024
Merged

homework-5 (with bonus) #5

merged 156 commits into from
May 4, 2024

Conversation

Efler
Copy link
Owner

@Efler Efler commented Mar 17, 2024

Бот отслеживает следующие сценарии:

Github:

  • обновление метаданных/настроек репозитория
  • новый пуш в репозитории
  • новая ветка в репозитории
  • удаление ветки в репозитории

Stackoverflow:

  • Новый ответ на вопрос
  • Новый комментарий к вопросу/ответу
  • Ответ был принят автором вопроса
  • Состояние вопроса было изменено

@Efler Efler self-assigned this Mar 17, 2024
@Efler
Copy link
Owner Author

Efler commented Mar 17, 2024

Code Coverage

Overall Project 41.78% -52.51% 🍏
Files changed 42.08% 🍏

File Coverage
LinkUpdateScheduler.java 100% 🍏
ChatDao.java 100% 🍏
TrackingDao.java 100% 🍏
JpaLinkService.java 100% 🍏
StackoverflowClient.java 94.7% -5.3% 🍏
LinkDao.java 91.54% -8.46% 🍏
JpaTgChatService.java 83.48% -16.52% 🍏
BranchDao.java 83.26% -16.74% 🍏
GithubClient.java 75.12% -24.88% 🍏
JpaLinkUpdateService.java 58.76% -41.24% 🍏
ScrapperApplication.java 37.5% 🍏
TgChatController.java 27.27% -72.73%
BotClient.java 19.09% -54.55%
SecurityService.java 16.67% -83.33%
LinksController.java 5.83% -80.58%
RestExceptionHandler.java 1.35% 🍏
ScrapperQueueProducer.java 0%
JdbcLinkService.java 0%
JdbcLinkUpdateService.java 0%
JdbcTgChatService.java 0%
JooqTgChatService.java 0%
JooqLinkUpdateService.java 0%
JooqLinkService.java 0%

public final class TimeConstants {

public final static OffsetDateTime MIN_DATE_TIME =
OffsetDateTime.parse("0001-01-01T00:00:00Z");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OffsetDateTime.now()?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Подправил на OffsetDateTime.now()

Comment on lines 15 to 89
public class BranchDao {

private final JdbcTemplate jdbcTemplate;

@Transactional
public boolean exists(Branch branch) {
String countSql = """
SELECT COUNT(*) AS row_count\s
FROM "Branch"\s
WHERE repository_owner = ? AND repository_name = ? AND branch_name = ?
""";
var rowCount = jdbcTemplate.queryForObject(
countSql,
Integer.class,
branch.getRepositoryOwner(),
branch.getRepositoryName(),
branch.getBranchName()
);
return rowCount != null && rowCount == 1;
}

@Transactional
public void add(Branch branch) {
String sql = """
INSERT INTO "Branch" (repository_owner, repository_name, branch_name, last_commit_time)\s
VALUES (?, ?, ?, ?)
""";
jdbcTemplate.update(
sql,
branch.getRepositoryOwner(),
branch.getRepositoryName(),
branch.getBranchName(),
branch.getLastCommitTime()
);
}

@Transactional
public void delete(Branch branch) {
if (!exists(branch)) {
throw new InvalidDataAccessResourceUsageException("Branch not found!");
}

String sql = """
DELETE FROM "Branch"\s
WHERE repository_owner = ? AND repository_name = ? AND branch_name = ?
""";
jdbcTemplate.update(
sql,
branch.getRepositoryOwner(),
branch.getRepositoryName(),
branch.getBranchName()
);
}

@Transactional
public List<Branch> findAll() {
String sql = "SELECT * FROM \"Branch\"";
return jdbcTemplate.query(sql, (rs, rowNum) ->
new Branch(
rs.getLong("id"),
rs.getString("repository_owner"),
rs.getString("repository_name"),
rs.getString("branch_name"),
rs.getObject("last_commit_time", OffsetDateTime.class)
)
);
}

@Transactional
public List<Branch> findAllByOwnerAndName(String owner, String name) {
String sql = "SELECT * FROM \"Branch\" WHERE repository_owner = ? AND repository_name = ?";
return jdbcTemplate.query(sql, (rs, rowNum) ->
new Branch(
rs.getLong("id"),
rs.getString("repository_owner"),
rs.getString("repository_name"),
rs.getString("branch_name"),
rs.getObject("last_commit_time", OffsetDateTime.class)
), owner, name
);
}
Copy link
Collaborator

@Betorov Betorov Apr 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BranchDao?

В задании 5-ом хотели реализовать через интерфейс, BranchDao, JdbcBranchDao, JooqBranchDao и т.д..

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обговорили в телеграме

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jooq, Предлагаю создать отдельный модуль где будет лежать вся модель. ? Почему, потому что ее часто приходится перегенирировать. И будет аккуратнее выглядеть

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделано!

Comment on lines 19 to 32
@Transactional
public boolean exists(Branch branch) {
String countSql = """
SELECT COUNT(*) AS row_count\s
FROM "Branch"\s
WHERE repository_owner = ? AND repository_name = ? AND branch_name = ?
""";
var rowCount = jdbcTemplate.queryForObject(
countSql,
Integer.class,
branch.getRepositoryOwner(),
branch.getRepositoryName(),
branch.getBranchName()
);
return rowCount != null && rowCount == 1;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У всех какая-то общая проблема. Создают транзакцию избыточно.
На селекте то она зачем?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Подправил

);
}

@Transactional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В одной бизнес-логике используется несколько транзакций, точно он так нужно? Может мы должны удалить в одном месте и в другом сразу?
Транзакция выглядит избыточной.

Обычно ее вставляют когда в бизнес-логике идет работа с БД (а тут с несколькими таблицами сразу)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

@Efler
Copy link
Owner Author

Efler commented Apr 12, 2024

Здравствуйте! Если что, отписал в телеграм по поводу правок

@Efler Efler merged commit a005e40 into homework-4 May 4, 2024
6 checks passed
@Efler Efler deleted the homework-5-with-bonus branch May 4, 2024 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants