Update API to use CMS_STORAGE
This commit is contained in:
@@ -34,7 +34,7 @@ feature -- Factory
|
||||
|
||||
if attached (create {JSON_CONFIGURATION}).new_database_configuration (l_layout.application_config_path) as l_database_config then
|
||||
create {DATABASE_CONNECTION_MYSQL} l_database.login_with_connection_string (l_database_config.connection_string)
|
||||
create l_api_service.make_with_database (l_database)
|
||||
create l_api_service.make (create {CMS_STORAGE_MYSQL}.make (l_database))
|
||||
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
||||
if (create {ROC_JSON_CONFIGURATION}).is_web_mode(l_layout.application_config_path) then
|
||||
Result.mark_web
|
||||
@@ -44,7 +44,7 @@ feature -- Factory
|
||||
set_successful
|
||||
else
|
||||
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
||||
create l_api_service.make_with_database (l_database)
|
||||
create l_api_service.make (create {CMS_STORAGE_NULL})
|
||||
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
||||
set_last_error ("Database Connections", generator + ".roc_config")
|
||||
log.write_error (generator + ".roc_config Error database connection" )
|
||||
@@ -58,7 +58,7 @@ feature -- Factory
|
||||
create l_email_service.make ((create {JSON_CONFIGURATION}).new_smtp_configuration(l_layout.application_config_path))
|
||||
|
||||
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
||||
create l_api_service.make_with_database (l_database)
|
||||
create l_api_service.make (create {CMS_STORAGE_NULL})
|
||||
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
||||
end
|
||||
rescue
|
||||
|
||||
@@ -158,12 +158,6 @@ feature -- Filters
|
||||
fh.custom_header.put_header ("X-ROCServer: " + version)
|
||||
l_filter := fh
|
||||
|
||||
-- Cors
|
||||
create {WSF_CORS_FILTER}f
|
||||
f.set_next (l_filter)
|
||||
l_filter := f
|
||||
|
||||
|
||||
-- Maintenance
|
||||
create {WSF_MAINTENANCE_FILTER} f
|
||||
f.set_next (l_filter)
|
||||
|
||||
@@ -54,7 +54,7 @@ feature -- HTTP Methods
|
||||
do
|
||||
|
||||
create l_page.make (req, "layout2.tpl")
|
||||
l_page.set_value (api_service.recent_nodes (5), "nodes")
|
||||
l_page.set_value (api_service.recent_nodes (0,5), "nodes")
|
||||
l_page.set_value (is_web, "web")
|
||||
l_page.set_value (roc_config.is_html, "html")
|
||||
l_page.send_to (res)
|
||||
|
||||
@@ -9,23 +9,21 @@ class
|
||||
inherit
|
||||
|
||||
SHARED_ERROR
|
||||
REFACTORING_HELPER
|
||||
|
||||
|
||||
create make_with_database
|
||||
create make
|
||||
|
||||
|
||||
feature -- Initialize
|
||||
|
||||
make_with_database (a_connection: DATABASE_CONNECTION)
|
||||
-- Create the API service
|
||||
require
|
||||
is_connected: a_connection.is_connected
|
||||
make (a_storage: CMS_STORAGE)
|
||||
-- Create the API service with an storege `a_storage'.
|
||||
do
|
||||
log.write_information (generator+".make_with_database is database connected? "+ a_connection.is_connected.out )
|
||||
create node_provider.make (a_connection)
|
||||
create user_provider.make (a_connection)
|
||||
post_node_provider_execution
|
||||
post_user_provider_execution
|
||||
storage := a_storage
|
||||
set_successful
|
||||
ensure
|
||||
storage_set: storage = a_storage
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -34,49 +32,27 @@ feature -- Access
|
||||
local
|
||||
l_security: SECURITY_PROVIDER
|
||||
do
|
||||
if attached user_provider.user_salt (l_auth_login) as l_hash then
|
||||
if attached user_provider.user_by_name (l_auth_login) as l_user then
|
||||
create l_security
|
||||
if
|
||||
attached l_user.password as l_password and then
|
||||
l_security.password_hash (l_auth_password, l_hash).is_case_insensitive_equal (l_password)
|
||||
then
|
||||
Result := True
|
||||
else
|
||||
log.write_information (generator + ".login_valid User: wrong username or password" )
|
||||
end
|
||||
else
|
||||
log.write_information (generator + ".login_valid User:" + l_auth_login + "does not exist" )
|
||||
end
|
||||
end
|
||||
post_user_provider_execution
|
||||
Result := storage.is_valid_credential (l_auth_login, l_auth_password)
|
||||
end
|
||||
|
||||
nodes: LIST[CMS_NODE]
|
||||
-- List of nodes.
|
||||
do
|
||||
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||
across node_provider.nodes as c loop
|
||||
Result.force (c.item)
|
||||
end
|
||||
post_node_provider_execution
|
||||
fixme ("Implementation")
|
||||
Result := storage.recent_nodes (0, 10)
|
||||
end
|
||||
|
||||
recent_nodes (a_rows: INTEGER): LIST[CMS_NODE]
|
||||
-- List of the `a_rows' most recent nodes.
|
||||
recent_nodes (a_offset, a_rows: INTEGER): LIST[CMS_NODE]
|
||||
-- List of the `a_rows' most recent nodes starting from `a_offset'.
|
||||
do
|
||||
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||
across node_provider.recent_nodes (0,a_rows) as c loop
|
||||
Result.force (c.item)
|
||||
end
|
||||
post_node_provider_execution
|
||||
Result := storage.recent_nodes (a_offset, a_rows)
|
||||
end
|
||||
|
||||
node (a_id: INTEGER_64): detachable CMS_NODE
|
||||
--
|
||||
-- Node by ID.
|
||||
do
|
||||
Result := node_provider.node (a_id)
|
||||
post_node_provider_execution
|
||||
fixme ("Check preconditions")
|
||||
Result := storage.node (a_id)
|
||||
end
|
||||
|
||||
|
||||
@@ -85,38 +61,35 @@ feature -- Node
|
||||
new_node (a_node: CMS_NODE)
|
||||
-- Add a new node
|
||||
do
|
||||
node_provider.new_node (a_node)
|
||||
post_node_provider_execution
|
||||
storage.save_node (a_node)
|
||||
end
|
||||
|
||||
delete_node (a_id: INTEGER_64)
|
||||
do
|
||||
node_provider.delete_node (a_id)
|
||||
post_node_provider_execution
|
||||
storage.delete_node (a_id)
|
||||
end
|
||||
|
||||
update_node (a_node: CMS_NODE)
|
||||
do
|
||||
node_provider.update_node (a_node)
|
||||
post_node_provider_execution
|
||||
storage.update_node (a_node)
|
||||
end
|
||||
|
||||
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
|
||||
do
|
||||
node_provider.update_node_title (a_id, a_title)
|
||||
post_node_provider_execution
|
||||
fixme ("Check preconditions")
|
||||
storage.update_node_title (a_id, a_title)
|
||||
end
|
||||
|
||||
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
|
||||
do
|
||||
node_provider.update_node_summary (a_id, a_summary)
|
||||
post_node_provider_execution
|
||||
fixme ("Check preconditions")
|
||||
storage.update_node_summary (a_id, a_summary)
|
||||
end
|
||||
|
||||
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
|
||||
do
|
||||
node_provider.update_node_content (a_id, a_content)
|
||||
post_node_provider_execution
|
||||
fixme ("Check preconditions")
|
||||
storage.update_node_content (a_id, a_content)
|
||||
end
|
||||
|
||||
|
||||
@@ -129,40 +102,17 @@ feature -- User
|
||||
attached a_user.password as l_password and then
|
||||
attached a_user.email as l_email
|
||||
then
|
||||
user_provider.new_user (a_user.name, l_password, l_email)
|
||||
storage.save_user (a_user)
|
||||
else
|
||||
-- set error
|
||||
fixme ("Add error")
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Post process
|
||||
|
||||
post_node_provider_execution
|
||||
do
|
||||
if node_provider.successful then
|
||||
set_successful
|
||||
else
|
||||
if attached node_provider.last_error then
|
||||
set_last_error_from_handler (node_provider.last_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
feature {NONE} -- Implemenataion
|
||||
|
||||
post_user_provider_execution
|
||||
do
|
||||
if user_provider.successful then
|
||||
set_successful
|
||||
else
|
||||
if attached user_provider.last_error then
|
||||
set_last_error_from_handler (user_provider.last_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
node_provider: NODE_DATA_PROVIDER
|
||||
-- Node Data provider.
|
||||
|
||||
user_provider: USER_DATA_PROVIDER
|
||||
-- User Data provider.
|
||||
storage: CMS_STORAGE
|
||||
-- Persistence storage
|
||||
|
||||
end
|
||||
|
||||
105
persistence/implementation/common/cms_storage_null.e
Normal file
105
persistence/implementation/common/cms_storage_null.e
Normal file
@@ -0,0 +1,105 @@
|
||||
note
|
||||
description: "Summary description for {CMS_STORAGE_NULL}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_STORAGE_NULL
|
||||
|
||||
inherit
|
||||
|
||||
CMS_STORAGE
|
||||
REFACTORING_HELPER
|
||||
|
||||
|
||||
feature -- Access: user
|
||||
|
||||
has_user: BOOLEAN
|
||||
-- Has any user?
|
||||
do
|
||||
end
|
||||
|
||||
|
||||
all_users: LIST [CMS_USER]
|
||||
do
|
||||
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
|
||||
end
|
||||
|
||||
user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER
|
||||
do
|
||||
end
|
||||
|
||||
is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Change: user
|
||||
|
||||
save_user (a_user: CMS_USER)
|
||||
-- Add a new user `a_user'.
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Access: node
|
||||
|
||||
nodes: LIST[CMS_NODE]
|
||||
-- List of nodes.
|
||||
do
|
||||
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||
end
|
||||
|
||||
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
|
||||
-- List of the `a_count' most recent nodes, starting from `a_lower'.
|
||||
do
|
||||
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||
end
|
||||
|
||||
node (a_id: INTEGER_64): detachable CMS_NODE
|
||||
--
|
||||
do
|
||||
end
|
||||
|
||||
|
||||
feature -- Node
|
||||
|
||||
save_node (a_node: CMS_NODE)
|
||||
-- Add a new node
|
||||
do
|
||||
end
|
||||
|
||||
delete_node (a_id: INTEGER_64)
|
||||
do
|
||||
end
|
||||
|
||||
update_node (a_node: CMS_NODE)
|
||||
do
|
||||
end
|
||||
|
||||
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
|
||||
do
|
||||
end
|
||||
|
||||
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
|
||||
do
|
||||
end
|
||||
|
||||
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
|
||||
do
|
||||
end
|
||||
|
||||
feature -- User
|
||||
|
||||
new_user (a_user: CMS_USER)
|
||||
-- Add a new user `a_user'.
|
||||
do
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user