Skip to content
Open

hw8 #11

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
8896a40
Update .gitignore
Ray-Not May 9, 2023
1ac5199
Add hw8
Ray-Not May 15, 2023
522ae1e
Rework
Ray-Not May 15, 2023
b85b201
Перенес с 8 практики
Ray-Not May 19, 2023
2ee103a
Workflows привет
Ray-Not May 19, 2023
cc8a642
Удаление левого теста, проверка workflows
Ray-Not May 19, 2023
fe33f8a
Исправлены пути
Ray-Not May 19, 2023
b20a4d8
Перенос workflows
Ray-Not May 19, 2023
bf15ea7
Удаление старого workflows
Ray-Not May 19, 2023
ab3cbb2
Замена версии???
Ray-Not May 19, 2023
69d7e32
Перенос workflows
Ray-Not May 19, 2023
2aa74c9
Изменение workflows
Ray-Not May 19, 2023
da303ec
Секрет
Ray-Not May 19, 2023
fac3782
Изменение в workflows
Ray-Not May 19, 2023
5b9aa50
Добавление workflows scrapper
Ray-Not May 19, 2023
9ce9809
Убраны лишние импорты
Ray-Not May 19, 2023
c5b88b5
Проблема с package bot не решена
Ray-Not May 19, 2023
739b32f
Попытка поставить CI
Ray-Not May 19, 2023
702aa97
Попытка поставить CI2
Ray-Not May 19, 2023
54d943b
Попытка поставить CI3
Ray-Not May 19, 2023
5c63d1b
Попытка поставить CI4
Ray-Not May 19, 2023
13e91a0
Попытка поставить CI5
Ray-Not May 19, 2023
d04960e
Попытка поставить CI6
Ray-Not May 19, 2023
a5762ce
Попытка поставить CI7
Ray-Not May 19, 2023
5788ba9
Попытка поставить CI8
Ray-Not May 19, 2023
850428d
Попытка поставить CI9
Ray-Not May 19, 2023
e40db0d
Попытка 10
Ray-Not May 19, 2023
4ae09b0
Попытка 11
Ray-Not May 19, 2023
d9d08aa
Попытка 11
Ray-Not May 19, 2023
8d9f251
Попытка 12
Ray-Not May 19, 2023
c4dd3bc
Попытка 13
Ray-Not May 19, 2023
520022e
Попытка 14
Ray-Not May 19, 2023
3a6bdd6
Попытка 15
Ray-Not May 19, 2023
dcc947f
Попытка 16
Ray-Not May 19, 2023
e58a31c
Попытка 17
Ray-Not May 19, 2023
f24afe0
Попытка 18
Ray-Not May 19, 2023
2a2c1cd
Попытка 19
Ray-Not May 19, 2023
6c1901e
Попытка 20
Ray-Not May 19, 2023
2ebb200
Попытка 21
Ray-Not May 19, 2023
6d09d45
Запуск контейнера
Ray-Not May 19, 2023
9b3bc28
Запуск контейнера
Ray-Not May 19, 2023
2442f91
Запуск контейнера
Ray-Not May 19, 2023
d8ce43d
Запуск контейнера
Ray-Not May 19, 2023
a22009a
Запуск контейнера
Ray-Not May 19, 2023
6c19564
Откат помника
Ray-Not May 19, 2023
5dcf5c0
Git publisher
Ray-Not May 19, 2023
40c79c4
Git publisher
Ray-Not May 19, 2023
3f82eff
Git publisher
Ray-Not May 19, 2023
9964605
Git publisher
Ray-Not May 20, 2023
6bbc8fb
Git publisher
Ray-Not May 20, 2023
1106798
Git publisher
Ray-Not May 20, 2023
037b81a
Git publisher
Ray-Not May 20, 2023
5d1d684
Git publisher
Ray-Not May 20, 2023
9cecb09
Git publisher
Ray-Not May 20, 2023
56a5971
Git publisher
Ray-Not May 20, 2023
6714c61
Git publisher
Ray-Not May 20, 2023
efd38ae
Git publisher
Ray-Not May 20, 2023
6a2eca1
Добавление 2 конфигов и checkstyle
Ray-Not May 20, 2023
cacba8b
Добавление 2 конфигов и checkstyle
Ray-Not May 20, 2023
d030c2b
Изменения в pom link парсера
Ray-Not May 20, 2023
ec00007
Изменения конфигурация editor и checkstyle
Ray-Not May 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/scrapper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Scrapper Build

on:
push:
paths:
- 'FP/scrapper/**'
- 'FP/pom.xml'
pull_request:
paths:
- 'FP/scrapper/**'
- '.github/workflows/scrapper.yml'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 20
uses: actions/setup-java@v3
with:
java-version: '20'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: cd FP && mvn package -pl scrapper -am

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build scrapper Docker image
run: cd FP && docker build -f scrapper.Dockerfile -t ghcr.io/ray-not/javaguava/scrapper:latest .

- name: Push Docker image to GitHub Container Registry
run: docker push ghcr.io/ray-not/javaguava/scrapper:latest
checkstyle:

runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 20
uses: actions/setup-java@v3
with:
java-version: '20'
distribution: 'temurin'

- name: Format code
run: cd FP && mvn -pl scrapper -am checkstyle:check
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Compiled class file
*.class


# Log file
*.log

Expand All @@ -23,4 +24,8 @@
hs_err_pid*

# idea
.idea
FP/.idea/

# volumes
FP/migrations/postgres_data/
FP/rabbitmq/
11 changes: 11 additions & 0 deletions FP/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.java]
indent_style = space
indent_size = 4
4 changes: 4 additions & 0 deletions FP/bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:20
WORKDIR /app/bot
COPY target/bot-1.0.jar bot.jar
CMD ["java", "-jar", "bot.jar"]
135 changes: 135 additions & 0 deletions FP/bot/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.example</groupId>
<artifactId>FP</artifactId>
<version>1.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>bot</artifactId>

<properties>
<starter-validation.version>3.0.1</starter-validation.version>
<starter-web.version>2.7.6</starter-web.version>
</properties>

<dependencies>
<!--Swagger UI-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
<!--Swagger UI-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${starter-validation.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${starter-web.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--Для бота-->
<dependency>
<groupId>com.github.pengrad</groupId>
<artifactId>java-telegram-bot-api</artifactId>
<version>6.6.0</version>
</dependency>
<!--Для бота-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</dependency>
<!--RabbitMQ-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>3.0.6</version>
</dependency>
<!-- Database -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>scrapper</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
26 changes: 26 additions & 0 deletions FP/bot/src/main/java/ru/tinkoff/edu/java/bot/BotApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.tinkoff.edu.java.bot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.jdbc.core.JdbcTemplate;
import ru.tinkoff.edu.java.bot.configuration.records.ApplicationConfig;
import ru.tinkoff.edu.java.bot.handler.BotMain;

import javax.sql.DataSource;


@SpringBootApplication
@EnableConfigurationProperties(ApplicationConfig.class)
public class BotApplication
{
public static void main(String[] args){
var ctx = SpringApplication.run(BotApplication.class, args);
ApplicationConfig config = ctx.getBean(ApplicationConfig.class);
JdbcTemplate jdbcTemplate = (JdbcTemplate) ctx.getBean("jdbcTemplate");
BotMain bot = new BotMain(config.bot().token(), jdbcTemplate);
bot.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.tinkoff.edu.java.bot.api;

import org.springframework.web.bind.annotation.*;
import ru.tinkoff.edu.java.bot.model.LinkUpdate;

@RestController
@RequestMapping("/update")
public class BotController {

@PostMapping
public String updateChat(@RequestBody LinkUpdate update) {
return update.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.tinkoff.edu.java.bot.api.exceptionHandler;

import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import ru.tinkoff.edu.java.bot.model.ApiErrorResponse;

@RestControllerAdvice
public class BotExceptionHandler {

private String getDescription(String message) {
ApiErrorResponse errorObj = new ApiErrorResponse(
message,
null,
null,
null,
null
);
return errorObj.description();
}

@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public String MessageNotReadable(HttpMessageNotReadableException Exception) {
return getDescription("Некорректные значения параметров или их нет!");
}

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public String MethodNotSupported(HttpRequestMethodNotSupportedException Exception) {
return getDescription("Метод не разрешен!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.tinkoff.edu.java.bot.configuration;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ru.tinkoff.edu.java.bot.configuration.records.ApplicationConfig;

import java.util.Collections;

@Configuration
public class RabbitMQConfiguration {

private final ApplicationConfig config;

public RabbitMQConfiguration(ApplicationConfig config) {
this.config = config;
}

@Bean
public DirectExchange exchange() {
return new DirectExchange(config.exchange());
}

@Bean
public Queue queue() {
return QueueBuilder.durable(config.queue())
.withArgument("x-dead-letter-exchange",config.queue() + ".dlq")
.build();
}

@Bean
public Binding binding(Queue queue, DirectExchange exchange) {
return BindingBuilder.bind(queue)
.to(exchange)
.with(config.routingKey());
}

@Bean
public DirectExchange dlqExchange() {
return new DirectExchange(config.exchange() + ".dlq");
}

@Bean
public Queue dlqQueue() {
return QueueBuilder.durable(config.queue() + ".dlq").build();
}

@Bean
public Binding dlqBinding() {
return BindingBuilder.bind(dlqQueue())
.to(dlqExchange())
.with(config.routingKey());
}
}
Loading