-
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
19 changed files
with
750 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# WARNING: Paths must not include the name of the "lessons" directory. | ||
# Outside, this directory is called "exercises". | ||
|
||
**/*/presentation*.html | ||
.vagrant | ||
.idea/ | ||
node_modules/ | ||
vendor/ | ||
dist | ||
.gradle/ | ||
build/ | ||
caches/ | ||
.vscode/ | ||
.project | ||
.settings | ||
jte-classes | ||
.classpath | ||
bin |
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,5 @@ | ||
test: | ||
./gradlew test | ||
|
||
start: | ||
./gradlew run |
Large diffs are not rendered by default.
Oops, something went wrong.
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,28 @@ | ||
## Поисковые формы | ||
|
||
### Ссылки | ||
|
||
* [Методы работы с контекстом](https://javalin.io/documentation#context) | ||
* [Подключение стилей Bootstrap](https://getbootstrap.com/docs/5.1/getting-started/introduction/#css) | ||
* [Класс StringUtils из библиотеки Apache Commons](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#startsWithIgnoreCase-java.lang.CharSequence-java.lang.CharSequence-) | ||
|
||
### src/main/java/exercise/App.java | ||
|
||
Реализуйте обработчик, который будет обрабатывать GET-запросы на адрес */users* и формировать список пользователей. Обработчик должен поддерживать фильтрацию через параметр *term*, в котором передается имя пользователя *firstName*. | ||
|
||
В итоге обработчик должен выдавать все совпадения по началу имени пользователя без учета регистра | ||
|
||
Список пользователей `List<User>` находится в константе `USERS`. | ||
|
||
### src/main/java/exercise/dto/users/UsersPage.java | ||
|
||
Реализуйте дата-класс для передачи данных в шаблоны. | ||
|
||
### src/main/jte/users/index.jte | ||
|
||
Реализуйте вывод списка пользователей и формы для фильтрации. Если совпадения не найдены, то должна выводится только форма. Поле ввода форма должна сохранять введенное значение. | ||
|
||
### Подсказки | ||
|
||
* Если хотите сделать красивый вывод в шаблонах, используйте классы Bootstrap | ||
* Присмотритесь к методам класса `StringUtils` — возможно, какой-то из них вам понадобится |
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,50 @@ | ||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat | ||
import org.gradle.api.tasks.testing.logging.TestLogEvent | ||
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask | ||
|
||
plugins { | ||
id("com.github.ben-manes.versions") version "0.48.0" | ||
application | ||
|
||
id("io.freefair.lombok") version "8.1.0" | ||
} | ||
|
||
application { | ||
mainClass.set("exercise.App") | ||
} | ||
|
||
group = "exercise" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("io.javalin:javalin:5.6.1") | ||
|
||
implementation("gg.jte:jte:3.0.1") | ||
implementation("io.javalin:javalin-rendering:5.6.0") | ||
implementation("org.slf4j:slf4j-simple:2.0.7") | ||
implementation("net.datafaker:datafaker:2.0.1") | ||
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.0") | ||
testImplementation(platform("org.junit:junit-bom:5.9.1")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
testImplementation("com.konghq:unirest-java:3.13.0") | ||
testImplementation("org.hamcrest:hamcrest-core:2.2") | ||
testImplementation("org.assertj:assertj-core:3.24.2") | ||
implementation("org.apache.commons:commons-lang3:3.13.0") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
// https://technology.lastminute.com/junit5-kotlin-and-gradle-dsl/ | ||
testLogging { | ||
exceptionFormat = TestExceptionFormat.FULL | ||
events = mutableSetOf(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED) | ||
// showStackTraces = true | ||
// showCauses = true | ||
showStandardStreams = true | ||
} | ||
} | ||
|
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,38 @@ | ||
import io.javalin.Javalin; | ||
|
||
public final class App { | ||
|
||
public static Javalin getApp() { | ||
|
||
var app = Javalin.create(config -> { | ||
config.plugins.enableDevLogging(); | ||
}); | ||
|
||
List<String> users = List.of("John", "Mark", "Ann"); | ||
|
||
app.get("/users", ctx -> { | ||
var userNumber = ctx.pathParamAsClass("id", Integer.class); | ||
var cond = ctx.queryParam("cond"); | ||
List<String> filteredUsers; | ||
|
||
if (term == null) { | ||
filteredUsers = users; | ||
} else { | ||
filteredUsers = users | ||
.stream() | ||
.filter(u -> u.contains(cond)) | ||
.toList(); | ||
} | ||
|
||
var page = new UsersPage(users, cond); | ||
ctx.render("users/index.jte", Collections.singletonMap("page", page)); | ||
}); | ||
|
||
return app; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Javalin app = getApp(); | ||
app.start(7070); | ||
} | ||
} |
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
java-web-ru/get-form/gradle/wrapper/gradle-wrapper.properties
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,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.