Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
kitdim committed Apr 21, 2024
1 parent 1e6e99d commit 565552a
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 294 deletions.
62 changes: 34 additions & 28 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,40 @@ application {
}

dependencies {

testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.assertj:assertj-core:3.24.2'

implementation("io.javalin:javalin:5.6.3")
implementation("org.slf4j:slf4j-simple:2.0.9")
implementation("io.javalin:javalin-bundle:5.6.2")
implementation("io.javalin:javalin-rendering:5.6.2")
implementation("gg.jte:jte:3.1.2")

implementation("com.h2database:h2:2.2.224")
implementation("com.zaxxer:HikariCP:5.0.1")

compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'

testCompileOnly 'org.projectlombok:lombok:1.18.30'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'

implementation("com.fasterxml.jackson.core:jackson-databind:2.15.0")

implementation("org.postgresql:postgresql:42.6.0")

implementation("com.konghq:unirest-java:3.14.5")
implementation("org.jsoup:jsoup:1.16.1")

testImplementation("com.squareup.okhttp3:mockwebserver:4.11.0")
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
developmentOnly("org.springframework.boot:spring-boot-devtools")

implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
implementation("org.springframework.boot:spring-boot-starter-validation")
//
// implementation("org.springframework.boot:spring-boot-starter-security")
// implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")

compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

implementation("org.mapstruct:mapstruct:1.5.5.Final")
annotationProcessor("org.mapstruct:mapstruct-processor:1.5.5.Final")

implementation("org.openapitools:jackson-databind-nullable:0.2.6")

runtimeOnly("com.h2database:h2")
runtimeOnly("org.postgresql:postgresql")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc")
// testImplementation("org.springframework.security:spring-security-test")
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
testImplementation("net.javacrumbs.json-unit:json-unit-assertj:3.2.2")
implementation("net.datafaker:datafaker:2.0.1")
implementation("org.instancio:instancio-junit:3.3.0")

implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0")
}

