-
Notifications
You must be signed in to change notification settings - Fork 6
Mashkov Homework-15 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| [:input {:type "submit" :value "Generate"}]]]])) | ||
|
|
||
| (defn gen-data-response [spec] | ||
| (let [decoded-spec (json-to-edn spec)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Строго говоря, тут может и ошибка возникнуть, если JSON не получится декодировать.
UPD: вижу, что ниже эта ошибка обрабатывается. Но я бы ожидал отлов ошибки парсинга здесь, раз уж в этой функции вы уже responses возвращаете, в том числе и bad request.
| (invalid-spec-response decoded-spec)))) | ||
|
|
||
| (defn redirect-response [spec-json] | ||
| (see-other (str "/?spec=" (URLEncoder/encode ^String spec-json "UTF-8")))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно воспользоваться hiccup.util/url, раз уж hiccup всё равно используется в проекте
|
Солидно! Отличная работа! |
| [ring.util.http-response :refer :all] | ||
| [hiccup.core :refer [html]] | ||
| [schema.core :as s]) | ||
| (:gen-class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gen-class обычно в самом конце пишут. Или хотя бы require и import рядом располагают, как связанные по смыслу директивы
| (GET "/" [] | ||
| (html [:h1 "Hello World!"]))) | ||
| {:port 8000})) | ||
| (run-jetty app {:port 8000 :join? false})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В main как раз нужно делать join, иначе если вы запустите программу не из REPL, то сервер тут же будет остановлен, поскольку главный поток завершит работу сразу же.
| (let [minimum (:minimum schema 0) | ||
| maximum (:maximum schema Integer/MAX_VALUE)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно попробовать вынести эти опции в деструктуризацию и указать значения по умолчанию там же через :or {minimum 0 ..}.
| ([schema count] | ||
| (gen/sample (gen-schema schema) count)) | ||
| ([schema] | ||
| (first (gen-example schema 1)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я бы не очень хотел, чтобы функция возвращала здесь не последовательность, а один элемент, даже если count подразумевается равным единице - не очень приятно получать результаты вызова функции, имеющие разные типы без особой на то нужды. Если хочется возвращать именно один элемент, то имеет смысл завести две функции: gen-example и gen-examples.
No description provided.