class Applied_Fortune(MethodView): def get(self, code): rows = db.query('SELECT liked FROM applied_fortune WHERE shortId = %s', code) if len(rows) == 1: return json.dumps(rows[0]) else: return 'Invalid code' def post(self, code): values = request.json # Validate that the required fields are present if 'rating' not in values: return 'Missing rating' # Update the value on the fortune db.query('UPDATE applied_fortune SET liked = %s WHERE shortId = %s', (values['rating'], code)) return 'Applied Fortune updated' applied_fortune_view = Applied_Fortune.as_view('applied_fortune') app.add_url_rule('/api/applied_fortune/like/<code>', view_func=applied_fortune_view, methods=['GET', 'POST',]) # # Helper Functions #
row['expires'] = row['expires'].strftime('%Y-%m-%d %H:%M:%S') return json.dumps(rows) def postPsychicProfile(self, psychicGuid, values): db.query( 'UPDATE psychic SET givenName = %s, fullName = %s, nickName = %s, surName = %s WHERE guid = %s', (values['givenName'], values['fullName'], values['nickName'], values['surName'], psychicGuid) ) return 'psychic updated' def postPsychicState(self, psychicGuid, values): db.query( 'UPDATE psychic SET active = %s WHERE guid = %s', (values['isActive'], psychicGuid) ) return 'psychic updated' psychic_view = Psychic.as_view('psychic') app.add_url_rule('/api/psychic/<psychicGuid>', defaults={'method': None}, view_func=psychic_view, methods=['GET',]) app.add_url_rule('/api/psychic/<psychicGuid>/<method>', view_func=psychic_view, methods=['GET', 'POST',]) # # Helper Functions #
db.query('DELETE FROM fortune WHERE guid = %s', fortuneGuid) return 'Fortune deleted' def postFortuneNetwork(self, fortuneGuid, values): if 'network' not in values: return 'Missing network' if values['network'] != 'twitter' and values['network'] != 'facebook': return 'Invalid network' db.query('UPDATE fortune SET service=%s WHERE guid = %s', (values['network'], fortuneGuid)) return 'Network Updated' fortune_view = Fortune.as_view('fortune') app.add_url_rule('/api/fortune/', defaults={'fortuneGuid': None, 'method': None}, view_func=fortune_view, methods=['GET',]) app.add_url_rule('/api/fortune/<fortuneGuid>', defaults={'method': None}, view_func=fortune_view, methods=['GET',]) app.add_url_rule('/api/fortune/<fortuneGuid>/<method>', view_func=fortune_view, methods=['GET', 'POST', ]) # # Helper Functions # def getFortuneStats(fortuneGuid): dataToReturn = {} data = db.query( 'SELECT name, appliedTime, student_client.service, liked, fortune.active AS \'fortuneActive\', fortune.createdTime AS \'fortuneCreatedTime\' FROM applied_fortune JOIN student_client on student_client.guid = applied_fortune.studentGuid JOIN fortune on applied_fortune.fortuneGuid = fortune.guid WHERE fortuneGuid = %s ORDER BY appliedTime', fortuneGuid )