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

View File

@@ -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))
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)

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_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)

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)

View File

@@ -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)

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)

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'.

View File

@@ -45,11 +45,13 @@ feature -- User Nodes
user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is a collaborator.
do
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
end
user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is the author.
do
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
end
feature -- Change: user
@@ -67,6 +69,7 @@ feature -- Access: roles and permissions
user_roles: LIST [CMS_USER_ROLE]
do
create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0)
end
@@ -104,6 +107,7 @@ feature -- Access: node
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
-- Possible list of node's collaborator.
do
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
end
feature -- Node

View File

@@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS `cms_dev`.`users` (
PRIMARY KEY (`id`),
UNIQUE INDEX `username` (`username` ASC))
ENGINE = InnoDB
AUTO_INCREMENT = 2
DEFAULT CHARACTER SET = latin1;
@@ -40,7 +41,7 @@ CREATE TABLE IF NOT EXISTS `cms_dev`.`nodes` (
`summary` TEXT NOT NULL,
`content` MEDIUMTEXT NOT NULL,
`author_id` INT(10) UNSIGNED NULL DEFAULT NULL,
`version` INT(10) ZEROFILL NULL,
`version` INT(10) UNSIGNED ZEROFILL NULL DEFAULT NULL,
`editor_id` INT(10) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `fk_nodes_users1_idx` (`author_id` ASC),
@@ -56,6 +57,7 @@ CREATE TABLE IF NOT EXISTS `cms_dev`.`nodes` (
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 11
DEFAULT CHARACTER SET = latin1;

View File

@@ -189,6 +189,7 @@ feature -- Node
delete_node (a_id: INTEGER_64)
do
node_provider.delete_from_user_nodes(a_id)
node_provider.delete_node (a_id)
post_node_provider_execution
end

View File

@@ -224,6 +224,18 @@ feature -- Basic operations
post_execution
end
delete_from_user_nodes (a_id: INTEGER_64)
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".delete_from_user_nodes")
create l_parameters.make (1)
l_parameters.put (a_id, "id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_delete_from_user_node, l_parameters))
db_handler.execute_change
post_execution
end
feature -- Basic Operations: User_Nodes
add_author (a_user_id: INTEGER_64; a_node_id: INTEGER_64)
@@ -413,6 +425,8 @@ feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
Select_exist_user_node: STRING= "Select Count(*) from Users_nodes where users_id=:user_id and nodes_id=:node_id;"
sql_delete_from_user_node: STRING = "delete from users_nodes where nodes_id=:id"
feature --