Use custom Result/Option types
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use BitBadger\InspiredByFSharp\Option;
|
||||
use BitBadger\PDODocument\{DocumentException, Patch};
|
||||
use FeedReaderCentral\{ItemWithFeed, Table};
|
||||
|
||||
@@ -18,22 +19,21 @@ include '../start.php';
|
||||
FeedReaderCentral\Security::verifyUser();
|
||||
|
||||
$id = key_exists('id', $_GET) ? (int)$_GET['id'] : -1;
|
||||
$item = ItemWithFeed::retrieveById($id)->getOrCall(not_found(...));
|
||||
$item = Option::getOrCall(not_found(...), ItemWithFeed::retrieveById($id));
|
||||
|
||||
if (key_exists('action', $_GET)) {
|
||||
$flag = match ($_GET['action']) {
|
||||
'add' => 1,
|
||||
'remove' => 0,
|
||||
default => null
|
||||
};
|
||||
if (isset($flag)) {
|
||||
Option::iter(function (int $flag) use ($id, &$item) {
|
||||
try {
|
||||
Patch::byId(Table::Item, $id, ['is_bookmarked' => $flag]);
|
||||
$item->is_bookmarked = $flag;
|
||||
} catch (DocumentException $ex) {
|
||||
add_error("$ex");
|
||||
}
|
||||
}
|
||||
}, match ($_GET['action']) {
|
||||
'add' => Option::Some(1),
|
||||
'remove' => Option::Some(0),
|
||||
default => Option::None(),
|
||||
});
|
||||
}
|
||||
|
||||
$action = $item->isBookmarked() ? 'remove' : 'add';
|
||||
|
||||
Reference in New Issue
Block a user