Delete comments
This commit is contained in:
parent
b7ea1bb5f7
commit
6c6054ed38
4 changed files with 24 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Reference in a new issue