def saveUserData(self): mydb = s3DB.s3DB('users') mydb.bucket = "tbos-data" mydb.index = "user_id" user = dict(self.toJSON()) user.pop('entries') mydb.save(user)
def load(self, user_id, year): mydb = s3DB.s3DB('entries') mydb.bucket = "tbos-data" all_entries = mydb.load(year) user_entries = { "1": [], "2": [], "3": [], "4": [], "5": [], "6": [], "7": [] } if all_entries: if all_entries['months']: for month in all_entries['months']: current_month = month['month'] for day in month['days']: current_day = day['day'] for entry in day['entries']: if entry['user_id'] == user_id: user_entries[entry['type']].append( date(year, current_month, current_day).strftime("%Y-%m-%d")) return user_entries
def add_user(): user = request.get_json() mydb = s3DB.s3DB('users') mydb.bucket = "tbos-data" mydb.index = "principalID" #user = {"name": "Dan Danciu", "age": 23} mydb.save(user) return jsonify({"message": "User added."}), 200
def delete_user(): user = request.get_json() mydb = s3DB.s3DB('users') mydb.bucket = "tbos-data" if 'name' in user: if mydb.delete(user["name"]): return jsonify(f"User {user['name']} deleted" ), 200 else: return jsonify("User name not specified"), 404
def save(self, user_id, year): mydb = s3DB.s3DB('entries') mydb.bucket = "tbos-data" mydb.index = "year" data = mydb.load(year) if data: data[user_id] = self.toJSON() else: data = {'year': year, 'months': []} mydb.save(data)
def load(self, user_id): mydb = s3DB.s3DB('users') mydb.bucket = "tbos-data" user = mydb.load(user_id) return user
def save(self): mydb = s3DB.s3DB('all_users') mydb.bucket = "tbos-data" mydb.index = 'index' mydb.save(self.toJSON())
def load(self): mydb = s3DB.s3DB('all_users') mydb.bucket = "tbos-data" user_list = mydb.load('all_users') return user_list
def load(self, year): mydb = s3DB.s3DB('entries') mydb.bucket = "tbos-data" entries = mydb.load(year) return entries