Skip to content

issue #628 save_user_coords#629

Open
hxdimpf wants to merge 3 commits intoopencaching:masterfrom
hxdimpf:save_user-coords
Open

issue #628 save_user_coords#629
hxdimpf wants to merge 3 commits intoopencaching:masterfrom
hxdimpf:save_user-coords

Conversation

@hxdimpf
Copy link
Copy Markdown

@hxdimpf hxdimpf commented Nov 23, 2023

This is about adding a new service endpoint. The platforms (opencaching.xx) provide the capabilities to maintain a personal cache notes field for each cache. In addition with this there is also a capability to store user provided coordinates for instance the coordinates that are the result of solving a puzzle.

The OKAPI provides a service to retrieve the personal caches notes and also the user_coords. It also provides a service to update the personal cache notes but not the user coords.

I have implemented a new service to fill this gap. First I thought about extending the already existing service

:: services/caches/save_personal_notes

however, to make sure that this doesn't create any adverse side effects for existing client applications I decided to implement a new service:
:: services/caches/save_user_coords.

Comment thread okapi/services/caches/save_user_coords/docs.xml Outdated
Comment thread okapi/services/caches/save_user_coords/docs.xml
Comment thread okapi/services/caches/save_user_coords/docs.xml
Comment thread okapi/services/caches/save_user_coords/docs.xml Outdated
Comment thread okapi/services/caches/save_user_coords/WebService.php Outdated
Comment thread okapi/services/caches/save_user_coords/WebService.php
@hxdimpf hxdimpf force-pushed the save_user-coords branch 2 times, most recently from 091137a to ad8b421 Compare November 23, 2023 19:16
hxdimpf

This comment was marked as resolved.

@hxdimpf hxdimpf force-pushed the save_user-coords branch 2 times, most recently from cccc1cd to 4a5f2f4 Compare November 23, 2023 20:55
hxdimpf

This comment was marked as resolved.

@hxdimpf hxdimpf force-pushed the save_user-coords branch 4 times, most recently from e8d3b16 to 0462c38 Compare November 24, 2023 09:54
@hxdimpf hxdimpf requested a review from wrygiel November 24, 2023 09:57
@bekuno
Copy link
Copy Markdown
Contributor

bekuno commented Nov 27, 2023

If you want a feedback from c:geo side, please open an issue there.

Comment thread okapi/services/caches/save_user_coords/WebService.php Outdated
Comment thread okapi/services/caches/save_user_coords/docs.xml
@hxdimpf hxdimpf requested a review from wrygiel December 9, 2023 11:11
Use a simple '' instead of Db::escape_string("") for the empty
description value in the INSERT statement.
Comment on lines +109 to +143
else # oc.pl branch
{
$rs = Db::query("
select max(id) as id
from cache_mod_cords
where
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 cache_mod_cords (
cache_id, user_id, latitude, longitude
) values (
'".Db::escape_string($cache_id)."',
'".Db::escape_string($user_id)."',
'".Db::escape_string($latitude)."',
'".Db::escape_string($longitude)."'
)
");
} else {
Db::query("
update cache_mod_cords
set latitude = '".Db::escape_string($latitude)."',
longitude = '".Db::escape_string($longitude)."'
where
id = '".Db::escape_string($id)."'
");
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OCPL cache_mod_cords table does not contain an id column.

create table cache_mod_cords
(
	cache_id int not null,
	user_id int not null,
	date timestamp default current_timestamp() not null,
	longitude double not null,
	latitude double not null,
	primary key (cache_id, user_id)
)

it should look something like this:

else # oc.pl branch
{
    Db::query("
        INSERT INTO cache_mod_cords (
            cache_id,
            user_id,
            latitude,
            longitude,
            date
        ) VALUES (
            '".Db::escape_string($cache_id)."',
            '".Db::escape_string($user_id)."',
            '".Db::escape_string($latitude)."',
            '".Db::escape_string($longitude)."',
            NOW()
        )
        ON DUPLICATE KEY UPDATE
            latitude = VALUES(latitude),
            longitude = VALUES(longitude),
            date = NOW()
    ");
}

Additionally, in OCPL only some cache types support user coordinates:
https://github.com/opencaching/opencaching-pl/blob/30ae3a4681c6840fe5aad454ccdb50fdb1340603/src/Controllers/ViewCacheController.php#L646-L648

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants