-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
211 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
app/src/main/java/hexlet/code/controller/RootController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
app/src/main/java/hexlet/code/controller/UrlController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
//} |
10 changes: 9 additions & 1 deletion
10
app/src/main/java/hexlet/code/repository/UrlsCheckRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.