Updated blog design to use ?page=123&size=456.

Use  /blog/{user} url to list blog from a specific user.
Fixed bad xhtml rendering (missing closing tag).
This commit is contained in:
2017-01-27 19:12:37 +01:00
parent 456770ca3e
commit 38b4713276
5 changed files with 69 additions and 60 deletions

View File

@@ -1,14 +1,16 @@
note
description: "[
Request handler related to
/blogs/user/{id}/
or /blogs/user/{id}/page/{page}.
/blog/{user}/
or /blog/{user}?page={page}.
Displays all posts of the given user
]"
author: "Dario B<>sch <daboesch@student.ethz.ch>"
contributor: "Dario B<>sch <daboesch@student.ethz.ch>"
date: "$Date: 2015-05-22 15:13:00 +0100 (lun., 18 mai 2015) $"
revision: "$Revision 96616$"
fixme: "redesign pagination... see CMS_PAGINATION_GENERATOR."
class
BLOG_USER_HANDLER
@@ -28,7 +30,7 @@ create
feature -- Global Variables
user : detachable CMS_USER
user: detachable CMS_USER
feature -- HTTP Methods
@@ -37,7 +39,7 @@ feature -- HTTP Methods
local
l_error: NOT_FOUND_ERROR_CMS_RESPONSE
do
user := Void
check user_void: user = Void end
if attached user_from_request (req) as l_user then
user := l_user
-- Output the results, similar as in the blog hanlder (but with other queries)
@@ -45,53 +47,47 @@ feature -- HTTP Methods
else
-- Throw a bad request error because the user is not valid
create l_error.make (req, res, api)
l_error.set_main_content ("<h1>Error</h1>User with id " + user_id_path_parameter (req).out + " doesn't exist!")
if attached user_parameter (req) as l_user_id then
l_error.set_main_content ("<h1>Error</h1>User with id " + api.html_encoded (l_user_id) + " not found!</h1>")
else
l_error.set_main_content ("<h1>Error</h1>User not found!</h1>")
end
l_error.execute
end
user := Void
end
feature -- Query
user_valid (req: WSF_REQUEST) : BOOLEAN
-- Returns true if a valid user id is given and a user with this id exists,
-- otherwise returns false.
local
user_id: INTEGER_32
do
user_id := user_id_path_parameter (req)
if user_id <= 0 then
-- Given user id is not valid
Result := False
else
--Check if user with user_id exists
Result := api.user_api.user_by_id (user_id) /= Void
end
end
user_from_request (req: WSF_REQUEST): detachable CMS_USER
-- Eventual user with given id in the path of request `req'.
local
uid: like user_id_path_parameter
uid: INTEGER_64
do
uid := user_id_path_parameter (req)
if uid > 0 then
Result := api.user_api.user_by_id (uid)
if
attached user_parameter (req) as l_user_id and then
not l_user_id.is_whitespace
then
if l_user_id.is_integer_64 then
uid := l_user_id.to_integer_64
if uid > 0 then
Result := api.user_api.user_by_id (uid)
end
else
Result := api.user_api.user_by_name (l_user_id)
end
else
-- Missing or invalid user id.
end
end
user_id_path_parameter (req: WSF_REQUEST): INTEGER_32
-- User id from path /blogs/{user}.
user_parameter (req: WSF_REQUEST): detachable STRING_32
-- User id from path /blog/{user}.
-- Unsigned integer since negative ids are not allowed.
-- If no valid id can be read it returns -1
do
Result := -1
if attached {WSF_STRING} req.path_parameter ("user") as l_user_id then
if l_user_id.is_integer then
Result := l_user_id.integer_value
end
Result := l_user_id.value
end
end
@@ -139,9 +135,9 @@ feature -- HTML Output
-- If user is logged in, include user id
do
if attached user as l_user then
Result := "/blogs/user/" + l_user.id.out
Result := "/blog/" + l_user.id.out
else
Result := precursor
Result := Precursor
end
end