test {
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/hexlet/code/App.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package hexlet.code;

public final class App {
public static void main(String[] args) {
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}

}
20 changes: 10 additions & 10 deletions app/src/main/java/hexlet/code/controller/RootController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package hexlet.code.controller;

import hexlet.code.dto.BasePage;
import io.javalin.http.Context;
import io.javalin.http.HttpStatus;

import java.util.Collections;

public final class RootController {
}
//package hexlet.code.controller;
//
//import hexlet.code.dto.BasePage;
//import io.javalin.http.Context;
//import io.javalin.http.HttpStatus;
//
//import java.util.Collections;
//
//public final class RootController {
//}
30 changes: 30 additions & 0 deletions app/src/main/java/hexlet/code/controller/UrlController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
package hexlet.code.controller;

import hexlet.code.model.Url;
import hexlet.code.service.UrlService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class UrlController {
private final UrlService urlService;

@GetMapping(path = "/urls")
public ResponseEntity<List<Url>> getAll() {
List<Url> urls = urlService.getAll();
return ResponseEntity.ok()
.header("X-Total-Count", String.valueOf(urls.size()))
.body(urls);
}
@PostMapping(path = "/urls")
@ResponseStatus(HttpStatus.CREATED)
public Url create(@RequestBody Url url) {
return urlService.save(url);
}
}
37 changes: 18 additions & 19 deletions app/src/main/java/hexlet/code/dto/UrlsPage.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package hexlet.code.dto;

import hexlet.code.model.UrlCheck;
import lombok.AllArgsConstructor;
import lombok.Getter;
import hexlet.code.model.Url;

import java.util.List;
import java.util.Map;

@Getter
@AllArgsConstructor
public class UrlsPage extends BasePage {
private List<Url> urls;
private Map<Long, UrlCheck> checks;
public UrlsPage(List<Url> urls) {
this.urls = urls;
}
}
//package hexlet.code.dto;
//
//import lombok.AllArgsConstructor;
//import lombok.Getter;
//import hexlet.code.model.Url;
//
//import java.util.List;
//import java.util.Map;
//
//@Getter
//@AllArgsConstructor
//public class UrlsPage extends BasePage {
// private List<Url> urls;
// private Map<Long, UrlCheck> checks;
// public UrlsPage(List<Url> urls) {
// this.urls = urls;
// }
//}
27 changes: 24 additions & 3 deletions app/src/main/java/hexlet/code/model/Url.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
package hexlet.code.model;

import lombok.Builder;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.sql.Timestamp;
import java.util.List;

import static jakarta.persistence.GenerationType.IDENTITY;

@Entity(name = "urls")
@EntityListeners(AuditingEntityListener.class)
@ToString(onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@Setter
@Getter
public final class Url {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;
@Column(unique = true)
@NotBlank(message = "url no be empty")
@ToString.Include
private String name;
@CreatedDate
private Timestamp createdAt;
private List<UrlCheck> urlChecks;
// @OneToMany(mappedBy = "url", cascade = CascadeType.ALL, orphanRemoval = true)
// private List<UrlCheck> urlChecks = new ArrayList<>();
}
57 changes: 28 additions & 29 deletions app/src/main/java/hexlet/code/model/UrlCheck.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package hexlet.code.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.sql.Timestamp;

@Setter
@Getter
@Builder
@AllArgsConstructor
public final class UrlCheck {
private Long id;
private Long urlId;
private int statusCode;
private String h1;
private String title;
private String description;
private Timestamp createdAt;

public UrlCheck(int statusCode, String title, String h1, String description) {
this.statusCode = statusCode;
this.title = title;
this.h1 = h1;
this.description = description;
}
}
//package hexlet.code.model;
//
//import jakarta.persistence.Entity;
//import jakarta.persistence.GeneratedValue;
//import jakarta.persistence.Id;
//import jakarta.persistence.ManyToOne;
//import jakarta.persistence.Table;
//import lombok.Getter;
//
//import java.sql.Timestamp;
//
//import static jakarta.persistence.GenerationType.IDENTITY;
//
//@Entity
//@Table(name = "urls-checks")
//@Getter
//public final class UrlCheck {
// @Id
// @GeneratedValue(strategy = IDENTITY)
// private Long id;
// @ManyToOne
// private Url url;
// private int statusCode;
// private String h1;
// private String title;
// private String description;
// private Timestamp createdAt;
//}
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
package hexlet.code.repository;
//package hexlet.code.repository;
//
//import hexlet.code.model.UrlCheck;
//import org.springframework.data.jpa.repository.JpaRepository;
//import org.springframework.stereotype.Repository;
//
//@Repository
//public interface UrlsCheckRepository extends JpaRepository<UrlCheck, Long> {
//}
8 changes: 8 additions & 0 deletions app/src/main/java/hexlet/code/repository/UrlsRepository.java
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
package hexlet.code.repository;

import hexlet.code.model.Url;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UrlsRepository extends JpaRepository<Url, Long> {
}
17 changes: 17 additions & 0 deletions app/src/main/java/hexlet/code/service/UrlService.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
package hexlet.code.service;

import hexlet.code.repository.UrlsRepository;
import hexlet.code.model.Url;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UrlService {
private final UrlsRepository urlsRepository;

public List<Url> getAll() {
return urlsRepository.findAll();
}
public Url save(Url data) {
return urlsRepository.save(data);
}
}
15 changes: 15 additions & 0 deletions app/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spring:
datasource:
username: SA
password: password
url: jdbc:h2:mem:spring
h2:
console:
enabled: true
path: /h2-console/
settings:
web-allow-others: true
logging:
level:
root: INFO
web: DEBUG
10 changes: 10 additions & 0 deletions app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
spring:
jpa:
show-sql: true
hibernate:
ddl-auto: create-drop
output:
ansi:
enabled: always
profiles:
active: ${APP_ENV:dev}
File renamed without changes.
32 changes: 0 additions & 32 deletions app/src/main/resources/templates/index.jte

This file was deleted.

Loading

0 comments on commit 565552a

Please sign in to comment.