@ -24,6 +24,17 @@
#:sex ) )
#:sex ) )
( in-package #:rails-to-caveman.model )
( in-package #:rails-to-caveman.model )
( defclass vote ( )
( ( entry
:col-type entry
:initarg :entry
:accessor entry-of )
( user
:col-type user
:initarg :user
:accessor user-of ) )
( :metaclass mito:dao-table-class ) )
( defclass article ( )
( defclass article ( )
( ( title :initarg :title
( ( title :initarg :title
:col-type ( :varchar 80 )
:col-type ( :varchar 80 )
@ -98,6 +109,26 @@
:inflate #' cl-pass:hash ) )
:inflate #' cl-pass:hash ) )
( :metaclass mito:dao-table-class ) )
( :metaclass mito:dao-table-class ) )
( defmethod mito:delete-dao :before ( ( user user ) )
( mito:delete-by-values 'vote
:user-id ( mito:object-id user ) )
( mito:delete-by-values 'entry
:user-id ( mito:object-id user ) ) )
( defmethod mito:delete-dao :before ( ( o entry ) )
( mito:delete-by-values 'vote
:entry-id ( mito:object-id o ) )
( mito:delete-by-values 'entry-image
:entry-id ( mito:object-id o ) ) )
( defun votablep ( entry user )
( and entry ( not ( mito:object= user ( author-of entry ) ) )
( null ( mito:select-dao 'vote
( sxql:where
( :and
( := :user-id ( mito:object-id user ) )
( := :entry-id ( mito:object-id entry ) ) ) )
( sxql:limit 1 ) ) ) ) )
( defun ids ( )
( defun ids ( )
" Produces a list of all the Id 's in the database. Part of Chapter 4
" Produces a list of all the Id 's in the database. Part of Chapter 4
@ -538,8 +569,21 @@ reference for future projects. This is a learning project after all.
;; 'user' class definition highlighting this.
;; 'user' class definition highlighting this.
:administrator ( zerop 0 )
:administrator ( zerop 0 )
:password "asagao!"
:password "asagao!"
:filename ( when ( zerop x ) "profile.png" )
:filename "profile.png" ; (when (zerop x) "profile.png")
:content-type ( when ( zerop x ) "image/png" ) ) )
:content-type "image/png" ) ; (when (zerop x) "image/png"))
;; PROBLEM IS IN HERE....
( with-open-file ( s ( merge-pathnames #P"profile.png"
rails-to-caveman.config::*application-root* )
:element-type ' ( unsigned-byte 8 ) )
( let ( ( vector ( make-array
( file-length s )
:element-type ' ( unsigned-byte 8 ) ) ) )
( read-sequence vector s )
( rails-to-caveman.storage::write
( make-instance 'flex::vector-input-stream :vector vector ) x "account"
( rails-to-caveman.storage::make-file :name "profile.png" :content-type "image/png" ) )
;; PROBLEM IS IN HERE....
) ) )
;; "#.(" is an ARRAY LITERAL. (Noted in 'Loving Common Lisp' book).
;; "#.(" is an ARRAY LITERAL. (Noted in 'Loving Common Lisp' book).
( let ( ( body #. ( with-output-to-string ( *standard-output* )
( let ( ( body #. ( with-output-to-string ( *standard-output* )
( format t "Morning glory wins.~2%" )
( format t "Morning glory wins.~2%" )
@ -555,27 +599,40 @@ reference for future projects. This is a learning project after all.
:date-expired ( local-time:timestamp- now-time ( - 2 x ) :day )
:date-expired ( local-time:timestamp- now-time ( - 2 x ) :day )
:member-only ( zerop 0 ) ) )
:member-only ( zerop 0 ) ) )
( dolist ( name ' ( "Jiro" "Taro" "Hana" ) )
( dolist ( name ' ( "Jiro" "Taro" "Hana" ) )
;; replace here...
( let ( ( user ( mito:find-dao 'user :name name ) ) )
( let ( ( user ( mito:find-dao 'user :name name ) ) )
( when user ( dotimes ( x 10 )
( when user ( dotimes ( x 10 )
( mito:create-dao 'entry
;; (mito:create-dao 'entry
;; :user user
;; :title (format nil "Title~D" x)
;; :body body
;; :date-posted (local-time:timestamp- now-time (- 10 x) :day)
;; :status (nth (rem x 3) '("draft" "member-only" "public")))))))
( let ( ( entry ( mito:create-dao 'entry
:user user
:user user
:title ( format nil "Title~D" x )
:title ( format nil "Title~D" x )
:body body
:body body
:date-posted ( local-time:timestamp- now-time ( - 10 x ) :day )
:date-posted ( local-time:timestamp- now-time ( - 10 x ) :day )
:status ( nth ( rem x 3 ) ' ( "draft" "member-only" "public" ) ) ) ) ) ) )
:status ( nth ( rem x 3 ) ' ( "draft" "member-only" "public" ) ) ) ) )
;; PROBLEM IS IN HERE....
( when ( find x ' ( 7 8 ) )
( with-open-file ( s ( merge-pathnames #P"profile.png"
( dolist ( name ' ( "John" "Mike" "Sophy" ) )
rails-to-caveman.config::*application-root* )
( let ( ( voter ( mito:find-dao 'user :name name ) ) )
:element-type ' ( unsigned-byte 8 ) )
( mito:create-dao 'vote :user voter :entry entry ) ) ) ) ) ) ) ) ) ) ) ) )
( let ( ( vector ( make-array
( file-length s )
:element-type ' ( unsigned-byte 8 ) ) ) )
( read-sequence vector s )
( rails-to-caveman.storage::write
( make-instance 'flex::vector-input-stream :vector vector ) 1 "account"
( rails-to-caveman.storage::make-file :name "profile.png" :content-type "image/png" ) )
;; PROBLEM IS IN HERE....
;; PROBLEM IS IN HERE....
) ) ) ) ) )
;; (with-open-file (s (merge-pathnames #P"profile.png"
;; rails-to-caveman.config::*application-root*)
;; :element-type '(unsigned-byte 8))
;; (let ((vector (make-array
;; (file-length s)
;; :element-type '(unsigned-byte 8))))
;; (read-sequence vector s)
;; (rails-to-caveman.storage::write
;; (make-instance 'flex::vector-input-stream :vector vector) 1 "account"
;; (rails-to-caveman.storage::make-file :name "profile.png" :content-type "image/png"))
;; ;; PROBLEM IS IN HERE....
;; ))))))
;; ))))
#|
#|
( defun seeds ( ) ( with-open-file ( s ( merge-pathnames "profile.png"
( defun seeds ( ) ( with-open-file ( s ( merge-pathnames "profile.png"
@ -600,6 +657,6 @@ reference for future projects. This is a learning project after all.
( defun rebuild ( )
( defun rebuild ( )
"Drops the current database table, recreates it and populates it using seeded data."
"Drops the current database table, recreates it and populates it using seeded data."
( with-connection ( db )
( with-connection ( db )
( mapc #' mito:ensure-table-exists ' ( user article entry ) )
( mapc #' mito:ensure-table-exists ' ( user article entry entry-image vote ) )
( mapc #' mito:recreate-table ' ( user article entry ) ) )
( mapc #' mito:recreate-table ' ( user article entry entry-image vote ) ) )
( seeds ) )
( seeds ) )