Update api and storage api.

Fix missing parameters for sqlite query.
This commit is contained in:
2015-01-21 17:49:16 +01:00
parent 4aa9c1e097
commit d23cfbc300
6 changed files with 93 additions and 77 deletions

View File

@@ -62,13 +62,13 @@ feature -- Access: user
sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
do
db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, Void))
db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params))
db_handler.execute_query
end
sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
do
db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, Void))
db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params))
db_handler.execute_change
end

View File

@@ -68,7 +68,10 @@ feature -- HTTP Methods
do
-- Existing node
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
if
l_id.is_integer and then
attached api.node (l_id.value.to_integer_64) as l_node
then
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
l_page.add_variable (l_node, "node")
l_page.execute
@@ -89,7 +92,10 @@ feature -- HTTP Methods
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.node (l_id.integer_value) as l_node then
if
l_id.is_integer and then
attached {CMS_NODE} api.node (l_id.value.to_integer_64) as l_node
then
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
if l_method.is_case_insensitive_equal ("DELETE") then
do_delete (req, res)
@@ -104,7 +110,8 @@ feature -- HTTP Methods
end
else
-- New node
u_node := extract_data_form (req)
create u_node.make ("", "", "")
update_node_from_data_form (req, u_node)
u_node.set_author (l_user)
api.new_node (u_node)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
@@ -116,16 +123,17 @@ feature -- HTTP Methods
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
do
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.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.value.to_integer_64)
api.update_node (l_user.id,u_node)
if
l_id.is_integer and then
attached api.node (l_id.value.to_integer_64) as l_node
then
update_node_from_data_form (req, l_node)
l_node.set_author (l_user)
api.update_node (l_node)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
@@ -136,7 +144,6 @@ feature -- HTTP Methods
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
@@ -144,7 +151,10 @@ feature -- HTTP Methods
do
if attached current_user_name (req) then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
if
l_id.is_integer and then
attached api.node (l_id.integer_value) as l_node
then
api.delete_node (l_id.integer_value)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
else
@@ -198,19 +208,18 @@ feature {NONE} -- Node
feature -- {NONE} Form data
extract_data_form (req: WSF_REQUEST): CMS_NODE
update_node_from_data_form (req: WSF_REQUEST; a_node: CMS_NODE)
-- Extract request form data and build a object
-- Node
do
create Result.make ("", "", "")
if attached {WSF_STRING} req.form_parameter ("title") as l_title then
Result.set_title (l_title.value)
a_node.set_title (l_title.value)
end
if attached {WSF_STRING} req.form_parameter ("summary") as l_summary then
Result.set_summary (l_summary.value)
a_node.set_summary (l_summary.value)
end
if attached {WSF_STRING} req.form_parameter ("content") as l_content then
Result.set_content (l_content.value)
a_node.set_content (l_content.value)
end
end

View File

