Updated Example (API) to use the new CMS_STORAGE interface.

This commit is contained in:
jvelilla
2014-09-21 15:53:09 -03:00
parent fb9157dbb4
commit 588827b495
10 changed files with 63 additions and 23 deletions
@@ -37,8 +37,12 @@ feature -- Basic operations
if (attached l_auth.type as l_auth_type and then l_auth_type.is_case_insensitive_equal ("basic")) and then
attached l_auth.login as l_auth_login and then attached l_auth.password as l_auth_password then
if api_service.login_valid (l_auth_login, l_auth_password) then
req.set_execution_variable ("user", create {CMS_USER}.make (l_auth_login))
execute_next (req, res)
if attached api_service.user_by_name (l_auth_login) as l_user then
req.set_execution_variable ("user", l_user)
execute_next (req, res)
else
-- Internal server error
end
else
log.write_error (generator + ".execute login_valid failed for: " + l_auth_login )
execute_next (req, res)
@@ -133,12 +133,13 @@ feature -- HTTP Methods
u_node: CMS_NODE
l_page: ROC_RESPONSE
do
if attached current_user_name (req) then
to_implement ("Check if user has permissions")
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.integer_value)
api_service.update_node_content (u_node.id, u_node.content)
api_service.update_node_content (l_user.id, u_node.id, u_node.content)
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
+8 -4
View File
@@ -93,7 +93,8 @@ feature -- HTTP Methods
u_node: CMS_NODE
l_page: ROC_RESPONSE
do
if attached current_user_name (req) then
to_implement ("Check user permissions!!!")
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
@@ -113,7 +114,9 @@ feature -- HTTP Methods
end
else
-- New node
api_service.new_node (extract_data_form (req))
u_node := extract_data_form (req)
u_node.set_author (l_user)
api_service.new_node (u_node)
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
end
else
@@ -126,12 +129,13 @@ feature -- HTTP Methods
local
u_node: CMS_NODE
do
if attached current_user_name (req) then
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.integer_value)
api_service.update_node (u_node)
api_service.update_node (l_user.id,u_node)
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
@@ -132,12 +132,13 @@ feature -- HTTP Methods
u_node: CMS_NODE
l_page: ROC_RESPONSE
do
if attached current_user_name (req) then
to_implement ("Check if user has permissions!!!")
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.integer_value)
api_service.update_node_summary (u_node.id, u_node.summary)
api_service.update_node_summary (l_user.id,u_node.id, u_node.summary)
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
+3 -2
View File
@@ -133,12 +133,13 @@ feature -- HTTP Methods
u_node: CMS_NODE
l_page: ROC_RESPONSE
do
if attached current_user_name (req) then
to_implement ("Check if user has permissions")
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.integer_value)
api_service.update_node_title (u_node.id, u_node.title)
api_service.update_node_title (l_user.id,u_node.id, u_node.title)
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
+18 -10
View File
@@ -35,6 +35,8 @@ feature -- Access
Result := storage.is_valid_credential (l_auth_login, l_auth_password)
end
feature -- Access: Node
nodes: LIST[CMS_NODE]
-- List of nodes.
do
@@ -56,7 +58,7 @@ feature -- Access
end
feature -- Node
feature -- Change: Node
new_node (a_node: CMS_NODE)
-- Add a new node
@@ -69,31 +71,37 @@ feature -- Node
storage.delete_node (a_id)
end
update_node (a_node: CMS_NODE)
update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE)
do
storage.update_node (a_node)
storage.update_node (a_id,a_node)
end
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
do
fixme ("Check preconditions")
storage.update_node_title (a_id, a_title)
storage.update_node_title (a_id,a_node_id,a_title)
end
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
do
fixme ("Check preconditions")
storage.update_node_summary (a_id, a_summary)
storage.update_node_summary (a_id,a_node_id, a_summary)
end
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
do
fixme ("Check preconditions")
storage.update_node_content (a_id, a_content)
storage.update_node_content (a_id,a_node_id, a_content)
end
feature -- User
feature -- Access: User
user_by_name (a_username: READABLE_STRING_32): detachable CMS_USER
do
Result := storage.user_by_name (a_username)
end
feature -- Change User
new_user (a_user: CMS_USER)
-- Add a new user `a_user'.