-
Notifications
You must be signed in to change notification settings - Fork 18
Issue #601 fieldnotes #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
2ce5c31
68dcca8
b237808
29bdd99
1cb7fe6
0ac5c6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,38 @@ public static function call(OkapiRequest $request) | |
| $result['has_image_positions'] = Settings::get('OC_BRANCH') == 'oc.de'; | ||
| $result['has_ratings'] = Settings::get('OC_BRANCH') == 'oc.pl'; | ||
| $result['geocache_passwd_max_length'] = Db::field_length('caches', 'logpw'); | ||
| if (Settings::get('OC_BRANCH') == 'oc.de') { | ||
| $result['has_draft_logs'] = true; | ||
| $result['has_lists'] = true; | ||
| $result['cache_types'] = self::get_cache_types(); | ||
| $result['log_types'] = self::get_log_types(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing from the documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why wasn’t it possible to use |
||
|
|
||
| } | ||
|
|
||
| return Okapi::formatted_response($request, $result); | ||
| } | ||
|
|
||
| private static function get_cache_types() { | ||
| $rs = Db::query(" | ||
| SELECT name | ||
| FROM cache_type; | ||
| "); | ||
| $cache_types = []; | ||
| while ($row = Db::fetch_assoc($rs)) { | ||
| $cache_types[] = $row['name']; | ||
| } | ||
| return $cache_types; | ||
| } | ||
|
|
||
| private static function get_log_types() { | ||
| $rs = Db::query(" | ||
| SELECT name | ||
| FROM log_types; | ||
| "); | ||
| $log_types = []; | ||
| while ($row = Db::fetch_assoc($rs)) { | ||
| $log_types[] = $row['name']; | ||
| } | ||
| return $log_types; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| <?php | ||
|
|
||
| namespace okapi\services\caches\save_user_coords; | ||
|
|
||
| use okapi\core\Db; | ||
| use okapi\core\Exception\ParamMissing; | ||
| use okapi\core\Exception\InvalidParam; | ||
| use okapi\core\Okapi; | ||
| use okapi\core\OkapiServiceRunner; | ||
| use okapi\core\Request\OkapiInternalRequest; | ||
| use okapi\core\Request\OkapiRequest; | ||
| use okapi\Settings; | ||
|
|
||
| class WebService | ||
| { | ||
| public static function options() | ||
| { | ||
| return array( | ||
| 'min_auth_level' => 3 | ||
| ); | ||
| } | ||
|
|
||
| public static function call(OkapiRequest $request) | ||
| { | ||
|
|
||
| $user_coords = $request->get_parameter('user_coords'); | ||
| if ($user_coords == null) | ||
| throw new ParamMissing('user_coords'); | ||
| $parts = explode('|', $user_coords); | ||
| if (count($parts) != 2) | ||
| throw new InvalidParam('user_coords', "Expecting 2 pipe-separated parts, got ".count($parts)."."); | ||
| foreach ($parts as &$part_ref) | ||
| { | ||
| if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) | ||
| throw new InvalidParam('user_coords', "'$part_ref' is not a valid float number."); | ||
| $part_ref = floatval($part_ref); | ||
| } | ||
| list($latitude, $longitude) = $parts; | ||
|
|
||
| # Verify cache_code | ||
|
|
||
| $cache_code = $request->get_parameter('cache_code'); | ||
| if ($cache_code == null) | ||
| throw new ParamMissing('cache_code'); | ||
| $geocache = OkapiServiceRunner::call( | ||
| 'services/caches/geocache', | ||
| new OkapiInternalRequest($request->consumer, $request->token, array( | ||
| 'cache_code' => $cache_code, | ||
| 'fields' => 'internal_id' | ||
| )) | ||
| ); | ||
| $cache_id = $geocache['internal_id']; | ||
|
|
||
| self::update_notes($cache_id, $request->token->user_id, $latitude, $longitude); | ||
|
|
||
| $ret_value = 'ok'; | ||
|
|
||
| $result = array( | ||
| 'status' => $ret_value | ||
| ); | ||
| return Okapi::formatted_response($request, $result); | ||
| } | ||
|
|
||
| private static function update_notes($cache_id, $user_id, $latitude, $longitude) | ||
| { | ||
| /* See: | ||
| * | ||
| * - https://github.com/OpencachingDeutschland/oc-server3/tree/development/htdocs/src/Oc/Libse/CacheNote | ||
| * - https://www.opencaching.de/okapi/devel/dbstruct | ||
| */ | ||
|
|
||
| $rs = Db::query(" | ||
| select max(id) as id | ||
| from coordinates | ||
| where | ||
| type = 2 -- personal note | ||
| and cache_id = '".Db::escape_string($cache_id)."' | ||
| and user_id = '".Db::escape_string($user_id)."' | ||
| "); | ||
| $id = null; | ||
| if($row = Db::fetch_assoc($rs)) { | ||
| $id = $row['id']; | ||
| } | ||
| if ($id == null) { | ||
| Db::query(" | ||
| insert into coordinates ( | ||
| type, latitude, longitude, cache_id, user_id | ||
| ) values ( | ||
| 2, | ||
| '".Db::escape_string($latitude)."', | ||
| '".Db::escape_string($longitude)."', | ||
| '".Db::escape_string($cache_id)."', | ||
| '".Db::escape_string($user_id)."' | ||
| ) | ||
| "); | ||
| } else { | ||
| Db::query(" | ||
| update coordinates | ||
| set latitude = '".Db::escape_string($latitude)."', | ||
| longitude = '".Db::escape_string($longitude)."', | ||
| where | ||
| id = '".Db::escape_string($id)."' | ||
| and type = 2 | ||
| "); | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <xml> | ||
| <brief>Update personal coordinates of a geocache</brief> | ||
| <issue-id>629</issue-id> | ||
| <desc> | ||
| <p>This method allows your users to update the coordinates of their | ||
| personal geocache coordinates.</p> | ||
|
|
||
| <p>Current personal coordinates for the geocache can be retrieved | ||
| using the <b>alt_wpts</b> field in the | ||
| <a href="%OKAPI:methodargref:services/caches/geocache#fields%">services/caches/geocache</a> | ||
| method.</p> | ||
| </desc> | ||
| <req name='cache_code'> | ||
| <p>Code of the geocache</p> | ||
| </req> | ||
| <req name='user_coords'> | ||
| <p>The coordinates are defined by a string in the format "lat|lon"</p> | ||
| <p>Use positive numbers for latitudes in the northern hemisphere and longitudes | ||
| in the eastern hemisphere (and negative for southern and western hemispheres | ||
| accordingly). These are full degrees with a dot as a decimal point (ex. "48.7|15.89").</p> | ||
| </req> | ||
| <common-format-params/> | ||
| <returns> | ||
| <p>A dictionary of the following structure:</p> | ||
| <ul> | ||
| <li>status - ok</li> | ||
| </ul> | ||
| </returns> | ||
| </xml> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not fully convinced that conditionally omitting these fields is the best approach.
The docs say "Only present on installations where it is true", but from a practical API consistency point of view it might be better to always return these fields and use false for installations where the feature is not supported. That would make the response structure stable and easier to consume on the client side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$result['has_lists']is currently missing from documentation.I see it is already documented in the next PR, but since this value is already being returned here, it should probably be documented in this PR as well. Otherwise, if only this PR gets merged, the API response will include a field that is not described anywhere.