diff --git a/Vagrantfile b/Vagrantfile index 203385a..3b7acc6 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,7 +5,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "ubuntu/trusty64" - config.vm.network "forwarded_port", guest: 5432, host: 15432 + config.vm.network "forwarded_port", guest: 5432, host: 5432 config.vm.network "forwarded_port", guest: 5000, host: 15000 config.vm.network "forwarded_port", guest: 80, host:10080 config.vm.network "forwarded_port", guest: 15672, host: 15673 diff --git a/blockbuster/__init__.py b/blockbuster/__init__.py index 5a3baad..1f71476 100644 --- a/blockbuster/__init__.py +++ b/blockbuster/__init__.py @@ -1,6 +1,6 @@ __author__ = 'matt' -__version__ = '1.23.05' -__db_schema_version__ = '1.23.00' +__version__ = '1.24.00' +__db_schema_version__ = '1.24.00' from flask import Flask app = Flask(__name__) diff --git a/blockbuster/bb_dbconnector_pg.py b/blockbuster/bb_dbconnector_pg.py index b8fe88d..c349177 100644 --- a/blockbuster/bb_dbconnector_pg.py +++ b/blockbuster/bb_dbconnector_pg.py @@ -491,32 +491,20 @@ def db_stats_check(self): datetime.date.today().day) try: - sql = "SELECT * from stats_usage " \ + sql = "SELECT date::text, instance_name, name, count from v_stats_usage " \ "where date = %s;" data = (today,) - self.cursor.execute(sql, data) - rows = self.cursor.fetchall() - if len(rows) < 1: - return "No User Activity Today" - - stats = "" - if len(rows) > 1: - i = 0 - stats = "" - for row in rows: - statrow = str(row[0]) + ", " + str(row[1]) + ", " + str(row[2] + ", " + str(row[3])) - stats = stats + statrow + "
" - i += 1 - stats = stats + "" - - return stats, 200 + self.dict_cursor.execute(sql, data) + rows = self.dict_cursor.fetchall() + return rows except psycopg2.DatabaseError, e: self.log_exception(e) log.error("Error getting stats from database.\n" + str(e)) - return "500: Error retrieving stats from database", 500 + empty = {} + return {} # Take a mobile number, return a list of active blocks from that number def get_list_of_blocks_for_blocker(self, blocker_mobile): @@ -942,7 +930,7 @@ def api_blocks_getall(self): log.debug("Getting all blocks") try: - sql = "SELECT * from active_blocks;" + sql = "SELECT * from v_active_blocks;" self.dict_cursor.execute(sql,) rows = self.dict_cursor.fetchall() return rows diff --git a/blockbuster/bb_routes.py b/blockbuster/bb_routes.py index b60bce6..7261229 100644 --- a/blockbuster/bb_routes.py +++ b/blockbuster/bb_routes.py @@ -48,6 +48,7 @@ def decorated(*args, **kwargs): return f(*args, **kwargs) return decorated + # Core App Routes @app.route("/InboundSMS/", methods=['POST']) def post_inboundsms(): @@ -55,20 +56,23 @@ def post_inboundsms(): return bb_request_processor.process_twilio_request(request) -@app.route("/stats/", methods=['GET']) -def get_stats(): - stats = bb_api_request_processor.APIRequestProcessor().service_stats_get() - bb_auditlogger.BBAuditLoggerFactory().create().logAudit('app', 'GET_STATS', stats) - return stats - - @app.route("/status/", methods=['GET']) def get_status(): status = bb_api_request_processor.APIRequestProcessor().service_status_get() bb_auditlogger.BBAuditLoggerFactory().create().logAudit('app', 'GET_STATUS', status) return status + # API Routes +@app.route("/api/v1.0/stats/", methods=['GET']) +@requires_auth +def get_stats(): + result = bb_api_request_processor.APIRequestProcessor()\ + .service_stats_get() + bb_auditlogger.BBAuditLoggerFactory().create().logAudit('app', 'GET_STATS', str(result)) + return jsonify(stats=result) + + @app.route("/api/v1.0/cars/", methods=['GET']) @requires_auth def uri_get_cars(): diff --git a/run.py b/run.py index ca668fd..6d93de1 100644 --- a/run.py +++ b/run.py @@ -24,4 +24,4 @@ # This section only applies when you are running run.py directly if __name__ == '__main__': blockbuster.bb_logging.logger.info("Running http on port 5000") - blockbuster.app.run(host='0.0.0.0') \ No newline at end of file + blockbuster.app.run(host='0.0.0.0', debug=True) \ No newline at end of file diff --git a/sql/008_1.23.00-1.24.00.sql b/sql/008_1.23.00-1.24.00.sql new file mode 100644 index 0000000..d0acbb6 --- /dev/null +++ b/sql/008_1.23.00-1.24.00.sql @@ -0,0 +1,50 @@ +BEGIN; + +-- Rename the status_usage view to use v_XXXXXX naming convention +ALTER VIEW IF EXISTS stats_usage RENAME TO v_stats_usage; +ALTER VIEW IF EXISTS active_move_requests RENAME TO v_active_move_requests; +ALTER VIEW IF EXISTS active_blocks RENAME TO v_active_blocks; + + +-- Create Table: tbl_users_api +CREATE TABLE tbl_users_api +( + api_user_ref uuid NOT NULL DEFAULT uuid_generate_v4(), + username text NOT NULL, + password text NOT NULL DEFAULT 0, + enabled boolean NOT NULL DEFAULT true, + CONSTRAINT tbl_users_api_pkey PRIMARY KEY (api_user_ref), + CONSTRAINT tbl_users_api_username_key UNIQUE (username) +) +WITH ( + OIDS=FALSE +); +ALTER TABLE tbl_users_api + OWNER TO blockbuster; + + +-- Create Index: username +CREATE INDEX username + ON tbl_users_api + USING btree + (username COLLATE pg_catalog."default"); + +-- Index: mobile +CREATE INDEX mobile + ON users + USING btree + (mobile COLLATE pg_catalog."default"); + +-- Index: registration +CREATE INDEX registration + ON registrations + USING btree + (registration COLLATE pg_catalog."default"); + + +-- Update schema version to 1.24.00 +UPDATE general +SET value = '1.24.00' +WHERE key = 'version'; + +COMMIT; diff --git a/sql/UpgradeDB.sql b/sql/UpgradeDB.sql index 1b2908e..3e5cd0a 100644 --- a/sql/UpgradeDB.sql +++ b/sql/UpgradeDB.sql @@ -4,4 +4,5 @@ \i ./004_1.18.00-1.19.00.sql \i ./005_1.19.00-1.20.00.sql \i ./006_1.20.00-1.20.01.sql -\i ./007_1.20.01-1.23.00.sql \ No newline at end of file +\i ./007_1.20.01-1.23.00.sql +\i ./008_1.23.00-1.24.00.sql \ No newline at end of file