summaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2023-10-08 10:10:40 -0700
committerAaron Parecki <aaron@parecki.com>2023-10-08 10:10:40 -0700
commit17c5d57fd05cb4ee5b0b189bd4cbf519fb636d41 (patch)
treea082fd06c900860c50b7921434c320dce6565f3e /controllers
parent88509de125bd382832228cdd2efcf7b259dcab2b (diff)
parent1c0432939a5381ffe1453e05401ec8e3b2ba4826 (diff)
Merge branch 'Zegnat-add-weight-posts'
Diffstat (limited to 'controllers')
-rw-r--r--controllers/controllers.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php
index b213f5b..7b7234c 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -412,6 +412,9 @@ $app->post('/settings/save', function() use($app) {
$user->micropub_syndicate_field = $params['syndicate_field'];
}
+ if(array_key_exists('weight_unit', $params) && $params['weight_unit'])
+ $user->weight_unit = $params['weight_unit'];
+
$user->save();
$app->response()['Content-type'] = 'application/json';
$app->response()->body(json_encode(array(
@@ -1036,3 +1039,44 @@ $app->get('/map-img', function() use($app) {
});
+function create_weight(&$user, $weight_num, $weight_unit) {
+ $micropub_request = array(
+ 'type' => ['h-entry'],
+ 'properties' => [
+ 'weight' => [[
+ 'type' => ['h-measure'],
+ 'properties' => [
+ 'num' => [$weight_num],
+ 'unit' => [$weight_unit]
+ ]
+ ]]
+ ]
+ );
+ $r = micropub_post_for_user($user, $micropub_request, null, true);
+
+ return $r;
+}
+
+$app->get('/weight', function() use($app){
+ if($user=require_login($app)) {
+ render('new-weight', array(
+ 'title' => 'New Weight',
+ 'unit' => $user->weight_unit
+ ));
+ }
+});
+
+$app->post('/weight', function() use($app) {
+ if($user=require_login($app)) {
+ $params = $app->request()->params();
+
+ $r = create_weight($user, $params['weight_num'], $user->weight_unit);
+ $location = $r['location'];
+
+ $app->response()['Content-type'] = 'application/json';
+ $app->response()->body(json_encode(array(
+ 'location' => $location,
+ 'error' => $r['error']
+ )));
+ }
+});