Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 19 additions & 14 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
id("java")
id("application")
id("checkstyle")
id("jacoco")
application
checkstyle
jacoco

id("com.github.johnrengelman.shadow") version "8.1.1"

id("se.patrikerdes.use-latest-versions") version "0.2.18"
id("com.github.ben-manes.versions") version "0.51.0"
id("com.github.ben-manes.versions") version "0.52.0"

id("org.sonarqube") version "6.2.0.5505"
}
Expand All @@ -28,11 +28,10 @@ repositories {

dependencies {
// Javalin
implementation("io.javalin:javalin:6.5.0")
implementation("io.javalin:javalin-rendering:6.5.0")
implementation("org.slf4j:slf4j-simple:2.0.16")
implementation("gg.jte:jte:3.1.16")

implementation("io.javalin:javalin:6.7.0")
implementation("io.javalin:javalin-rendering:6.7.0")
implementation("org.slf4j:slf4j-simple:2.1.0-alpha1")
implementation("gg.jte:jte:3.2.1")

// LOMBOK
compileOnly("org.projectlombok:lombok:1.18.38")
Expand All @@ -41,17 +40,23 @@ dependencies {
testCompileOnly("org.projectlombok:lombok:1.18.38")
testAnnotationProcessor("org.projectlombok:lombok:1.18.38")

// CheckStyle
implementation("com.puppycrawl.tools:checkstyle:10.26.0")

// database H2 & HikariCP
implementation("com.h2database:h2:2.3.232")
implementation("com.zaxxer:HikariCP:6.3.0")

// CheckStyle
implementation("com.puppycrawl.tools:checkstyle:10.23.1")
// Tests
testImplementation("org.junit.jupiter:junit-jupiter:5.13.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.13.2")

testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
//testImplementation(platform("org.junit:junit-bom:5.13.2"))
//testImplementation("org.junit.jupiter:junit-jupiter")
}

checkstyle {
toolVersion = "10.23.1"
toolVersion = "10.26.0"
configFile = file("config/checkstyle/checkstyle.xml")
}

Expand Down
47 changes: 45 additions & 2 deletions app/src/main/java/hexlet/code/App.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
package hexlet.code;

import hexlet.code.repository.BaseRepository;
// import io.hexlet.component.DataInitializer;

import io.javalin.Javalin;
import io.javalin.rendering.template.JavalinJte;

import lombok.extern.slf4j.Slf4j;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.stream.Collectors;


@Slf4j
public class App {
public static Javalin getApp() { //throws SQLException


private static String getDatabaseUrl() {
// Получаю url базы данных из переменной окружения DATABASE_URL
// Если она не установлена, используем базу в памяти
return System.getenv().getOrDefault("JDBC_DATABASE_URL", "jdbc:h2:mem:project;DB_CLOSE_DELAY=-1;");
}


private static String readResourceFile(String fileName) throws IOException {
var inputStream = App.class.getClassLoader().getResourceAsStream(fileName);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
return reader.lines().collect(Collectors.joining("\n"));
}
}

public static Javalin getApp() throws IOException, SQLException { //
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(getDatabaseUrl());

HikariDataSource dataSource = new HikariDataSource(hikariConfig);
var sql = readResourceFile("schema.sql");

log.info(sql);
try (var connection = dataSource.getConnection();
var statement = connection.createStatement()) {
statement.execute(sql);
}
BaseRepository.dataSource = dataSource;


var app = Javalin.create(config -> {
config.bundledPlugins.enableDevLogging();
Expand All @@ -21,7 +63,8 @@ public static Javalin getApp() { //throws SQLException
return app;
}

public static void main(String[] args) { //throws SQLException

public static void main(String[] args) throws IOException, SQLException { //throws SQLException
Javalin app = getApp();
app.start(7070);
}
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/hexlet/code/model/Url.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hexlet.code.model;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.LocalDateTime;

@Getter
@Setter
@ToString
public class Url {
private Long id;
private String name;
private LocalDateTime createdAt;

public Url(String name, LocalDateTime createdAt) {
this.name = name;
this.createdAt = createdAt;
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/hexlet/code/repository/BaseRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hexlet.code.repository;

import com.zaxxer.hikari.HikariDataSource;

public class BaseRepository {
public static HikariDataSource dataSource;
}
7 changes: 7 additions & 0 deletions app/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DROP TABLE IF EXISTS urls;

CREATE TABLE urls (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP
);
Loading