add repl to api server and fix list-snippets sorting

This commit is contained in:
Travis Shears 2026-03-10 18:31:36 +01:00
parent a8038a604c
commit a90cabf605
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
6 changed files with 25 additions and 3 deletions

View file

@ -22,6 +22,8 @@ RUN clj -P
COPY build.clj config.edn ./ COPY build.clj config.edn ./
COPY src ./src COPY src ./src
ENV DATOMIC_PATH=/datomic_data
ENV DATOMIC_ENV=prd
# construct the application jar # construct the application jar
RUN clj -T:build uber && cp target/snippets-standalone.jar ./app.jar && rm -r target RUN clj -T:build uber && cp target/snippets-standalone.jar ./app.jar && rm -r target

View file

@ -32,6 +32,14 @@ $ fd -e clj | entr -r clojure -M -m snippets.main
### Repl ### Repl
Connect to the repl of running app
```shell
$ rlwrap nc localhost 5555
```
Or start up fresh repl
``` ```
$ rlwrap clojure $ rlwrap clojure
; print stuff ; print stuff

View file

@ -1,6 +1,6 @@
{ {
"version": "1", "version": "1",
"name": "CodeSnippets", "name": "Snippets",
"type": "collection", "type": "collection",
"ignore": [ "ignore": [
"node_modules", "node_modules",

View file

@ -2,7 +2,6 @@
(:require (:require
[ring.adapter.jetty :as jetty] [ring.adapter.jetty :as jetty]
[clojure.pprint :as pprint] [clojure.pprint :as pprint]
[clojure.string :as str]
[taoensso.telemere :as t] [taoensso.telemere :as t]
[snippets.use-cases.view] [snippets.use-cases.view]
[snippets.use-cases.delete] [snippets.use-cases.delete]

View file

@ -1,9 +1,20 @@
(ns snippets.main (ns snippets.main
(:require (:require
[snippets.infra.api :as api] [snippets.infra.api :as api]
[snippets.infra.db2 :refer [start-up-check]]) [clojure.core.server]
[snippets.infra.db2 :refer [start-up-check]]
[taoensso.telemere :as t])
(:gen-class)) (:gen-class))
(defn start-repl-server []
(let [settings {:port 5555 :host "0.0.0.0"}]
(clojure.core.server/start-server
(merge
{:name "repl"
:accept 'clojure.core.server/repl} settings))
(t/log! {:level :info, :data {:settings settings}} "Starting repl server")))
(defn -main [] (defn -main []
(start-up-check) (start-up-check)
(start-repl-server)
(api/run-server)) (api/run-server))

View file

@ -15,6 +15,8 @@
(let [limit (:limit options) (let [limit (:limit options)
skip (:skip options)] skip (:skip options)]
(->> (db/list-snippets) (->> (db/list-snippets)
(sort-by :pub-date)
(reverse)
(drop skip) (drop skip)
(take limit) (take limit)
(map serialize-snippet))))) (map serialize-snippet)))))