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]) sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
do 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 db_handler.execute_query
end end
sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
do 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 db_handler.execute_change
end end

View File

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

View File

@@ -126,7 +126,7 @@ feature -- Access: node
feature -- Node feature -- Node
save_node (a_node: CMS_NODE) new_node (a_node: CMS_NODE)
-- Add a new node -- Add a new node
do do
end end
@@ -136,22 +136,22 @@ feature -- Node
do do
end end
update_node (a_id: like {CMS_NODE}.id; a_node: CMS_NODE) update_node (a_node: CMS_NODE)
-- <Precursor> -- <Precursor>
do do
end 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> -- <Precursor>
do do
end 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> -- <Precursor>
do do
end 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> -- <Precursor>
do do
end end

View File

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

View File

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

View File

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