From e8ff313c284a98bffcdaf34792b54db9a3e8da0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20B=C3=B6sch?= Date: Fri, 22 May 2015 17:58:46 +0200 Subject: [PATCH] added some commments --- examples/demo/modules/blog/cms_blog_api.e | 3 ++- examples/demo/modules/blog/handler/blog_handler.e | 15 ++++++--------- .../demo/modules/blog/handler/blog_user_handler.e | 13 +++++++------ .../demo/modules/blog/handler/cms_blog_handler.e | 8 ++++---- src/persistence/sql/cms_storage_sql_builder.e | 5 ----- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/examples/demo/modules/blog/cms_blog_api.e b/examples/demo/modules/blog/cms_blog_api.e index 95a9509..e75593c 100644 --- a/examples/demo/modules/blog/cms_blog_api.e +++ b/examples/demo/modules/blog/cms_blog_api.e @@ -1,5 +1,5 @@ note - description: "API to handle nodes of type blog" + description: "API to handle nodes of type blog. Extends the node API." author: "Dario Bösch do Precursor + -- Create the node storage for type blog if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then create {CMS_BLOG_STORAGE_SQL} node_storage.make (l_storage_sql) else diff --git a/examples/demo/modules/blog/handler/blog_handler.e b/examples/demo/modules/blog/handler/blog_handler.e index c0a04ab..536681c 100644 --- a/examples/demo/modules/blog/handler/blog_handler.e +++ b/examples/demo/modules/blog/handler/blog_handler.e @@ -1,5 +1,5 @@ note - description: "Request handler related to /blogs." + description: "Request handler related to /blogs and /blogs/{page}. Displays all posts in the blog." author: "Dario Bösch " date: "$Date: 2015-05-18 13:49:00 +0100 (lun., 18 mai 2015) $" revision: "$9661667$" @@ -67,13 +67,11 @@ feature -- HTTP Methods local l_page: CMS_RESPONSE do - -- At the moment the template is hardcoded, but we can - -- get them from the configuration file and load them into - -- the setup class. -- Read the page number from get variable page_number := page_number_path_parameter (req) + -- execute response by setting the main content create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api) l_page.set_main_content (main_content_html(l_page)) l_page.execute @@ -83,7 +81,7 @@ feature -- Query posts : LIST[CMS_NODE] - -- The posts to list on the given page + -- The posts to list on the given page ordered by date (descending) do Result := node_api.blogs_order_created_desc_limited (entries_per_page, (page_number-1) * entries_per_page) end @@ -142,7 +140,7 @@ feature -- HTML Output -- Get the posts from the current page (given by page number and entries per page) if attached posts as lst then - -- List all posts of the blog + -- Start list of posts Result.append ("
    %N") across lst as ic @@ -169,7 +167,7 @@ feature -- HTML Output -- End of post list Result.append ("
%N") - -- Pagination + -- Pagination (older and newer links) Result.append (pagination_html) --end @@ -182,13 +180,12 @@ feature -- HTML Output create Result.make_from_string ("

Blog") if more_than_one_page then Result.append (" (Page " + page_number.out + " of " + pages.out + ")") - -- Get the posts from the current page (limited by entries per page) end Result.append ("

") end creation_date_html (n: CMS_NODE) : STRING - -- returns the creation date. At the moment hard coded as html + -- returns the creation date as a html string local hdate: HTTP_DATE do diff --git a/examples/demo/modules/blog/handler/blog_user_handler.e b/examples/demo/modules/blog/handler/blog_user_handler.e index d20667a..58fff51 100644 --- a/examples/demo/modules/blog/handler/blog_user_handler.e +++ b/examples/demo/modules/blog/handler/blog_user_handler.e @@ -1,5 +1,5 @@ note - description: "Request handler related to /blogs/user/{id}/. Displays all posts of the given user" + description: "Request handler related to /blogs/user/{id}/ or /blogs/user/{id}/page/{page}. Displays all posts of the given user" author: "Dario Bösch " date: "$Date: 2015-05-22 15:13:00 +0100 (lun., 18 mai 2015) $" revision: "$Revision 96616$" @@ -35,9 +35,10 @@ feature -- HTTP Methods -- Check if userID valid if user_valid (req) then user := load_user(req) + -- Output the results, similar as in the blog hanlder (but with other queries) precursor(req, res) else - -- Throw a bad request error if the user is not valid + -- Throw a bad request error because the user is not valid create l_error.make (req, res, api) l_error.set_main_content ("

Error

User with id " + user_path_parameter(req).out + " doesn't exist!") l_error.execute @@ -88,7 +89,7 @@ feature -- Query end posts : LIST[CMS_NODE] - -- The posts to list on the given page + -- The posts to list on the given page. Filters out the posts of the current user do if attached user as l_user then Result := node_api.blogs_from_user_order_created_desc_limited (l_user.id.to_integer_32, entries_per_page, (page_number-1) * entries_per_page) @@ -98,7 +99,7 @@ feature -- Query end total_entries : NATURAL_32 - -- Returns the number of total entries/posts + -- Returns the number of total entries/posts of the current user do if attached user as l_user then Result := node_api.blogs_count_from_user(l_user.id).to_natural_32 @@ -111,7 +112,7 @@ feature -- Query feature -- HTML Output page_title_html : STRING - -- Returns the title of the page as a html string. It shows the current page number + -- Returns the title of the page as a html string. It shows the current page number and the name of the current user do create Result.make_from_string ("

Posts from ") if attached user as l_user then @@ -127,7 +128,7 @@ feature -- HTML Output end base_path : STRING - -- the path to the page that lists all blogs + -- the path to the page that lists all blogs. It must include the user id do if attached user as l_user then Result := "/blogs/user/" + l_user.id.out diff --git a/examples/demo/modules/blog/handler/cms_blog_handler.e b/examples/demo/modules/blog/handler/cms_blog_handler.e index c33d834..bef34e5 100644 --- a/examples/demo/modules/blog/handler/cms_blog_handler.e +++ b/examples/demo/modules/blog/handler/cms_blog_handler.e @@ -1,8 +1,8 @@ note - description: "Summary description for {CMS_NODE_HANDLER}." - author: "" - date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $" - revision: "$Revision: 96616 $" + description: "Deferred request handler related to /blogs/... Has an own blog api." + author: "Dario Bösch " + date: "$Date: 2015-05-18 13:49:00 +0100 (lun., 18 mai 2015) $" + revision: "$9661667$" deferred class CMS_BLOG_HANDLER diff --git a/src/persistence/sql/cms_storage_sql_builder.e b/src/persistence/sql/cms_storage_sql_builder.e index 8c9fe69..6000207 100644 --- a/src/persistence/sql/cms_storage_sql_builder.e +++ b/src/persistence/sql/cms_storage_sql_builder.e @@ -36,11 +36,6 @@ feature -- Initialization create u.make ("admin") u.set_password ("istrator#") u.set_email (a_setup.site_email) - a_storage.new_user (u) - - create u.make ("daboesch") - u.set_password ("eiffel") - u.set_email ("daboesch@student.ethz.ch") a_storage.new_user (u) --| Node