Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Rewrote checking on existence of article title.
  • Loading branch information
JackKaif committed Feb 12, 2024
1 parent 9ab523b commit 2968ff0
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions java-web-ru/validation/src/main/java/exercise/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ public static Javalin getApp() {
app.post("/articles", ctx -> {
try {
var name = ctx.formParamAsClass("title", String.class)
.check(value -> {
var exists = ArticleRepository.getEntities().stream()
.map(Article::getTitle)
.filter(value::equals)
.findFirst()
.orElse(null);
return exists == null;
}, "Статья с таким названием уже существует")
.check(value -> !ArticleRepository.existsByTitle(value), "Статья с таким названием уже существует")
.check(value -> value.length() > 2, "Название не должно быть короче двух символов")
.get();
var content = ctx.formParamAsClass("content", String.class)
Expand Down

0 comments on commit 2968ff0

Please sign in to comment.