Delete comments

This commit is contained in:
Aaron Fischer 2017-04-15 23:08:11 +02:00
parent b7ea1bb5f7
commit 6c6054ed38
4 changed files with 24 additions and 4 deletions

View file

@ -84,6 +84,15 @@ SELECT * FROM comments
WHERE image_id = :image_id
ORDER BY created_at ASC
-- :name get-comment :? :1
SELECT * FROM comments
WHERE id = :id
LIMIT 1
-- :name delete-comment! :! :1
DELETE FROM comments
WHERE id = :id
-- :name get-recent-comments :? :*
SELECT comments.*, images.title FROM comments
LEFT JOIN images ON images.id = comments.image_id

View file

@ -72,6 +72,9 @@
<img src="https://robohash.org/{{ comment.author }}?size=50x50" class="d-flex mr-3"/>
<div class="media-body">
<h5 class="mt-0 mb-1">{{ comment.author }}</h5>
{% ifequal identity ":creator" %}
<a class="btn btn-sm btn-danger" href="/delete-comment/{{ comment.id}}">Löschen</a>
{% endifequal %}
{{ comment.comment|markdown-to-html|safe }}
</div>
</li>

View file

@ -58,6 +58,9 @@
(db/delete-image-tags! {:id id})
(add-tags-for-image id tags))
(defn image-id-from-comment [id]
(:image_id (db/get-comment {:id id})))
(defroutes admin-routes
(GET "/upload" [:as request]
(-> (layout/render
@ -75,6 +78,12 @@
(-> (redirect "/page/1")
(assoc :flash {:message "Bild wurde gelöscht" :type "danger"})))
(GET "/delete-comment/:id" [id]
(let [image-id (image-id-from-comment id)]
(db/delete-comment! {:id id})
(-> (redirect (str "/show/" image-id))
(assoc :flash {:message "Kommentar wurde gelöscht" :type "danger"}))))
(GET "/edit/:id" [id :as request]
(edit-image-form id request))

View file

@ -35,16 +35,15 @@
(page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))]]
[:div.clearfix]))
(defn index-page [current-page request]
(defn index-page [current request]
(let [image-count 25
offset (* (dec current-page) image-count)
offset (* (dec current) image-count)
pages (number-of-pages image-count)
images (db/get-all-images {:offset offset :count image-count})]
(layout/render "index.html"
{:images images
:flash (:flash request)
:current-page current-page
:pagination (pagination pages current-page)})))
:pagination (pagination pages current)})))
(defn detail-page [image-id request]
(let [image (db/get-image {:id image-id})