diff --git a/extra/webapps/blogs/blogs.factor b/extra/webapps/blogs/blogs.factor index f098bb9f09..27ddc58afe 100644 --- a/extra/webapps/blogs/blogs.factor +++ b/extra/webapps/blogs/blogs.factor @@ -47,19 +47,19 @@ entity f { M: entity feed-entry-date date>> ; -TUPLE: post < entity title comments ; +TUPLE: post-state < entity title comments ; -M: post feed-entry-title +M: post-state feed-entry-title [ author>> ] [ title>> ] bi ": " glue ; -M: post entity-url +M: post-state entity-url id>> view-post-url ; -\ post "BLOG_POSTS" { +\ post-state "BLOG_POSTS" { { "title" "TITLE" { VARCHAR 256 } +not-null+ } } define-persistent -: ( id -- post ) \ post new swap >>id ; +: ( id -- post ) \ post-state new swap >>id ; TUPLE: comment < entity parent ; @@ -79,7 +79,7 @@ M: comment entity-url swap >>parent ; : post ( id -- post ) - [ select-tuple ] [ f select-tuples ] bi + [ select-tuple ] [ f select-tuples ] bi >>comments ; : reverse-chronological-order ( seq -- sorted ) @@ -89,7 +89,7 @@ M: comment entity-url { { "author" [ v-username ] } } validate-params ; : list-posts ( -- posts ) - f "author" value >>author + f "author" value >>author select-tuples [ dup id>> f count-tuples >>comments ] map reverse-chronological-order ; @@ -164,7 +164,7 @@ M: comment entity-url ] >>validate [ - f + f dup { "title" "content" } to-object username >>author now >>date @@ -183,7 +183,7 @@ M: comment entity-url : do-post-action ( -- ) validate-integer-id - "id" value select-tuple from-object ; + "id" value select-tuple from-object ; : ( -- action ) @@ -197,7 +197,7 @@ M: comment entity-url [ "author" value authorize-author ] >>authorize [ - "id" value + "id" value dup { "title" "author" "date" "content" } to-object [ update-tuple ] [ entity-url ] bi ] >>submit @@ -208,7 +208,7 @@ M: comment entity-url "edit a blog post" >>description ; : delete-post ( id -- ) - [ delete-tuples ] [ f delete-tuples ] bi ; + [ delete-tuples ] [ f delete-tuples ] bi ; : ( -- action ) @@ -234,7 +234,7 @@ M: comment entity-url [ [ - f "author" value >>author select-tuples [ id>> delete-post ] each + f "author" value >>author select-tuples [ id>> delete-post ] each f f "author" value >>author delete-tuples ] with-transaction "author" value posts-by-url @@ -277,7 +277,7 @@ M: comment entity-url ] >>validate [ - "parent" value select-tuple + "parent" value select-tuple author>> authorize-author ] >>authorize