@@ -126,7 +126,7 @@ feature -- Access: node
feature -- Node
save_node (a_node: CMS_NODE)
new_node (a_node: CMS_NODE)
-- Add a new node
do
end
@@ -136,22 +136,22 @@ feature -- Node
do
end
update_node (a_id: like {CMS_NODE}.id; a_node: CMS_NODE)
update_node (a_node: CMS_NODE)
-- <Precursor>
do
end
update_node_title (a_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
update_node_title (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- <Precursor>
do
end
update_node_summary (a_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
update_node_summary (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- <Precursor>
do
end
update_node_content (a_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
update_node_content (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- <Precursor>
do
end

View File

@@ -45,9 +45,10 @@ feature -- Access
feature -- Change: Node
save_node (a_node: CMS_NODE)
new_node (a_node: CMS_NODE)
-- Save node `a_node'.
require
no_id: not a_node.has_id
valid_user: attached a_node.author as l_author implies l_author.id > 0
deferred
end
@@ -59,12 +60,12 @@ feature -- Change: Node
deferred
end
update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE)
update_node (a_node: CMS_NODE)
-- Update node content `a_node'.
-- The user `a_id' is an existing or new collaborator.
require
valid_node_id: a_node.id > 0
valid_user_id: a_id > 0
has_id: a_node.has_id
has_author: attached a_node.author as l_author and then l_author.has_id
deferred
end

View File

@@ -125,38 +125,34 @@ feature -- Access
feature -- Change: Node
save_node (a_node: CMS_NODE)
new_node (a_node: CMS_NODE)
-- Save node `a_node'.
local
l_parameters: STRING_TABLE [detachable ANY]
do
if a_node.has_id and attached a_node.author as l_author and then l_author.has_id then
update_node (l_author.id, a_node)
-- New node
error_handler.reset
log.write_information (generator + ".new_node")
create l_parameters.make (7)
l_parameters.put (a_node.title, "title")
l_parameters.put (a_node.summary, "summary")
l_parameters.put (a_node.content, "content")
l_parameters.put (a_node.publication_date, "publication_date")
l_parameters.put (a_node.creation_date, "creation_date")
l_parameters.put (a_node.modification_date, "modification_date")
if
attached a_node.author as l_author and then
l_author.id > 0
then
l_parameters.put (l_author.id, "author_id")
else
-- New node
error_handler.reset
log.write_information (generator + ".save_node")
create l_parameters.make (7)
l_parameters.put (a_node.title, "title")
l_parameters.put (a_node.summary, "summary")
l_parameters.put (a_node.content, "content")
l_parameters.put (a_node.publication_date, "publication_date")
l_parameters.put (a_node.creation_date, "creation_date")
l_parameters.put (a_node.modification_date, "modification_date")
if
attached a_node.author as l_author and then
l_author.id > 0
then
l_parameters.put (l_author.id, "author_id")
else
l_parameters.put (0, "author_id")
end
sql_change (sql_insert_node, l_parameters)
l_parameters.put (0, "author_id")
end
sql_change (sql_insert_node, l_parameters)
sql_post_execution
if not error_handler.has_error then
a_node.set_id (last_inserted_node_id)
sql_post_execution
if not error_handler.has_error then
a_node.set_id (last_inserted_node_id)
sql_post_execution
end
end
end
@@ -178,9 +174,8 @@ feature -- Change: Node
sql_post_execution
end
update_node (a_user_id: like {CMS_USER}.id; a_node: CMS_NODE)
update_node (a_node: CMS_NODE)
-- Update node content `a_node'.
-- The user `a_user_id' is an existing or new collaborator.
local
l_parameters: STRING_TABLE [detachable ANY]
do
@@ -193,55 +188,64 @@ feature -- Change: Node
l_parameters.put (a_node.publication_date, "publication_date")
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_node.id, "id")
l_parameters.put (a_user_id, "editor")
if attached a_node.author as l_author then
l_parameters.put (l_author.id, "id")
l_parameters.put (l_author.id, "editor")
else
l_parameters.put (0, "id")
l_parameters.put (0, "editor")
end
sql_change (sql_update_node, l_parameters)
sql_post_execution
end
update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- Update node title to `a_title', node identified by id `a_node_id'.
-- The user `a_id' is an existing or new collaborator.
-- The user `a_user_id' is an existing or new collaborator.
local
l_parameters: STRING_TABLE [detachable ANY]
do
-- FIXME: unused a_user_id !
error_handler.reset
log.write_information (generator + ".update_node_title")
create l_parameters.make (3)
l_parameters.put (a_title, "title")
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_id, "id")
l_parameters.put (a_node_id, "id")
sql_change (sql_update_node_title, l_parameters)
sql_post_execution
end
update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- Update node summary to `a_summary', node identified by id `a_node_id'.
-- The user `a_id' is an existing or new collaborator.
-- The user `a_user_id' is an existing or new collaborator.
local
l_parameters: STRING_TABLE [detachable ANY]
do
-- FIXME: unused a_user_id !
error_handler.reset
log.write_information (generator + ".update_node_summary")
create l_parameters.make (3)
l_parameters.put (a_summary, "summary")
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_id, "id")
l_parameters.put (a_node_id, "id")
sql_change (sql_update_node_summary, l_parameters)
sql_post_execution
end
update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- Update node content to `a_content', node identified by id `a_node_id'.
-- The user `a_id' is an existing or new collaborator.
-- The user `a_user_id' is an existing or new collaborator.
local
l_parameters: STRING_TABLE [detachable ANY]
do
-- FIXME: unused a_user_id !
error_handler.reset
log.write_information (generator + ".update_node_content")
create l_parameters.make (3)
l_parameters.put (a_content, "content")
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_id, "id")
l_parameters.put (a_node_id, "id")
sql_change (sql_update_node_content, l_parameters)
sql_post_execution
end

View File

@@ -116,8 +116,10 @@ feature -- Change: Node
new_node (a_node: CMS_NODE)
-- Add a new node `a_node'
require
no_id: not a_node.has_id
do
storage.save_node (a_node)
storage.new_node (a_node)
end
delete_node (a_id: INTEGER_64)
@@ -126,37 +128,37 @@ feature -- Change: Node
storage.delete_node (a_id)
end
update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE)
-- Update node by id `a_id' with `a_node' data.
update_node (a_node: CMS_NODE)
-- Update node `a_node' data.
do
storage.update_node (a_id,a_node)
storage.update_node (a_node)
end
update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- Update node title, with user identified by `a_id', with node id `a_node_id' and a new title `a_title'.
do
debug ("refactor_fixme")
fixme ("Check preconditions")
end
storage.update_node_title (a_id,a_node_id,a_title)
storage.update_node_title (a_user_id, a_node_id, a_title)
end
update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- Update node summary, with user identified by `a_id', with node id `a_node_id' and a new summary `a_summary'.
update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- Update node summary, with user identified by `a_user_id', with node id `a_node_id' and a new summary `a_summary'.
do
debug ("refactor_fixme")
fixme ("Check preconditions")
end
storage.update_node_summary (a_id,a_node_id, a_summary)
storage.update_node_summary (a_user_id, a_node_id, a_summary)
end
update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- Update node content, with user identified by `a_id', with node id `a_node_id' and a new content `a_content'.
update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- Update node content, with user identified by `a_user_id', with node id `a_node_id' and a new content `a_content'.
do
debug ("refactor_fixme")
fixme ("Check preconditions")
end
storage.update_node_content (a_id,a_node_id, a_content)
storage.update_node_content (a_user_id, a_node_id, a_content)
end