From ffd483411c138b7c445ff1b7a8ddc3d26f92e0c4 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 24 Sep 2022 01:15:41 +0100 Subject: [PATCH] start implementing the CRUD functions for the /archive routes. I still need to write the edit and delete functions (I.E. the 'U' and 'D' in 'CRUD') to have a basic CRUD system in place for this section. I'm commiting this as an part of an end-of-session commit, hence the partical amount of work done. --- src/nera.lisp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/nera.lisp b/src/nera.lisp index c1a0018..76b95c4 100644 --- a/src/nera.lisp +++ b/src/nera.lisp @@ -36,7 +36,10 @@ #:get-storage-file #:get-all-storage-files #:rename-storage-file - #:delete-storage-file)) + #:delete-storage-file + #:get-all-archive-entries + #:create-archive-entry + #:get-archive-entry)) (in-package #:nera-db) (defparameter *tables* '(user site-settings page storage-file archive-entry) @@ -273,3 +276,31 @@ slug is updated based on `NEW-FILE-NAME'." (if (null slug) (mito:delete-by-values 'files:storage-file :name name) (mito:delete-by-values 'files:storage-file :slug slug)))) + +(defun get-all-archive-entries () + "Returns a list of all `ARCHIVE-ENTRY' entries in the database." + (with-connection (db) + (mito:select-dao 'archive:archive-entry + (sxql:order-by (:asc :title))))) + +(defun create-archive-entry (title search-id slug thumbnail-slug thumbnail-file-type keywords) + "Add a new `ARCHIVE-ENTRY' to the database." + (with-connection (db) + (mito:create-dao 'archive:archive-entry + :title title + :search-id search-id + :slug slug + :thumbnail-slug thumbnail-slug + :thumbnail-file-type thumbnail-file-type + :keywords keywords))) + +(defun get-archive-entry (&key id title slug) + "Returns a `ARCHIVE-ENTRY' from the database." + (with-connection (db) + (cond ((and (not title) (not slug)) + (mito:find-dao 'archive:archive-entry :id id)) + ((and (not id) (not slug)) + (mito:find-dao 'archive:archive-entry :title title)) + ((and (not id) (not title)) + (mito:find-dao 'archive:archive-entry :slug slug)) + (t nil))))