From 312bcd70a6e87170aed56b5e60ca18191fb1c21f Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Wed, 8 Jan 2020 19:04:38 +0000 Subject: [PATCH] remove in-mem readings and refactor related items. --- app/api.py | 25 +++---------------------- app/services/get_services.py | 4 +--- app/swagger.yml | 36 +----------------------------------- 3 files changed, 5 insertions(+), 60 deletions(-) diff --git a/app/api.py b/app/api.py index ab261ab..a7a53a8 100644 --- a/app/api.py +++ b/app/api.py @@ -9,30 +9,11 @@ in the files in the /services/ folder. These functions are acting as very light controllers essentially. ''' -# The each value represents a light meter. -READINGS = [0, 0, 0] - def post_a_reading(light_meter, the_reading): - if light_meter == 1: - READINGS[0] = the_reading.get("reading") - elif light_meter == 2: - READINGS[1] = the_reading.get("reading") - elif light_meter == 3: - READINGS[2] = the_reading.get("reading") - return post_services.add_latest_reading(light_meter,the_reading) - + return post_services.add_latest_reading(light_meter,the_reading) + def get_latest(light_meter): - # YOU ARE UP TO HERE. NEED TO REFACTOR BACK INTO DATABASE FUNCTION - # BELOW THIS FUNCTION. YAML FILE NEEDS CLEANING UP TOO. - if light_meter == 1: - return READINGS[0] - elif light_meter == 2: - return READINGS[1] - elif light_meter == 3: - return READINGS[2] - -def get_latest_reading(light_meter): - return get_services.get_in_mem_reading(light_meter) + return get_services.get_latest_reading(light_meter) def get_all_readings(light_meter): return get_services.get_all_readings_from_table(light_meter) diff --git a/app/services/get_services.py b/app/services/get_services.py index 86c678d..1b154b9 100644 --- a/app/services/get_services.py +++ b/app/services/get_services.py @@ -12,9 +12,7 @@ at Ritherdon, you will need to head to the /post_services.py/ file. It should be in the same directory at this: /services/. ''' -def get_in_mem_reading(meter): - # Need to refactor in use an in-mem database. - # Currently grabbing from database. +def get_latest_reading(meter): if meter == 1: return get_m1_latest() elif meter == 2: diff --git a/app/swagger.yml b/app/swagger.yml index fff8ef7..804f29b 100644 --- a/app/swagger.yml +++ b/app/swagger.yml @@ -74,7 +74,7 @@ paths: /readings/latest/{light_meter}: get: - operationId: api.get_latest_reading + operationId: api.get_latest tags: - Request Readings summary: >- @@ -200,37 +200,3 @@ paths: schema: type: object additionalProperties: True - -# This is the in-mem. database URL. - /readings/late/{light_meter}: - get: - operationId: api.get_latest - tags: - - Request Readings - summary: >- - Returns latest from in-mem database. - description: >- - latest in-mem db reading - parameters: - - name: light_meter - in: path - description: >- - This is the Id. of the light meter which you are retrieving - the readings for. The Id. consists of a number between 1-3 - at the time of writing. - type: integer - required: True - responses: - 200: - description: >- - In-mem db latest value - schema: - type: object - properties: - reading: - type: integer - example: 34 - description: >- - This is the actual reading taken from the specified - light meter, at the time specified in this response - body (I.E. JSON object).