| 
				
			 | 
			
			
				@@ -29,6 +29,7 @@ class Person(db.Model): 
			 | 
		
	
		
			
			| 
				29
			 | 
			
				29
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				30
			 | 
			
				30
			 | 
			
			
				     person_id = db.Column(db.Integer, primary_key=True) 
			 | 
		
	
		
			
			| 
				31
			 | 
			
				31
			 | 
			
			
				     name = db.Column(db.String, nullable=False) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+    active = db.Column(db.Boolean, nullable=False, default=False) 
			 | 
		
	
		
			
			| 
				32
			 | 
			
				33
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				33
			 | 
			
				34
			 | 
			
			
				     consumptions = db.relationship("Consumption", backref="person", lazy=True) 
			 | 
		
	
		
			
			| 
				34
			 | 
			
				35
			 | 
			
			
				  
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -136,6 +137,10 @@ def ping() -> None: 
			 | 
		
	
		
			
			| 
				136
			 | 
			
				137
			 | 
			
			
				 def get_people(): 
			 | 
		
	
		
			
			| 
				137
			 | 
			
				138
			 | 
			
			
				     """ Return a list of currently known people. """ 
			 | 
		
	
		
			
			| 
				138
			 | 
			
				139
			 | 
			
			
				     people = Person.query.order_by(Person.name).all() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				140
			 | 
			
			
				+    q = Person.query.order_by(Person.name) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				141
			 | 
			
			
				+    if request.args.get('active'): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				142
			 | 
			
			
				+        q = q.filter_by(active=bool(request.args.get('active'))) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				143
			 | 
			
			
				+    people = q.all() 
			 | 
		
	
		
			
			| 
				139
			 | 
			
				144
			 | 
			
			
				     result = [person.as_dict for person in people] 
			 | 
		
	
		
			
			| 
				140
			 | 
			
				145
			 | 
			
			
				     return jsonify(people=result) 
			 | 
		
	
		
			
			| 
				141
			 | 
			
				146
			 | 
			
			
				  
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -189,6 +194,20 @@ def add_consumption(person_id: int): 
			 | 
		
	
		
			
			| 
				189
			 | 
			
				194
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				190
			 | 
			
				195
			 | 
			
			
				     return jsonify(person=person.as_dict, consumption=consumption.as_dict), 201 
			 | 
		
	
		
			
			| 
				191
			 | 
			
				196
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				197
			 | 
			
			
				+@app.route("/people/<int:person_id>", methods=["PATCH"]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				198
			 | 
			
			
				+def update_person(person_id: int): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				199
			 | 
			
			
				+    person = Person.query.get_or_404(person_id) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				200
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				201
			 | 
			
			
				+    data = requests.json['person'] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				202
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				203
			 | 
			
			
				+    if 'active' in data: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				204
			 | 
			
			
				+        person.active = data['active'] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				205
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				206
			 | 
			
			
				+        db.session.add(person) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				207
			 | 
			
			
				+        db.session.commit() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				208
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				209
			 | 
			
			
				+        return jsonify(person=person) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				210
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				192
			 | 
			
				211
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				193
			 | 
			
				212
			 | 
			
			
				 @app.route("/people/<int:person_id>/add_consumption/<int:ct_id>", methods=["POST"]) 
			 | 
		
	
		
			
			| 
				194
			 | 
			
				213
			 | 
			
			
				 def add_consumption2(person_id: int, ct_id: int): 
			 |