From 7313b9b0cda72276aa55c0742277f00dbc480a49 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Tue, 28 Jan 2025 18:15:49 +0100 Subject: [PATCH] wip: 2025-01-28T15:01:10+0100 (1738072870) --- .env.example.ini | 20 +- api/.env.example.ini | 6 +- api/endpoints/messages/POST.php | 51 ----- api/endpoints/work/GET.php | 107 --------- api/endpoints/work/actions/DELETE.php | 38 --- api/endpoints/work/actions/GET.php | 48 ---- api/endpoints/work/permalinks/GET.php | 52 ----- api/endpoints/work/tags/DELETE.php | 42 ---- api/endpoints/work/tags/GET.php | 51 ----- api/endpoints/work/tags/POST.php | 63 ----- api/src/databases/VLWdb.php | 101 -------- .../models/Battlestation/Config/ChassisMb.php | 14 -- .../models/Battlestation/Config/MbGpu.php | 14 -- .../models/Battlestation/Config/MbPsu.php | 14 -- api/src/databases/models/Work/WorkMedia.php | 10 - api/src/databases/models/Work/WorkTags.php | 21 -- composer.json | 4 +- composer.lock | 83 +++++-- .../about/languages/DELETE.php | 3 +- .../about/languages/GET.php | 7 +- .../about/languages/POST.php | 3 +- .../battlestation/GET.php | 22 +- .../battlestation/chassis/GET.php | 52 ++--- .../battlestation/coolers/GET.php | 28 +-- .../battlestation/cpu/GET.php | 58 +++-- .../battlestation/dram/GET.php | 62 +++-- .../battlestation/gpu/GET.php | 58 +++-- .../battlestation/mb/GET.php | 106 ++++----- .../battlestation/psu/GET.php | 54 ++--- .../battlestation/storage/GET.php | 58 +++-- endpoints/messages/POST.php | 47 ++++ {api/endpoints => endpoints}/search/GET.php | 28 +-- {api/endpoints => endpoints}/work/DELETE.php | 38 ++- endpoints/work/GET.php | 55 +++++ {api/endpoints => endpoints}/work/PATCH.php | 58 +++-- {api/endpoints => endpoints}/work/POST.php | 62 +++-- endpoints/work/actions/DELETE.php | 32 +++ endpoints/work/actions/GET.php | 44 ++++ .../work/actions/POST.php | 44 ++-- endpoints/work/permalinks/GET.php | 48 ++++ .../work/permalinks/POST.php | 36 ++- endpoints/work/tags/DELETE.php | 38 +++ endpoints/work/tags/GET.php | 47 ++++ endpoints/work/tags/POST.php | 59 +++++ public/about/battlestation.php | 216 +++++++++--------- public/contact.php | 12 +- public/search.php | 20 +- public/work.php | 10 +- public/work/timeline.php | 52 ++--- src/{client => API}/API.php | 6 +- {api/src => src/API}/Endpoints.php | 21 +- src/Database/Database.php | 37 +++ src/Database/Models/Model.php | 34 +++ src/Database/Models/Timeline/Timeline.php | 41 ++++ src/Database/Models/Work/Work.php | 5 + .../Tables}/Battlestation/Chassis.php | 8 +- .../Tables/Battlestation/Config/ChassisMb.php | 14 ++ .../Tables}/Battlestation/Config/Config.php | 6 +- .../Battlestation/Config/MbCpuCooler.php | 6 +- .../Tables}/Battlestation/Config/MbDram.php | 8 +- .../Tables/Battlestation/Config/MbGpu.php | 14 ++ .../Tables/Battlestation/Config/MbPsu.php | 14 ++ .../Battlestation/Config/MbStorage.php | 8 +- .../Tables}/Battlestation/Coolers.php | 6 +- .../Database/Tables}/Battlestation/Cpu.php | 8 +- .../Database/Tables}/Battlestation/Dram.php | 8 +- .../Database/Tables}/Battlestation/Gpu.php | 8 +- .../Database/Tables}/Battlestation/Mb.php | 8 +- .../Database/Tables}/Battlestation/Psu.php | 8 +- .../Tables}/Battlestation/Storage.php | 8 +- .../Database/Tables}/Messages/Messages.php | 6 +- .../Database/Tables/Work/Actions.php | 6 +- src/Database/Tables/Work/Media.php | 10 + .../Database/Tables/Work/Namespaces.php | 6 +- .../Database/Tables/Work/Permalinks.php | 6 +- src/Database/Tables/Work/Tags.php | 21 ++ .../Database/Tables}/Work/Work.php | 8 +- 77 files changed, 1220 insertions(+), 1315 deletions(-) delete mode 100755 api/endpoints/messages/POST.php delete mode 100755 api/endpoints/work/GET.php delete mode 100755 api/endpoints/work/actions/DELETE.php delete mode 100644 api/endpoints/work/actions/GET.php delete mode 100755 api/endpoints/work/permalinks/GET.php delete mode 100755 api/endpoints/work/tags/DELETE.php delete mode 100644 api/endpoints/work/tags/GET.php delete mode 100755 api/endpoints/work/tags/POST.php delete mode 100755 api/src/databases/VLWdb.php delete mode 100644 api/src/databases/models/Battlestation/Config/ChassisMb.php delete mode 100644 api/src/databases/models/Battlestation/Config/MbGpu.php delete mode 100644 api/src/databases/models/Battlestation/Config/MbPsu.php delete mode 100644 api/src/databases/models/Work/WorkMedia.php delete mode 100644 api/src/databases/models/Work/WorkTags.php rename {api/endpoints => endpoints}/about/languages/DELETE.php (92%) rename {api/endpoints => endpoints}/about/languages/GET.php (90%) rename {api/endpoints => endpoints}/about/languages/POST.php (98%) rename {api/endpoints => endpoints}/battlestation/GET.php (71%) rename {api/endpoints => endpoints}/battlestation/chassis/GET.php (55%) rename {api/endpoints => endpoints}/battlestation/coolers/GET.php (78%) rename {api/endpoints => endpoints}/battlestation/cpu/GET.php (59%) rename {api/endpoints => endpoints}/battlestation/dram/GET.php (54%) rename {api/endpoints => endpoints}/battlestation/gpu/GET.php (54%) rename {api/endpoints => endpoints}/battlestation/mb/GET.php (57%) rename {api/endpoints => endpoints}/battlestation/psu/GET.php (56%) rename {api/endpoints => endpoints}/battlestation/storage/GET.php (55%) create mode 100644 endpoints/messages/POST.php rename {api/endpoints => endpoints}/search/GET.php (62%) mode change 100755 => 100644 rename {api/endpoints => endpoints}/work/DELETE.php (51%) mode change 100755 => 100644 create mode 100644 endpoints/work/GET.php rename {api/endpoints => endpoints}/work/PATCH.php (59%) mode change 100755 => 100644 rename {api/endpoints => endpoints}/work/POST.php (55%) mode change 100755 => 100644 create mode 100644 endpoints/work/actions/DELETE.php create mode 100644 endpoints/work/actions/GET.php rename {api/endpoints => endpoints}/work/actions/POST.php (50%) mode change 100755 => 100644 create mode 100644 endpoints/work/permalinks/GET.php rename {api/endpoints => endpoints}/work/permalinks/POST.php (50%) mode change 100755 => 100644 create mode 100644 endpoints/work/tags/DELETE.php create mode 100644 endpoints/work/tags/GET.php create mode 100644 endpoints/work/tags/POST.php rename src/{client => API}/API.php (70%) rename {api/src => src/API}/Endpoints.php (65%) create mode 100644 src/Database/Database.php create mode 100644 src/Database/Models/Model.php create mode 100644 src/Database/Models/Timeline/Timeline.php create mode 100644 src/Database/Models/Work/Work.php rename {api/src/databases/models => src/Database/Tables}/Battlestation/Chassis.php (70%) create mode 100644 src/Database/Tables/Battlestation/Config/ChassisMb.php rename {api/src/databases/models => src/Database/Tables}/Battlestation/Config/Config.php (57%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Config/MbCpuCooler.php (70%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Config/MbDram.php (60%) create mode 100644 src/Database/Tables/Battlestation/Config/MbGpu.php create mode 100644 src/Database/Tables/Battlestation/Config/MbPsu.php rename {api/src/databases/models => src/Database/Tables}/Battlestation/Config/MbStorage.php (69%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Coolers.php (72%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Cpu.php (82%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Dram.php (79%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Gpu.php (72%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Mb.php (78%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Psu.php (78%) rename {api/src/databases/models => src/Database/Tables}/Battlestation/Storage.php (82%) rename {api/src/databases/models => src/Database/Tables}/Messages/Messages.php (68%) rename api/src/databases/models/Work/WorkActions.php => src/Database/Tables/Work/Actions.php (69%) create mode 100644 src/Database/Tables/Work/Media.php rename api/src/databases/models/Work/WorkNamespaces.php => src/Database/Tables/Work/Namespaces.php (68%) rename api/src/databases/models/Work/WorkPermalinks.php => src/Database/Tables/Work/Permalinks.php (55%) create mode 100644 src/Database/Tables/Work/Tags.php rename {api/src/databases/models => src/Database/Tables}/Work/Work.php (76%) diff --git a/.env.example.ini b/.env.example.ini index 8d9449e..b0dc222 100755 --- a/.env.example.ini +++ b/.env.example.ini @@ -1,7 +1,17 @@ -[api] +date_time_zone = "Europe/Stockholm" + +[api_database] +host = "" +user = "" +pass = "" +db = "" + +[api_forgejo] +base_url = "" +cache_file = "" +scan_profiles = "" + +[api_client] base_url = "https://api.vlw.one/" api_key = "" -verify_peer = 0 - -[time] -date_time_zone = "Europe/Stockholm" \ No newline at end of file +verify_peer = 0 \ No newline at end of file diff --git a/api/.env.example.ini b/api/.env.example.ini index 04c3c11..2e6e01e 100755 --- a/api/.env.example.ini +++ b/api/.env.example.ini @@ -1,7 +1,7 @@ [connect] -host = "" -user = "" -pass = "" +database_host = "" +database_user = "" +database_pass = "" [databases] vlw = "" diff --git a/api/endpoints/messages/POST.php b/api/endpoints/messages/POST.php deleted file mode 100755 index f8761b4..0000000 --- a/api/endpoints/messages/POST.php +++ /dev/null @@ -1,51 +0,0 @@ -ruleset = new Ruleset(strict: true); - - $this->ruleset->POST([ - (new Rules(MessagesModel::EMAIL->value)) - ->type(Type::STRING) - ->max(255) - ->default(null), - - (new Rules(MessagesModel::MESSAGE->value)) - ->required() - ->type(Type::STRING) - ->min(1) - ->max(parent::MYSQL_TEXT_MAX_LENGTH) - ]); - - parent::__construct(Databases::VLW, $this->ruleset); - } - - public function main(): Response { - // Use copy of request body as entity - $entity = $_POST; - - $entity[MessagesModel::ID->value] = parent::gen_uuid4(); - $entity[MessagesModel::DATE_CREATED->value] = time(); - - return $this->db->for(MessagesModel::TABLE)->insert($entity) === true - ? new Response($entity[MessagesModel::ID->value], 201) - : new Response("Failed to create message", 500); - } - } \ No newline at end of file diff --git a/api/endpoints/work/GET.php b/api/endpoints/work/GET.php deleted file mode 100755 index 21f3046..0000000 --- a/api/endpoints/work/GET.php +++ /dev/null @@ -1,107 +0,0 @@ -ruleset = new Ruleset(strict: true); - - $this->ruleset->GET([ - (new Rules(WorkModel::ID->value)) - ->type(Type::STRING) - ->min(1) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - - (new Rules(WorkModel::TITLE->value)) - ->type(Type::STRING) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - - (new Rules(WorkModel::SUMMARY->value)) - ->type(Type::STRING) - ->max(parent::MYSQL_TEXT_MAX_LENGTH), - - (new Rules(WorkModel::IS_LISTED->value)) - ->type(Type::BOOLEAN) - ->default(true), - - (new Rules(WorkModel::DATE_MODIFIED->value)) - ->type(Type::NUMBER) - ->min(1) - ->max(parent::MYSQL_INT_MAX_LENGTH), - - (new Rules(WorkModel::DATE_CREATED->value)) - ->type(Type::NUMBER) - ->min(1) - ->max(parent::MYSQL_INT_MAX_LENGTH), - - (new Rules(PARAM_LIMIT)) - ->type(Type::NUMBER) - ->type(Type::NULL) - ->min(1) - ->max(parent::MYSQL_INT_MAX_LENGTH) - ->default(null) - ]); - - parent::__construct(Databases::VLW, $this->ruleset); - } - - public function main(): Response { - // Use search parameters from model as filters - $filters = $_GET; - // Unset keys not included in database model from filter - foreach (array_diff(array_keys($_GET), WorkModel::values()) as $k) { - unset($filters[$k]); - } - - // Do a wildcard search on the title column if provided - if (array_key_exists(WorkModel::TITLE->value, $_GET)) { - $filters[WorkModel::TITLE->value] = [ - "LIKE" => "%{$_GET[WorkModel::TITLE->value]}%" - ]; - } - - // Do a wildcard search on the summary column if provided - if (array_key_exists(WorkModel::SUMMARY->value, $_GET)) { - $filters[WorkModel::SUMMARY->value] = [ - "LIKE" => "%{$_GET[WorkModel::SUMMARY->value]}%" - ]; - } - - $response = $this->db->for(WorkModel::TABLE) - ->where($filters) - ->order([WorkModel::DATE_CREATED->value => "DESC"]) - ->limit($_GET[PARAM_LIMIT]) - ->select([ - WorkModel::ID->value, - WorkModel::TITLE->value, - WorkModel::SUMMARY->value, - WorkModel::IS_LISTED->value, - WorkModel::DATE_YEAR->value, - WorkModel::DATE_MONTH->value, - WorkModel::DATE_DAY->value, - WorkModel::DATE_MODIFIED->value, - WorkModel::DATE_CREATED->value - ]); - - return $response->num_rows > 0 - ? new Response($response->fetch_all(MYSQLI_ASSOC)) - : new Response([], 404); - } - } \ No newline at end of file diff --git a/api/endpoints/work/actions/DELETE.php b/api/endpoints/work/actions/DELETE.php deleted file mode 100755 index a0d582c..0000000 --- a/api/endpoints/work/actions/DELETE.php +++ /dev/null @@ -1,38 +0,0 @@ -ruleset = new Ruleset(strict: true); - - $this->ruleset->POST([ - (new Rules(WorkActionsModel::REF_WORK_ID->value)) - ->min(1) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH) - ]); - } - - public function main(): Response { - return $this->db->for(WorkActionsModel::TABLE)->delete($_POST) === true - ? new Response(RESP_DELETE_OK) - : new Response("Failed to delete action for work entity", 500); - } - } \ No newline at end of file diff --git a/api/endpoints/work/actions/GET.php b/api/endpoints/work/actions/GET.php deleted file mode 100644 index 902a97d..0000000 --- a/api/endpoints/work/actions/GET.php +++ /dev/null @@ -1,48 +0,0 @@ -ruleset = new Ruleset(strict: true); - - $this->ruleset->GET([ - (new Rules(WorkActionsModel::REF_WORK_ID->value)) - ->type(Type::STRING) - ->min(1) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH) - ]); - - parent::__construct(Databases::VLW, $this->ruleset); - } - - public function main(): Response { - $response = $this->db->for(WorkActionsModel::TABLE) - ->where($_GET) - ->select([ - WorkActionsModel::REF_WORK_ID->value, - WorkActionsModel::DISPLAY_TEXT->value, - WorkActionsModel::HREF->value, - WorkActionsModel::CLASS_LIST->value - ]); - - return $response->num_rows > 0 - ? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), WorkActionsModel::REF_WORK_ID->value)) - : new Response([], 404); - } - } \ No newline at end of file diff --git a/api/endpoints/work/permalinks/GET.php b/api/endpoints/work/permalinks/GET.php deleted file mode 100755 index d414e14..0000000 --- a/api/endpoints/work/permalinks/GET.php +++ /dev/null @@ -1,52 +0,0 @@ -ruleset = new Ruleset(strict: true); - - $this->ruleset->GET([ - (new Rules(WorkPermalinksModel::ID->value)) - ->type(Type::STRING) - ->min(1) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - - (new Rules(WorkPermalinksModel::REF_WORK_ID->value)) - ->type(Type::STRING) - ->min(1) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH) - ]); - - parent::__construct(Databases::VLW, $this->ruleset); - } - - public function main(): Response { - $response = $this->db->for(WorkPermalinksModel::TABLE) - ->where($_GET) - ->select([ - WorkPermalinksModel::ID->value, - WorkPermalinksModel::REF_WORK_ID->value, - WorkPermalinksModel::DATE_CREATED->value - ]); - - return $response->num_rows > 0 - ? new Response($response->fetch_all(MYSQLI_ASSOC)) - : new Response([], 404); - } - } \ No newline at end of file diff --git a/api/endpoints/work/tags/DELETE.php b/api/endpoints/work/tags/DELETE.php deleted file mode 100755 index 04c6924..0000000 --- a/api/endpoints/work/tags/DELETE.php +++ /dev/null @@ -1,42 +0,0 @@ -ruleset = new Ruleset(strict: true); - - $this->ruleset->GET([ - (new Rules(WorkTagsModel::REF_WORK_ID->value)) - ->min(1) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - - (new Rules(WorkTagsModel::NAME->value)) - ->type(Type::ENUM, WorkTagsNameEnum::names()) - ]); - - parent::__construct(Databases::VLW, $this->ruleset); - } - - public function main(): Response { - return $this->db->for(WorkTagsModel::TABLE)->delete($_POST) === true - ? new Response(RESP_DELETE_OK) - : new Response("Failed to delete value from document", 500); - } - } \ No newline at end of file diff --git a/api/endpoints/work/tags/GET.php b/api/endpoints/work/tags/GET.php deleted file mode 100644 index 9d2bae3..0000000 --- a/api/endpoints/work/tags/GET.php +++ /dev/null @@ -1,51 +0,0 @@ -ruleset = new Ruleset(strict: true); - - $this->ruleset->GET([ - (new Rules(WorkTagsModel::REF_WORK_ID->value)) - ->min(1) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - - (new Rules(WorkTagsModel::NAME->value)) - ->type(Type::ENUM, WorkTagsNameEnum::names()) - ]); - - parent::__construct(Databases::VLW, $this->ruleset); - } - - public function main(): Response { - $response = $this->db->for(WorkTagsModel::TABLE) - ->where($_GET) - ->select([ - WorkTagsModel::REF_WORK_ID->value, - WorkTagsModel::NAME->value - ]); - - return $response->num_rows > 0 - ? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), WorkTagsModel::REF_WORK_ID->value)) - : new Response([], 404); - } - } \ No newline at end of file diff --git a/api/endpoints/work/tags/POST.php b/api/endpoints/work/tags/POST.php deleted file mode 100755 index e10ae90..0000000 --- a/api/endpoints/work/tags/POST.php +++ /dev/null @@ -1,63 +0,0 @@ -ruleset = new Ruleset(strict: true); - - $this->ruleset->POST([ - (new Rules(WorkTagsModel::REF_WORK_ID->value)) - ->required() - ->min(1) - ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - - (new Rules(WorkTagsModel::NAME->value)) - ->required() - ->type(Type::ENUM, WorkTagsNameEnum::names()) - ]); - - parent::__construct(Databases::VLW, $this->ruleset); - } - - private static function get_entity(): Response { - return (new Call(Endpoints::WORK->value))->params([ - WorkModel::ID->value => $_POST[WorkTagsModel::REF_WORK_ID->value] - ])->get(); - } - - public function main(): Response { - // Bail out if work entity could not be fetched - $entity = self::get_entity(); - if (!$entity->ok) { - return $entity; - } - - return $this->db->for(WorkTagsModel::TABLE)->insert($_POST) === true - ? new Response($_POST[WorkTagsModel::REF_WORK_ID->value], 201) - : new Response("Failed to add tag to work entity", 500); - } - } \ No newline at end of file diff --git a/api/src/databases/VLWdb.php b/api/src/databases/VLWdb.php deleted file mode 100755 index 7a06a4f..0000000 --- a/api/src/databases/VLWdb.php +++ /dev/null @@ -1,101 +0,0 @@ -db = new MySQL( - $_ENV["connect"]["host"], - $_ENV["connect"]["user"], - $_ENV["connect"]["pass"], - $_ENV["databases"][$database->value], - ); - } - - // Bail out if provided ReflectRules\Ruleset is invalid - private static function eval_ruleset_or_exit(Ruleset $ruleset): ?Response { - return !$ruleset->is_valid() ? new Response($ruleset->get_errors(), 422) : null; - } - - // Generate and return UUID4 string - public static function gen_uuid4(): string { - return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", - // 32 bits for "time_low" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - - // 16 bits for "time_mid" - mt_rand(0, 0xffff), - - // 16 bits for "time_hi_and_version", - // four most significant bits holds version number 4 - mt_rand(0, 0x0fff) | 0x4000, - - // 16 bits, 8 bits for "clk_seq_hi_res", - // 8 bits for "clk_seq_low", - // two most significant bits holds zero and one for variant DCE1.1 - mt_rand(0, 0x3fff) | 0x8000, - - // 48 bits for "node" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); - } - - // Mutate the value by array key $property_name into a libmysqldriver\MySQL custom operator - // https://codeberg.org/vlw/php-mysql#define-custom-operators - public static function make_wildcard_search(string $property_name, array &$filters): array { - // Bail out if property name is not set in filters array or if its value is null - if (!array_key_exists($property_name, $filters) || $filters[$property_name] === null) { - return $filters; - } - - // Mutate filter value into a custom operator array - $filters[$property_name] = [ - "LIKE" => "%{$filters[$property_name]}%" - ]; - - return $filters; - } - - public function index_array_by_key(array $input, string $key): array { - $output = []; - - foreach ($input as $item) { - $idx = $item[$key]; - - // Create entry for key in output array if first item - if (!array_key_exists($idx, $output)) { - $output[$idx] = []; - } - - // Append item to array of array by key - $output[$idx][] = $item; - } - - return $output; - } - } \ No newline at end of file diff --git a/api/src/databases/models/Battlestation/Config/ChassisMb.php b/api/src/databases/models/Battlestation/Config/ChassisMb.php deleted file mode 100644 index 1d549d2..0000000 --- a/api/src/databases/models/Battlestation/Config/ChassisMb.php +++ /dev/null @@ -1,14 +0,0 @@ -results = $this->db - ->for(ConfigModel::TABLE) + ->for(ConfigModel::NAME) ->where($this->query) ->order([ConfigModel::DATE_BUILT->value => "DESC"]) ->select(ConfigModel::values()) diff --git a/api/endpoints/battlestation/chassis/GET.php b/endpoints/battlestation/chassis/GET.php similarity index 55% rename from api/endpoints/battlestation/chassis/GET.php rename to endpoints/battlestation/chassis/GET.php index b00c21d..b525dd5 100644 --- a/api/endpoints/battlestation/chassis/GET.php +++ b/endpoints/battlestation/chassis/GET.php @@ -1,23 +1,17 @@ ruleset = new Ruleset(strict: true); $this->ruleset->GET([ - (new Rules(ChassisModel::ID->value)) + (new Rules(ChassisTable::ID->value)) ->type(Type::STRING) ->min(parent::UUID_LENGTH) ->max(parent::UUID_LENGTH), - (new Rules(ChassisModel::VENDOR_NAME->value)) + (new Rules(ChassisTable::VENDOR_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(ChassisModel::VENDOR_MODEL->value)) + (new Rules(ChassisTable::VENDOR_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(ChassisModel::STORAGE_TWOINCHFIVE->value)) + (new Rules(ChassisTable::STORAGE_TWOINCHFIVE->value)) ->type(Type::NUMBER) ->type(Type::NULL) ->min(0) ->max(parent::MYSQL_TINYINT_MAX_LENGTH), - (new Rules(ChassisModel::STORAGE_THREEINCHFIVE->value)) + (new Rules(ChassisTable::STORAGE_THREEINCHFIVE->value)) ->type(Type::NUMBER) ->type(Type::NULL) ->min(0) ->max(parent::MYSQL_TINYINT_MAX_LENGTH), - (new Rules(ChassisModel::IS_RETIRED->value)) + (new Rules(ChassisTable::IS_RETIRED->value)) ->type(Type::BOOLEAN) ]); @@ -70,26 +64,26 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_MOTHERBOARDS] = $this->db - ->for(ChassisMbModel::TABLE) - ->where([ChassisMbModel::REF_CHASSIS_ID->value => $result[ChassisModel::ID->value]]) - ->select(ChassisMbModel::values()) + ->for(ChassisMbTable::NAME) + ->where([ChassisMbTable::REF_CHASSIS_ID->value => $result[ChassisTable::ID->value]]) + ->select(ChassisMbTable::values()) ->fetch_all(MYSQLI_ASSOC); } } private function get_chassis(): array { return $this->results = $this->db - ->for(ChassisModel::TABLE) + ->for(ChassisTable::NAME) ->where($this->query) - ->order([ChassisModel::DATE_AQUIRED->value => "DESC"]) - ->select(ChassisModel::values()) + ->order([ChassisTable::DATE_AQUIRED->value => "DESC"]) + ->select(ChassisTable::values()) ->fetch_all(MYSQLI_ASSOC); } public function main(): Response { // Set properties as "searchable" - parent::make_wildcard_search(ChassisModel::VENDOR_NAME->value, $this->query); - parent::make_wildcard_search(ChassisModel::VENDOR_MODEL->value, $this->query); + parent::make_wildcard_search(ChassisTable::VENDOR_NAME->value, $this->query); + parent::make_wildcard_search(ChassisTable::VENDOR_MODEL->value, $this->query); // Get hardware $this->get_chassis(); diff --git a/api/endpoints/battlestation/coolers/GET.php b/endpoints/battlestation/coolers/GET.php similarity index 78% rename from api/endpoints/battlestation/coolers/GET.php rename to endpoints/battlestation/coolers/GET.php index 5d93726..c209033 100644 --- a/api/endpoints/battlestation/coolers/GET.php +++ b/endpoints/battlestation/coolers/GET.php @@ -1,25 +1,19 @@ results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_MOTHERBOARDS] = $this->db - ->for(MbCoolerModel::TABLE) + ->for(MbCoolerModel::NAME) ->where([MbCoolerModel::REF_COOLER_ID->value => $result[CoolerModel::ID->value]]) ->select(MbCoolerModel::values()) ->fetch_all(MYSQLI_ASSOC); @@ -84,7 +78,7 @@ private function get_coolers(): array { return $this->results = $this->db - ->for(CoolerModel::TABLE) + ->for(CoolerModel::NAME) ->where($this->query) ->order([CoolerModel::DATE_AQUIRED->value => "DESC"]) ->select(CoolerModel::values()) diff --git a/api/endpoints/battlestation/cpu/GET.php b/endpoints/battlestation/cpu/GET.php similarity index 59% rename from api/endpoints/battlestation/cpu/GET.php rename to endpoints/battlestation/cpu/GET.php index 2bdfb69..39b0362 100644 --- a/api/endpoints/battlestation/cpu/GET.php +++ b/endpoints/battlestation/cpu/GET.php @@ -1,26 +1,20 @@ ruleset = new Ruleset(strict: true); $this->ruleset->GET([ - (new Rules(CpuModel::ID->value)) + (new Rules(CpuTable::ID->value)) ->type(Type::STRING) ->min(parent::UUID_LENGTH) ->max(parent::UUID_LENGTH), - (new Rules(CpuModel::CLOCK_BASE->value)) + (new Rules(CpuTable::CLOCK_BASE->value)) ->type(Type::NUMBER) ->min(1), - (new Rules(CpuModel::CLOCK_TURBO->value)) + (new Rules(CpuTable::CLOCK_TURBO->value)) ->type(Type::NUMBER) ->min(1), - (new Rules(CpuModel::CORE_COUNT_PERFORMANCE->value)) + (new Rules(CpuTable::CORE_COUNT_PERFORMANCE->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_TINYINT_MAX_LENGTH), - (new Rules(CpuModel::CORE_COUNT_EFFICIENCY->value)) + (new Rules(CpuTable::CORE_COUNT_EFFICIENCY->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_TINYINT_MAX_LENGTH), - (new Rules(CpuModel::CORE_THREADS->value)) + (new Rules(CpuTable::CORE_THREADS->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_TINYINT_MAX_LENGTH), - (new Rules(CpuModel::VENDOR_NAME->value)) + (new Rules(CpuTable::VENDOR_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(CpuModel::VENDOR_MODEL->value)) + (new Rules(CpuTable::VENDOR_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(CpuModel::IS_RETIRED->value)) + (new Rules(CpuTable::IS_RETIRED->value)) ->type(Type::BOOLEAN) ]); @@ -84,8 +78,8 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_MOTHERBOARDS] = $this->db - ->for(MbCpuCoolerModel::TABLE) - ->where([MbCpuCoolerModel::REF_CPU_ID->value => $result[CpuModel::ID->value]]) + ->for(MbCpuCoolerModel::NAME) + ->where([MbCpuCoolerModel::REF_CPU_ID->value => $result[CpuTable::ID->value]]) ->select(MbCpuCoolerModel::values()) ->fetch_all(MYSQLI_ASSOC); } @@ -93,17 +87,17 @@ private function get_cpu(): array { return $this->results = $this->db - ->for(CpuModel::TABLE) + ->for(CpuTable::NAME) ->where($this->query) - ->order([CpuModel::DATE_AQUIRED->value => "DESC"]) - ->select(CpuModel::values()) + ->order([CpuTable::DATE_AQUIRED->value => "DESC"]) + ->select(CpuTable::values()) ->fetch_all(MYSQLI_ASSOC); } public function main(): Response { // Set properties as "searchable" - parent::make_wildcard_search(CpuModel::VENDOR_NAME->value, $this->query); - parent::make_wildcard_search(CpuModel::VENDOR_MODEL->value, $this->query); + parent::make_wildcard_search(CpuTable::VENDOR_NAME->value, $this->query); + parent::make_wildcard_search(CpuTable::VENDOR_MODEL->value, $this->query); // Get hardware $this->get_cpu(); diff --git a/api/endpoints/battlestation/dram/GET.php b/endpoints/battlestation/dram/GET.php similarity index 54% rename from api/endpoints/battlestation/dram/GET.php rename to endpoints/battlestation/dram/GET.php index 72539af..75b04b6 100644 --- a/api/endpoints/battlestation/dram/GET.php +++ b/endpoints/battlestation/dram/GET.php @@ -1,27 +1,21 @@ ruleset = new Ruleset(strict: true); $this->ruleset->GET([ - (new Rules(DramModel::ID->value)) + (new Rules(DramTable::ID->value)) ->type(Type::STRING) ->min(parent::UUID_LENGTH) ->max(parent::UUID_LENGTH), - (new Rules(DramModel::CAPACITY->value)) + (new Rules(DramTable::CAPACITY->value)) ->type(Type::NUMBER) ->min(1), - (new Rules(DramModel::SPEED->value)) + (new Rules(DramTable::SPEED->value)) ->type(Type::NUMBER) ->min(1), - (new Rules(DramModel::FORMFACTOR->value)) + (new Rules(DramTable::FORMFACTOR->value)) ->type(Type::ENUM, DramFormfactorEnum::names()), - (new Rules(DramModel::TECHNOLOGY->value)) + (new Rules(DramTable::TECHNOLOGY->value)) ->type(Type::ENUM, DramTechnologyEnum::names()), - (new Rules(DramModel::ECC->value)) + (new Rules(DramTable::ECC->value)) ->type(Type::BOOLEAN), - (new Rules(DramModel::BUFFERED->value)) + (new Rules(DramTable::BUFFERED->value)) ->type(Type::BOOLEAN), - (new Rules(DramModel::VENDOR_NAME->value)) + (new Rules(DramTable::VENDOR_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(DramModel::VENDOR_MODEL->value)) + (new Rules(DramTable::VENDOR_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(DramModel::IS_RETIRED->value)) + (new Rules(DramTable::IS_RETIRED->value)) ->type(Type::BOOLEAN) ]); @@ -82,26 +76,26 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_MOTHERBOARDS] = $this->db - ->for(MbDramModel::TABLE) - ->where([MbDramModel::REF_DRAM_ID->value => $result[DramModel::ID->value]]) - ->select(MbDramModel::values()) + ->for(MbDramTable::NAME) + ->where([MbDramTable::REF_DRAM_ID->value => $result[DramTable::ID->value]]) + ->select(MbDramTable::values()) ->fetch_all(MYSQLI_ASSOC); } } private function get_dram(): array { return $this->results = $this->db - ->for(DramModel::TABLE) + ->for(DramTable::NAME) ->where($this->query) - ->order([DramModel::DATE_AQUIRED->value => "DESC"]) - ->select(DramModel::values()) + ->order([DramTable::DATE_AQUIRED->value => "DESC"]) + ->select(DramTable::values()) ->fetch_all(MYSQLI_ASSOC); } public function main(): Response { // Set properties as "searchable" - parent::make_wildcard_search(DramModel::VENDOR_NAME->value, $this->query); - parent::make_wildcard_search(DramModel::VENDOR_MODEL->value, $this->query); + parent::make_wildcard_search(DramTable::VENDOR_NAME->value, $this->query); + parent::make_wildcard_search(DramTable::VENDOR_MODEL->value, $this->query); // Get hardware $this->get_dram(); diff --git a/api/endpoints/battlestation/gpu/GET.php b/endpoints/battlestation/gpu/GET.php similarity index 54% rename from api/endpoints/battlestation/gpu/GET.php rename to endpoints/battlestation/gpu/GET.php index 5a8598b..af4c86c 100644 --- a/api/endpoints/battlestation/gpu/GET.php +++ b/endpoints/battlestation/gpu/GET.php @@ -1,23 +1,17 @@ ruleset = new Ruleset(strict: true); $this->ruleset->GET([ - (new Rules(GpuModel::ID->value)) + (new Rules(GpuTable::ID->value)) ->type(Type::STRING) ->min(parent::UUID_LENGTH) ->max(parent::UUID_LENGTH), - (new Rules(GpuModel::MEMORY->value)) + (new Rules(GpuTable::MEMORY->value)) ->type(Type::NUMBER) ->min(1), - (new Rules(GpuModel::VENDOR_NAME->value)) + (new Rules(GpuTable::VENDOR_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(GpuModel::VENDOR_MODEL->value)) + (new Rules(GpuTable::VENDOR_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(GpuModel::VENDOR_CHIP_NAME->value)) + (new Rules(GpuTable::VENDOR_CHIP_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(GpuModel::VENDOR_CHIP_MODEL->value)) + (new Rules(GpuTable::VENDOR_CHIP_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(GpuModel::IS_RETIRED->value)) + (new Rules(GpuTable::IS_RETIRED->value)) ->type(Type::BOOLEAN) ]); @@ -72,28 +66,28 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_MOTHERBOARDS] = $this->db - ->for(MbGpuModel::TABLE) - ->where([MbGpuModel::REF_GPU_ID->value => $result[GpuModel::ID->value]]) - ->select(MbGpuModel::values()) + ->for(MbGpuTable::NAME) + ->where([MbGpuTable::REF_GPU_ID->value => $result[GpuTable::ID->value]]) + ->select(MbGpuTable::values()) ->fetch_all(MYSQLI_ASSOC); } } private function get_gpu(): array { return $this->results = $this->db - ->for(GpuModel::TABLE) + ->for(GpuTable::NAME) ->where($this->query) - ->order([GpuModel::DATE_AQUIRED->value => "DESC"]) - ->select(GpuModel::values()) + ->order([GpuTable::DATE_AQUIRED->value => "DESC"]) + ->select(GpuTable::values()) ->fetch_all(MYSQLI_ASSOC); } public function main(): Response { // Set properties as "searchable" - parent::make_wildcard_search(GpuModel::VENDOR_NAME->value, $this->query); - parent::make_wildcard_search(GpuModel::VENDOR_MODEL->value, $this->query); - parent::make_wildcard_search(GpuModel::VENDOR_CHIP_NAME->value, $this->query); - parent::make_wildcard_search(GpuModel::VENDOR_CHIP_MODEL->value, $this->query); + parent::make_wildcard_search(GpuTable::VENDOR_NAME->value, $this->query); + parent::make_wildcard_search(GpuTable::VENDOR_MODEL->value, $this->query); + parent::make_wildcard_search(GpuTable::VENDOR_CHIP_NAME->value, $this->query); + parent::make_wildcard_search(GpuTable::VENDOR_CHIP_MODEL->value, $this->query); // Get hardware $this->get_gpu(); diff --git a/api/endpoints/battlestation/mb/GET.php b/endpoints/battlestation/mb/GET.php similarity index 57% rename from api/endpoints/battlestation/mb/GET.php rename to endpoints/battlestation/mb/GET.php index d2c0ea0..6ea1129 100644 --- a/api/endpoints/battlestation/mb/GET.php +++ b/endpoints/battlestation/mb/GET.php @@ -1,38 +1,32 @@ ruleset = new Ruleset(strict: true); $this->ruleset->GET([ - (new Rules(MbModel::ID->value)) + (new Rules(MbTable::ID->value)) ->type(Type::STRING) ->min(parent::UUID_LENGTH) ->max(parent::UUID_LENGTH), - (new Rules(MbModel::FORMFACTOR->value)) + (new Rules(MbTable::FORMFACTOR->value)) ->type(Type::ENUM, MbFormfactorEnum::names()), - (new Rules(MbModel::VENDOR_NAME->value)) + (new Rules(MbTable::VENDOR_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(MbModel::VENDOR_MODEL->value)) + (new Rules(MbTable::VENDOR_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(MbModel::NETWORK_ETHERNET->value)) + (new Rules(MbTable::NETWORK_ETHERNET->value)) ->type(Type::NULL) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(MbModel::NETWORK_WLAN->value)) + (new Rules(MbTable::NETWORK_WLAN->value)) ->type(Type::NULL) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(MbModel::NETWORK_BLUETOOTH->value)) + (new Rules(MbTable::NETWORK_BLUETOOTH->value)) ->type(Type::NULL) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(MbModel::IS_RETIRED->value)) + (new Rules(MbTable::IS_RETIRED->value)) ->type(Type::BOOLEAN) ]); @@ -99,9 +93,9 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_CHASSIS] = $this->db - ->for(ChassisMbModel::TABLE) - ->where([ChassisMbModel::REF_MB_ID->value => $result[MbModel::ID->value]]) - ->select(ChassisMbModel::values()) + ->for(ChassisMbTable::NAME) + ->where([ChassisMbTable::REF_MB_ID->value => $result[MbTable::ID->value]]) + ->select(ChassisMbTable::values()) ->fetch_all(MYSQLI_ASSOC); } } @@ -110,9 +104,9 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_PSU] = $this->db - ->for(MbPsuModel::TABLE) - ->where([MbPsuModel::REF_MB_ID->value => $result[MbModel::ID->value]]) - ->select(MbPsuModel::values()) + ->for(MbPsuTable::NAME) + ->where([MbPsuTable::REF_MB_ID->value => $result[MbTable::ID->value]]) + ->select(MbPsuTable::values()) ->fetch_all(MYSQLI_ASSOC); } } @@ -121,8 +115,8 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_CPU] = $this->db - ->for(MbCpuCoolerModel::TABLE) - ->where([MbCpuCoolerModel::REF_MB_ID->value => $result[MbModel::ID->value]]) + ->for(MbCpuCoolerModel::NAME) + ->where([MbCpuCoolerModel::REF_MB_ID->value => $result[MbTable::ID->value]]) ->select(MbCpuCoolerModel::values()) ->fetch_all(MYSQLI_ASSOC); } @@ -132,9 +126,9 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_GPU] = $this->db - ->for(MbGpuModel::TABLE) - ->where([MbGpuModel::REF_MB_ID->value => $result[MbModel::ID->value]]) - ->select(MbGpuModel::values()) + ->for(MbGpuTable::NAME) + ->where([MbGpuTable::REF_MB_ID->value => $result[MbTable::ID->value]]) + ->select(MbGpuTable::values()) ->fetch_all(MYSQLI_ASSOC); } } @@ -143,9 +137,9 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_DRAM] = $this->db - ->for(MbDramModel::TABLE) - ->where([MbDramModel::REF_MB_ID->value => $result[MbModel::ID->value]]) - ->select(MbDramModel::values()) + ->for(MbDramTable::NAME) + ->where([MbDramTable::REF_MB_ID->value => $result[MbTable::ID->value]]) + ->select(MbDramTable::values()) ->fetch_all(MYSQLI_ASSOC); } } @@ -154,9 +148,9 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_STORAGE] = $this->db - ->for(MbStorageModel::TABLE) - ->where([MbStorageModel::REF_MB_ID->value => $result[MbModel::ID->value]]) - ->select(MbStorageModel::values()) + ->for(MbStorageTable::NAME) + ->where([MbStorageTable::REF_MB_ID->value => $result[MbTable::ID->value]]) + ->select(MbStorageTable::values()) ->fetch_all(MYSQLI_ASSOC); } } @@ -165,17 +159,17 @@ private function get_motherboards(): array { return $this->results = $this->db - ->for(MbModel::TABLE) + ->for(MbTable::NAME) ->where($this->query) - ->order([MbModel::DATE_AQUIRED->value => "DESC"]) - ->select(MbModel::values()) + ->order([MbTable::DATE_AQUIRED->value => "DESC"]) + ->select(MbTable::values()) ->fetch_all(MYSQLI_ASSOC); } public function main(): Response { // Set properties as "searchable" - parent::make_wildcard_search(MbModel::VENDOR_NAME->value, $this->query); - parent::make_wildcard_search(MbModel::VENDOR_MODEL->value, $this->query); + parent::make_wildcard_search(MbTable::VENDOR_NAME->value, $this->query); + parent::make_wildcard_search(MbTable::VENDOR_MODEL->value, $this->query); // Get hardware $this->get_motherboards(); diff --git a/api/endpoints/battlestation/psu/GET.php b/endpoints/battlestation/psu/GET.php similarity index 56% rename from api/endpoints/battlestation/psu/GET.php rename to endpoints/battlestation/psu/GET.php index 2420422..a94ef8c 100644 --- a/api/endpoints/battlestation/psu/GET.php +++ b/endpoints/battlestation/psu/GET.php @@ -1,26 +1,20 @@ ruleset = new Ruleset(strict: true); $this->ruleset->GET([ - (new Rules(PsuModel::ID->value)) + (new Rules(PsuTable::ID->value)) ->type(Type::STRING) ->min(parent::UUID_LENGTH) ->max(parent::UUID_LENGTH), - (new Rules(PsuModel::POWER->value)) + (new Rules(PsuTable::POWER->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_INT_MAX_LENGTH), - (new Rules(PsuModel::EIGHTYPLUS_RATING->value)) + (new Rules(PsuTable::EIGHTYPLUS_RATING->value)) ->type(Type::ENUM, EightyplusRatingEnum::names()), - (new Rules(PsuModel::VENDOR_NAME->value)) + (new Rules(PsuTable::VENDOR_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(PsuModel::VENDOR_MODEL->value)) + (new Rules(PsuTable::VENDOR_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(PsuModel::IS_RETIRED->value)) + (new Rules(PsuTable::IS_RETIRED->value)) ->type(Type::BOOLEAN) ]); @@ -69,26 +63,26 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_MOTHERBOARDS] = $this->db - ->for(MbPsuModel::TABLE) - ->where([MbPsuModel::REF_PSU_ID->value => $result[PsuModel::ID->value]]) - ->select(MbPsuModel::values()) + ->for(MbPsuTable::NAME) + ->where([MbPsuTable::REF_PSU_ID->value => $result[PsuTable::ID->value]]) + ->select(MbPsuTable::values()) ->fetch_all(MYSQLI_ASSOC); } } private function get_psu(): array { return $this->results = $this->db - ->for(PsuModel::TABLE) + ->for(PsuTable::NAME) ->where($this->query) - ->order([PsuModel::DATE_AQUIRED->value => "DESC"]) - ->select(PsuModel::values()) + ->order([PsuTable::DATE_AQUIRED->value => "DESC"]) + ->select(PsuTable::values()) ->fetch_all(MYSQLI_ASSOC); } public function main(): Response { // Set properties as "searchable" - parent::make_wildcard_search(PsuModel::VENDOR_NAME->value, $this->query); - parent::make_wildcard_search(PsuModel::VENDOR_MODEL->value, $this->query); + parent::make_wildcard_search(PsuTable::VENDOR_NAME->value, $this->query); + parent::make_wildcard_search(PsuTable::VENDOR_MODEL->value, $this->query); // Get hardware $this->get_psu(); diff --git a/api/endpoints/battlestation/storage/GET.php b/endpoints/battlestation/storage/GET.php similarity index 55% rename from api/endpoints/battlestation/storage/GET.php rename to endpoints/battlestation/storage/GET.php index 4bfff74..d423e4a 100644 --- a/api/endpoints/battlestation/storage/GET.php +++ b/endpoints/battlestation/storage/GET.php @@ -1,28 +1,22 @@ ruleset = new Ruleset(strict: true); $this->ruleset->GET([ - (new Rules(StorageModel::ID->value)) + (new Rules(StorageTable::ID->value)) ->type(Type::STRING) ->min(parent::UUID_LENGTH) ->max(parent::UUID_LENGTH), - (new Rules(StorageModel::DISK_TYPE->value)) + (new Rules(StorageTable::DISK_TYPE->value)) ->type(Type::ENUM, StorageDiskTypeEnum::names()), - (new Rules(StorageModel::DISK_SIZE->value)) + (new Rules(StorageTable::DISK_SIZE->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_INT_MAX_LENGTH), - (new Rules(StorageModel::DISK_INTERFACE->value)) + (new Rules(StorageTable::DISK_INTERFACE->value)) ->type(Type::ENUM, StorageDiskInterfaceEnum::names()), - (new Rules(StorageModel::DISK_FORMFACTOR->value)) + (new Rules(StorageTable::DISK_FORMFACTOR->value)) ->type(Type::ENUM, StorageDiskFormfactorEnum::names()), - (new Rules(StorageModel::VENDOR_NAME->value)) + (new Rules(StorageTable::VENDOR_NAME->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(StorageModel::VENDOR_MODEL->value)) + (new Rules(StorageTable::VENDOR_MODEL->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(StorageModel::IS_RETIRED->value)) + (new Rules(StorageTable::IS_RETIRED->value)) ->type(Type::BOOLEAN) ]); @@ -77,26 +71,26 @@ foreach ($this->results as &$result) { // Get motherboard id from relationship by chassis id $result[self::REL_MOTHERBOARDS] = $this->db - ->for(MbStorageModel::TABLE) - ->where([MbStorageModel::REF_STORAGE_ID->value => $result[StorageModel::ID->value]]) - ->select(MbStorageModel::values()) + ->for(MbStorageTable::NAME) + ->where([MbStorageTable::REF_STORAGE_ID->value => $result[StorageTable::ID->value]]) + ->select(MbStorageTable::values()) ->fetch_all(MYSQLI_ASSOC); } } private function get_storage(): array { return $this->results = $this->db - ->for(StorageModel::TABLE) + ->for(StorageTable::NAME) ->where($this->query) - ->order([StorageModel::DATE_AQUIRED->value => "DESC"]) - ->select(StorageModel::values()) + ->order([StorageTable::DATE_AQUIRED->value => "DESC"]) + ->select(StorageTable::values()) ->fetch_all(MYSQLI_ASSOC); } public function main(): Response { // Set properties as "searchable" - parent::make_wildcard_search(StorageModel::VENDOR_NAME->value, $this->query); - parent::make_wildcard_search(StorageModel::VENDOR_MODEL->value, $this->query); + parent::make_wildcard_search(StorageTable::VENDOR_NAME->value, $this->query); + parent::make_wildcard_search(StorageTable::VENDOR_MODEL->value, $this->query); // Get hardware $this->get_storage(); diff --git a/endpoints/messages/POST.php b/endpoints/messages/POST.php new file mode 100644 index 0000000..f7312ea --- /dev/null +++ b/endpoints/messages/POST.php @@ -0,0 +1,47 @@ +ruleset = new Ruleset(strict: true); + + $this->ruleset->POST([ + (new Rules(MessagesTable::EMAIL->value)) + ->type(Type::STRING) + ->max(255) + ->default(null), + + (new Rules(MessagesTable::MESSAGE->value)) + ->required() + ->type(Type::STRING) + ->min(1) + ->max(parent::MYSQL_TEXT_MAX_LENGTH) + ]); + + $ruleset->validate_or_exit(); + + parent::__construct(); + } + + public function main(): Response { + // Use copy of request body as entity + $entity = $_POST; + + $entity[MessagesTable::ID->value] = parent::gen_uuid4(); + $entity[MessagesTable::DATE_CREATED->value] = time(); + + return $this->db->for(MessagesTable::NAME)->insert($entity) === true + ? new Response($entity[MessagesTable::ID->value], 201) + : new Response("Failed to create message", 500); + } + } \ No newline at end of file diff --git a/api/endpoints/search/GET.php b/endpoints/search/GET.php old mode 100755 new mode 100644 similarity index 62% rename from api/endpoints/search/GET.php rename to endpoints/search/GET.php index 4454263..5ac87a5 --- a/api/endpoints/search/GET.php +++ b/endpoints/search/GET.php @@ -1,25 +1,19 @@ max(parent::MYSQL_VARCHAR_MAX_LENGTH) ]); - parent::__construct(Databases::VLW, $this->ruleset); + $ruleset->validate_or_exit(); + + parent::__construct(); } private function search_work(): Response { return (new Call(Endpoints::WORK->value))->params([ - WorkModel::TITLE->value => $_GET[self::GET_QUERY], - WorkModel::SUMMARY->value => $_GET[self::GET_QUERY] + WorkTable::TITLE->value => $_GET[self::GET_QUERY], + WorkTable::SUMMARY->value => $_GET[self::GET_QUERY] ])->get(); } diff --git a/api/endpoints/work/DELETE.php b/endpoints/work/DELETE.php old mode 100755 new mode 100644 similarity index 51% rename from api/endpoints/work/DELETE.php rename to endpoints/work/DELETE.php index 2b5905a..31be30f --- a/api/endpoints/work/DELETE.php +++ b/endpoints/work/DELETE.php @@ -1,63 +1,59 @@ ruleset = new Ruleset(strict: true); $this->ruleset->POST([ - (new Rules(WorkModel::ID->value)) + (new Rules(WorkTable::ID->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(WorkModel::TITLE->value)) + (new Rules(WorkTable::TITLE->value)) ->type(Type::STRING) ->min(3) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(WorkModel::SUMMARY->value)) + (new Rules(WorkTable::SUMMARY->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_TEXT_MAX_LENGTH), - (new Rules(WorkModel::IS_LISTED->value)) + (new Rules(WorkTable::IS_LISTED->value)) ->type(Type::BOOLEAN), - (new Rules(WorkModel::DATE_MODIFIED->value)) + (new Rules(WorkTable::DATE_MODIFIED->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_INT_MAX_LENGTH), - (new Rules(WorkModel::DATE_CREATED->value)) + (new Rules(WorkTable::DATE_CREATED->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_INT_MAX_LENGTH) ]); - parent::__construct(Databases::VLW, $this->ruleset); + $ruleset->validate_or_exit(); + + parent::__construct(); } public function main(): Response { - return $this->db->for(FieldsEnumsModel::TABLE)->delete($_POST) === true + return $this->db->for(FieldsEnumsModel::NAME)->delete($_POST) === true ? new Response(RESP_DELETE_OK) : new Response("Failed to delete work entity", 500); } diff --git a/endpoints/work/GET.php b/endpoints/work/GET.php new file mode 100644 index 0000000..cd374c7 --- /dev/null +++ b/endpoints/work/GET.php @@ -0,0 +1,55 @@ +ruleset = new Ruleset(strict: true); + + $this->ruleset->GET([ + (new Rules(WorkTable::ID->value)) + ->type(Type::STRING) + ->min(1) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), + + (new Rules(WorkTable::TITLE->value)) + ->type(Type::STRING) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), + + (new Rules(WorkTable::SUMMARY->value)) + ->type(Type::STRING) + ->max(parent::MYSQL_TEXT_MAX_LENGTH), + + (new Rules(WorkTable::IS_LISTED->value)) + ->type(Type::BOOLEAN) + ->default(true), + + (new Rules(WorkTable::DATE_MODIFIED->value)) + ->type(Type::NUMBER) + ->min(1) + ->max(parent::MYSQL_INT_MAX_LENGTH), + + (new Rules(WorkTable::DATE_CREATED->value)) + ->type(Type::NUMBER) + ->min(1) + ->max(parent::MYSQL_INT_MAX_LENGTH) + ]); + + $ruleset->validate_or_exit(); + + parent::__construct(); + } + + public function main(): Response { + return $this->list(WorkTable::NAME, WorkTable::values()); + } + } \ No newline at end of file diff --git a/api/endpoints/work/PATCH.php b/endpoints/work/PATCH.php old mode 100755 new mode 100644 similarity index 59% rename from api/endpoints/work/PATCH.php rename to endpoints/work/PATCH.php index de44730..2e3c5e4 --- a/api/endpoints/work/PATCH.php +++ b/endpoints/work/PATCH.php @@ -1,35 +1,29 @@ ruleset = new Ruleset(strict: true); $this->ruleset->GET([ - (new Rules(WorkModel::ID->value)) + (new Rules(WorkTable::ID->value)) ->required() ->type(Type::STRING) ->min(1) @@ -37,26 +31,26 @@ ]); $this->ruleset->POST([ - (new Rules(WorkModel::TITLE->value)) + (new Rules(WorkTable::TITLE->value)) ->type(Type::STRING) ->min(3) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(WorkModel::SUMMARY->value)) + (new Rules(WorkTable::SUMMARY->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_TEXT_MAX_LENGTH), - (new Rules(WorkModel::IS_LISTED->value)) + (new Rules(WorkTable::IS_LISTED->value)) ->type(Type::BOOLEAN), - (new Rules(WorkModel::DATE_MODIFIED->value)) + (new Rules(WorkTable::DATE_MODIFIED->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_INT_MAX_LENGTH) ->default(time()), - (new Rules(WorkModel::DATE_CREATED->value)) + (new Rules(WorkTable::DATE_CREATED->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_INT_MAX_LENGTH) @@ -73,15 +67,15 @@ // Compute and return modeled year, month, and day from Unix timestamp in request body private static function gen_date_created(): array { return [ - WorkModel::DATE_YEAR->value => date("Y", $_POST[WorkModel::DATE_CREATED->value]), - WorkModel::DATE_MONTH ->value => date("n", $_POST[WorkModel::DATE_CREATED->value]), - WorkModel::DATE_DAY->value => date("j", $_POST[WorkModel::DATE_CREATED->value]) + WorkTable::DATE_YEAR->value => date("Y", $_POST[WorkTable::DATE_CREATED->value]), + WorkTable::DATE_MONTH ->value => date("n", $_POST[WorkTable::DATE_CREATED->value]), + WorkTable::DATE_DAY->value => date("j", $_POST[WorkTable::DATE_CREATED->value]) ]; } private function get_entity_by_id(string $id): Response { return (new Call(Endpoints::WORK->value))->params([ - WorkModel::ID->value => $id + WorkTable::ID->value => $id ])->get(); } @@ -90,8 +84,8 @@ $entity = $_POST; // Generate a new slug id from title if changed - if ($_POST[WorkModel::TITLE->value]) { - $slug = $_POST[WorkModel::TITLE->value]; + if ($_POST[WorkTable::TITLE->value]) { + $slug = $_POST[WorkTable::TITLE->value]; // Bail out if the slug generated from the new tite already exist if ($this->get_entity_by_id($slug)) { @@ -99,17 +93,17 @@ } // Add the new slug to update entity - $entity[WorkModel::ID] = $slug; + $entity[WorkTable::ID] = $slug; } // Generate new work date fields from timestamp - if ($_POST[WorkModel::DATE_CREATED->value]) { + if ($_POST[WorkTable::DATE_CREATED->value]) { array_merge($entity, self::gen_date_created()); } // Update entity by existing id - return $this->db->for(WorkModel::TABLE)->where([WorkModel::ID->value => $_GET[WorkModel::ID->value]])->update($entity) === true - ? new Response($_GET[WorkModel::ID->value]) + return $this->db->for(WorkTable::NAME)->where([WorkTable::ID->value => $_GET[WorkTable::ID->value]])->update($entity) === true + ? new Response($_GET[WorkTable::ID->value]) : new Response("Failed to update entity", 500); } } \ No newline at end of file diff --git a/api/endpoints/work/POST.php b/endpoints/work/POST.php old mode 100755 new mode 100644 similarity index 55% rename from api/endpoints/work/POST.php rename to endpoints/work/POST.php index cf6c3c1..2c602ec --- a/api/endpoints/work/POST.php +++ b/endpoints/work/POST.php @@ -1,58 +1,54 @@ ruleset = new Ruleset(strict: true); $this->ruleset->POST([ - (new Rules(WorkModel::TITLE->value)) + (new Rules(WorkTable::TITLE->value)) ->type(Type::STRING) ->min(3) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH) ->default(null), - (new Rules(WorkModel::SUMMARY->value)) + (new Rules(WorkTable::SUMMARY->value)) ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_TEXT_MAX_LENGTH) ->default(null), - (new Rules(WorkModel::IS_LISTED->value)) + (new Rules(WorkTable::IS_LISTED->value)) ->type(Type::BOOLEAN) ->default(false), - (new Rules(WorkModel::DATE_CREATED->value)) + (new Rules(WorkTable::DATE_CREATED->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_INT_MAX_LENGTH) ->default(time()) ]); - parent::__construct(Databases::VLW, $this->ruleset); + $ruleset->validate_or_exit(); + + parent::__construct(); } // Generate a slug URL from string @@ -63,18 +59,18 @@ // Compute and return modeled year, month, and day from a Unix timestamp private static function gen_date_created(): array { // Use provided timestamp in request - $date_created = $_POST[WorkModel::DATE_CREATED->value]; + $date_created = $_POST[WorkTable::DATE_CREATED->value]; return [ - WorkModel::DATE_YEAR->value => date("Y", $date_created), - WorkModel::DATE_MONTH ->value => date("n", $date_created), - WorkModel::DATE_DAY->value => date("j", $date_created) + WorkTable::DATE_YEAR->value => date("Y", $date_created), + WorkTable::DATE_MONTH ->value => date("n", $date_created), + WorkTable::DATE_DAY->value => date("j", $date_created) ]; } private function get_entity_by_id(string $id): Response { return (new Call(Endpoints::WORK->value))->params([ - WorkModel::ID->value => $id + WorkTable::ID->value => $id ])->get(); } @@ -83,12 +79,12 @@ $entity = $_POST; // Generate URL slug from title text or UUID if undefined - $entity[WorkModel::ID->value] = $_POST[WorkModel::TITLE->value] - ? self::gen_slug($_POST[WorkModel::TITLE->value]) + $entity[WorkTable::ID->value] = $_POST[WorkTable::TITLE->value] + ? self::gen_slug($_POST[WorkTable::TITLE->value]) : parent::gen_uuid4(); // Bail out here if a work entry with id had been created already - if ($this->get_entity_by_id($entity[WorkModel::ID->value])->ok) { + if ($this->get_entity_by_id($entity[WorkTable::ID->value])->ok) { return new Response("An entity with id '{$slug}' already exist", 409); } @@ -96,15 +92,15 @@ array_merge($entity, self::gen_date_created()); // Let's try to insert the new entity - if (!$this->db->for(WorkModel::TABLE)->insert($entity)) { + if (!$this->db->for(WorkTable::NAME)->insert($entity)) { return new Response("Failed to insert work entry", 500); } // Generate permalink for new entity return (new Call(Endpoints::WORK_PERMALINKS->value))->post([ - WorkPermalinksModel::ID => $entity[WorkModel::ID->value], - WorkPermalinksModel::REF_WORK_ID => $entity[WorkModel::ID->value], - WorkPermalinksModel::DATE_CREATED => time() + PermalinksTable::ID => $entity[WorkTable::ID->value], + PermalinksTable::REF_WORK_ID => $entity[WorkTable::ID->value], + PermalinksTable::DATE_CREATED => time() ]); } } \ No newline at end of file diff --git a/endpoints/work/actions/DELETE.php b/endpoints/work/actions/DELETE.php new file mode 100644 index 0000000..b13d3b2 --- /dev/null +++ b/endpoints/work/actions/DELETE.php @@ -0,0 +1,32 @@ +ruleset = new Ruleset(strict: true); + + $this->ruleset->POST([ + (new Rules(ActionsTable::REF_WORK_ID->value)) + ->min(1) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH) + ]); + } + + public function main(): Response { + return $this->db->for(ActionsTable::NAME)->delete($_POST) === true + ? new Response(RESP_DELETE_OK) + : new Response("Failed to delete action for work entity", 500); + } + } \ No newline at end of file diff --git a/endpoints/work/actions/GET.php b/endpoints/work/actions/GET.php new file mode 100644 index 0000000..acb2475 --- /dev/null +++ b/endpoints/work/actions/GET.php @@ -0,0 +1,44 @@ +ruleset = new Ruleset(strict: true); + + $this->ruleset->GET([ + (new Rules(ActionsTable::REF_WORK_ID->value)) + ->type(Type::STRING) + ->min(1) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH) + ]); + + $ruleset->validate_or_exit(); + + parent::__construct(); + } + + public function main(): Response { + $response = $this->db->for(ActionsTable::NAME) + ->where($_GET) + ->select([ + ActionsTable::REF_WORK_ID->value, + ActionsTable::DISPLAY_TEXT->value, + ActionsTable::HREF->value, + ActionsTable::CLASS_LIST->value + ]); + + return $response->num_rows > 0 + ? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), ActionsTable::REF_WORK_ID->value)) + : new Response([], 404); + } + } \ No newline at end of file diff --git a/api/endpoints/work/actions/POST.php b/endpoints/work/actions/POST.php old mode 100755 new mode 100644 similarity index 50% rename from api/endpoints/work/actions/POST.php rename to endpoints/work/actions/POST.php index 7c8175a..5e319d8 --- a/api/endpoints/work/actions/POST.php +++ b/endpoints/work/actions/POST.php @@ -1,64 +1,60 @@ ruleset = new Ruleset(strict: true); $this->ruleset->POST([ - (new Rules(WorkActionsModel::REF_WORK_ID->value)) + (new Rules(ActionsTable::REF_WORK_ID->value)) ->required() ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(WorkActionsModel::DISPLAY_TEXT->value)) + (new Rules(ActionsTable::DISPLAY_TEXT->value)) ->required() ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(WorkActionsModel::HREF->value)) + (new Rules(ActionsTable::HREF->value)) ->required() ->type(Type::STRING) ->type(Type::NULL) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(WorkActionsModel::CLASS_LIST->value)) + (new Rules(ActionsTable::CLASS_LIST->value)) ->type(Type::ARRAY) ->min(1) ->default([]) ]); - parent::__construct(Databases::VLW, $this->ruleset); + $ruleset->validate_or_exit(); + + parent::__construct(); } private static function get_entity(): Response { return (new Call(Endpoints::WORK->value))->params([ - WorkModel::ID->value => $_POST[WorkActionsModel::REF_WORK_ID->value] + WorkTable::ID->value => $_POST[ActionsTable::REF_WORK_ID->value] ])->get(); } @@ -69,8 +65,8 @@ return $entity; } - return $this->db->for(WorkActionsModel::TABLE)->insert($_POST) === true - ? new Response($_POST[WorkActionsModel::REF_WORK_ID->value], 201) + return $this->db->for(ActionsTable::NAME)->insert($_POST) === true + ? new Response($_POST[ActionsTable::REF_WORK_ID->value], 201) : new Response("Failed to add action to work entity", 500); } } \ No newline at end of file diff --git a/endpoints/work/permalinks/GET.php b/endpoints/work/permalinks/GET.php new file mode 100644 index 0000000..2b06d2a --- /dev/null +++ b/endpoints/work/permalinks/GET.php @@ -0,0 +1,48 @@ +ruleset = new Ruleset(strict: true); + + $this->ruleset->GET([ + (new Rules(PermalinksTable::ID->value)) + ->type(Type::STRING) + ->min(1) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), + + (new Rules(PermalinksTable::REF_WORK_ID->value)) + ->type(Type::STRING) + ->min(1) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH) + ]); + + $ruleset->validate_or_exit(); + + parent::__construct(); + } + + public function main(): Response { + $response = $this->db->for(PermalinksTable::NAME) + ->where($_GET) + ->select([ + PermalinksTable::ID->value, + PermalinksTable::REF_WORK_ID->value, + PermalinksTable::DATE_CREATED->value + ]); + + return $response->num_rows > 0 + ? new Response($response->fetch_all(MYSQLI_ASSOC)) + : new Response([], 404); + } + } \ No newline at end of file diff --git a/api/endpoints/work/permalinks/POST.php b/endpoints/work/permalinks/POST.php old mode 100755 new mode 100644 similarity index 50% rename from api/endpoints/work/permalinks/POST.php rename to endpoints/work/permalinks/POST.php index fd2d904..59f339d --- a/api/endpoints/work/permalinks/POST.php +++ b/endpoints/work/permalinks/POST.php @@ -1,53 +1,49 @@ ruleset = new Ruleset(strict: true); $this->ruleset->POST([ - (new Rules(WorkPermalinksModel::ID->value)) + (new Rules(PermalinksTable::ID->value)) ->required() ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(WorkPermalinksModel::REF_WORK_ID->value)) + (new Rules(PermalinksTable::REF_WORK_ID->value)) ->required() ->type(Type::STRING) ->min(1) ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), - (new Rules(WorkPermalinksModel::DATE_CREATED->value)) + (new Rules(PermalinksTable::DATE_CREATED->value)) ->type(Type::NUMBER) ->min(1) ->max(parent::MYSQL_INT_MAX_LENGTH) ->default(time()) ]); - parent::__construct(Databases::VLW, $this->ruleset); + $ruleset->validate_or_exit(); + + parent::__construct(); } private static function get_entity(): Response { return (new Call(Endpoints::WORK->value))->params([ - WorkModel::ID->value => $_POST[WorkTagsModel::REF_WORK_ID->value] + WorkTable::ID->value => $_POST[TagsTable::REF_WORK_ID->value] ])->get(); } @@ -58,8 +54,8 @@ return $entity; } - return $this->db->for(WorkPermalinksModel::TABLE)->insert($_POST) === true - ? new Response($_POST[WorkPermalinksModel::ID->value], 201) + return $this->db->for(PermalinksTable::NAME)->insert($_POST) === true + ? new Response($_POST[PermalinksTable::ID->value], 201) : new Response("Failed to add permalink to work entity", 500); } } \ No newline at end of file diff --git a/endpoints/work/tags/DELETE.php b/endpoints/work/tags/DELETE.php new file mode 100644 index 0000000..53549c9 --- /dev/null +++ b/endpoints/work/tags/DELETE.php @@ -0,0 +1,38 @@ +ruleset = new Ruleset(strict: true); + + $this->ruleset->GET([ + (new Rules(TagsTable::REF_WORK_ID->value)) + ->min(1) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), + + (new Rules(TagsTable::NAME->value)) + ->type(Type::ENUM, TagsNameEnum::names()) + ]); + + $ruleset->validate_or_exit(); + + parent::__construct(); + } + + public function main(): Response { + return $this->db->for(TagsTable::NAME)->delete($_POST) === true + ? new Response(RESP_DELETE_OK) + : new Response("Failed to delete value from document", 500); + } + } \ No newline at end of file diff --git a/endpoints/work/tags/GET.php b/endpoints/work/tags/GET.php new file mode 100644 index 0000000..2e788a7 --- /dev/null +++ b/endpoints/work/tags/GET.php @@ -0,0 +1,47 @@ +ruleset = new Ruleset(strict: true); + + $this->ruleset->GET([ + (new Rules(TagsTable::REF_WORK_ID->value)) + ->min(1) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), + + (new Rules(TagsTable::NAME->value)) + ->type(Type::ENUM, TagsNameEnum::names()) + ]); + + $ruleset->validate_or_exit(); + + parent::__construct(); + } + + public function main(): Response { + $response = $this->db->for(TagsTable::NAME) + ->where($_GET) + ->select([ + TagsTable::REF_WORK_ID->value, + TagsTable::NAME->value + ]); + + return $response->num_rows > 0 + ? new Response(parent::index_array_by_key($response->fetch_all(MYSQLI_ASSOC), TagsTable::REF_WORK_ID->value)) + : new Response([], 404); + } + } \ No newline at end of file diff --git a/endpoints/work/tags/POST.php b/endpoints/work/tags/POST.php new file mode 100644 index 0000000..2856686 --- /dev/null +++ b/endpoints/work/tags/POST.php @@ -0,0 +1,59 @@ +ruleset = new Ruleset(strict: true); + + $this->ruleset->POST([ + (new Rules(TagsTable::REF_WORK_ID->value)) + ->required() + ->min(1) + ->max(parent::MYSQL_VARCHAR_MAX_LENGTH), + + (new Rules(TagsTable::NAME->value)) + ->required() + ->type(Type::ENUM, TagsNameEnum::names()) + ]); + + $ruleset->validate_or_exit(); + + parent::__construct(); + } + + private static function get_entity(): Response { + return (new Call(Endpoints::WORK->value))->params([ + WorkTable::ID->value => $_POST[TagsTable::REF_WORK_ID->value] + ])->get(); + } + + public function main(): Response { + // Bail out if work entity could not be fetched + $entity = self::get_entity(); + if (!$entity->ok) { + return $entity; + } + + return $this->db->for(TagsTable::NAME)->insert($_POST) === true + ? new Response($_POST[TagsTable::REF_WORK_ID->value], 201) + : new Response("Failed to add tag to work entity", 500); + } + } \ No newline at end of file diff --git a/public/about/battlestation.php b/public/about/battlestation.php index 21a753f..127abf3 100644 --- a/public/about/battlestation.php +++ b/public/about/battlestation.php @@ -5,22 +5,22 @@ use VLW\Client\API; use VLW\API\Endpoints; - use VLW\API\Databases\VLWdb\Models\Battlestation\{ - MbModel, - CpuModel, - GpuModel, - PsuModel, - DramModel, - StorageModel, - ChassisModel + use VLW\Database\Tables\Battlestation\{ + MbTable, + CpuTable, + GpuTable, + PsuTable, + DramTable, + StorageTable, + ChassisTable }; - use VLW\API\Databases\VLWdb\Models\Battlestation\Config\{ - MbPsuModel, - MbGpuModel, - MbDramModel, + use VLW\Database\Tables\Battlestation\Config\{ + MbPsuTable, + MbGpuTable, + MbDramTable, ConfigModel, - MbStorageModel, - ChassisMbModel, + MbStorageTable, + ChassisMbTable, MbCpuCoolerModel, MbStorageSlotFormfactorEnum }; @@ -29,22 +29,22 @@ require_once VV::root("api/src/Endpoints.php"); // Load hardware database models - require_once VV::root("api/src/databases/models/Battlestation/Mb.php"); - require_once VV::root("api/src/databases/models/Battlestation/Cpu.php"); - require_once VV::root("api/src/databases/models/Battlestation/Gpu.php"); - require_once VV::root("api/src/databases/models/Battlestation/Psu.php"); - require_once VV::root("api/src/databases/models/Battlestation/Dram.php"); - require_once VV::root("api/src/databases/models/Battlestation/Storage.php"); - require_once VV::root("api/src/databases/models/Battlestation/Chassis.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Mb.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Cpu.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Gpu.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Psu.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Dram.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Storage.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Chassis.php"); // Load hardware config database models - require_once VV::root("api/src/databases/models/Battlestation/Config/MbPsu.php"); - require_once VV::root("api/src/databases/models/Battlestation/Config/MbGpu.php"); - require_once VV::root("api/src/databases/models/Battlestation/Config/MbDram.php"); - require_once VV::root("api/src/databases/models/Battlestation/Config/Config.php"); - require_once VV::root("api/src/databases/models/Battlestation/Config/MbStorage.php"); - require_once VV::root("api/src/databases/models/Battlestation/Config/ChassisMb.php"); - require_once VV::root("api/src/databases/models/Battlestation/Config/MbCpuCooler.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Config/MbPsu.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Config/MbGpu.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Config/MbDram.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Config/Config.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Config/MbStorage.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Config/ChassisMb.php"); + require_once VV::root("api/src/Database/Models/Battlestation/Config/MbCpuCooler.php"); const GIGA = 0x3B9ACA00; const MEGA = 0xF4240; @@ -73,7 +73,7 @@ // Get motherboard details by ref_mb_id from config $motherboard = $api->call(Endpoints::BATTLESTATION_MB->value)->params([ - MbModel::ID->value => $config[ChassisMbModel::REF_MB_ID->value] + MbTable::ID->value => $config[ChassisMbTable::REF_MB_ID->value] ])->get()->json()[0]; ?> @@ -89,9 +89,9 @@ data-gpu="" data-dram="" data-case="" - data-drives-mdottwo="value), MbStorageSlotFormfactorEnum::MDOTTWO->value)) ?>" - data-drives-twodotfive="value), MbStorageSlotFormfactorEnum::TWODOTFIVE->value)) ?>" - data-drives-threedotfive="value), MbStorageSlotFormfactorEnum::THREEDOTFIVE->value)) ?>" + data-drives-mdottwo="value), MbStorageSlotFormfactorEnum::MDOTTWO->value)) ?>" + data-drives-twodotfive="value), MbStorageSlotFormfactorEnum::TWODOTFIVE->value)) ?>" + data-drives-threedotfive="value), MbStorageSlotFormfactorEnum::THREEDOTFIVE->value)) ?>" >
@@ -100,38 +100,38 @@

Motherboard

-

value] ?> value] ?>

+

value] ?> value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?? "No LAN" ?>

+

value] ?? "No LAN" ?>

-

value] ?? "No WLAN" ?>

+

value] ?? "No WLAN" ?>

-

value] ?? "No Bluetooth" ?>

+

value] ?? "No Bluetooth" ?>

-

value]) ?>

+

value]) ?>

- value]): ?> + value]): ?>

Yes

@@ -146,35 +146,35 @@ call(Endpoints::BATTLESTATION_CHASSIS->value)->params([ - ChassisModel::ID->value => $mb_chassis[ChassisMbModel::REF_CHASSIS_ID->value] + ChassisTable::ID->value => $mb_chassis[ChassisMbTable::REF_CHASSIS_ID->value] ])->get()->json()[0]; ?>

Case

-

value] ?> value] ?>

+

value] ?> value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value]) ?>

+

value]) ?>

- value]): ?> + value]): ?>

Yes

@@ -189,47 +189,47 @@ call(Endpoints::BATTLESTATION_CPU->value)->params([ - CpuModel::ID->value => $mb_cpu[MbCpuCoolerModel::REF_CPU_ID->value] + CpuTable::ID->value => $mb_cpu[MbCpuCoolerModel::REF_CPU_ID->value] ])->get()->json()[0]; ?>

CPU

-

value] ?> value] ?>

+

value] ?> value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] / GIGA ?>GHz

+

value] / GIGA ?>GHz

-

value] / GIGA ?>GHz

+

value] / GIGA ?>GHz

-

value] + $cpu[CpuModel::CORE_COUNT_EFFICIENCY->value] ?> (value] ?>/value] ?>)

+

value] + $cpu[CpuTable::CORE_COUNT_EFFICIENCY->value] ?> (value] ?>/value] ?>)

-

value] ?>

+

value] ?>

-

value]) ?>

+

value]) ?>

- value]): ?> + value]): ?>

Yes

@@ -254,39 +254,39 @@ call(Endpoints::BATTLESTATION_GPU->value)->params([ - GpuModel::ID->value => $mb_gpu[MbGpuModel::REF_GPU_ID->value] + GpuTable::ID->value => $mb_gpu[MbGpuTable::REF_GPU_ID->value] ])->get()->json()[0]; ?>

GPU

-

value] ?> value] ?>

+

value] ?> value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] / GIGA ?>GB

+

value] / GIGA ?>GB

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value]) ?>

+

value]) ?>

- value]): ?> + value]): ?>

Yes

@@ -301,39 +301,39 @@ call(Endpoints::BATTLESTATION_PSU->value)->params([ - PsuModel::ID->value => $mb_psu[MbPsuModel::REF_PSU_ID->value] + PsuTable::ID->value => $mb_psu[MbPsuTable::REF_PSU_ID->value] ])->get()->json()[0]; ?>

PSU

-

value] ?> value] ?> value] ?>W

+

value] ?> value] ?> value] ?>W

-

value] ?>W

+

value] ?>W

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] === "TRUE" ? "Yes" : "No" ?>

+

value] === "TRUE" ? "Yes" : "No" ?>

-

value] ?? "None" ?>

+

value] ?? "None" ?>

-

value]) ?>

+

value]) ?>

- value]): ?> + value]): ?>

Yes

@@ -354,54 +354,54 @@ call(Endpoints::BATTLESTATION_DRAM->value)->params([ - DramModel::ID->value => $mb_dram[MbDramModel::REF_DRAM_ID->value] + DramTable::ID->value => $mb_dram[MbDramTable::REF_DRAM_ID->value] ])->get()->json()[0]; ?>
-

DRAM - value] ?>

-

value] ?> - value] / GIGA ?>GB - value] / MEGA ?>MHz +

DRAM - value] ?>

+

value] ?> + value] / GIGA ?>GB + value] / MEGA ?>MHz

-

value] / GIGA ?>GB

+

value] / GIGA ?>GB

-

value] / MEGA ?>MHz

+

value] / MEGA ?>MHz

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] === "TRUE" ? "Yes" : "No" ?>

+

value] === "TRUE" ? "Yes" : "No" ?>

-

value] === "TRUE" ? "Yes" : "No" ?>

+

value] === "TRUE" ? "Yes" : "No" ?>

-

value]) ?>

+

value]) ?>

- value]): ?> + value]): ?>

Yes

@@ -411,11 +411,11 @@
-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

@@ -433,46 +433,46 @@ call(Endpoints::BATTLESTATION_STORAGE->value)->params([ - StorageModel::ID->value => $mb_storage[MbStorageModel::REF_STORAGE_ID->value] + StorageTable::ID->value => $mb_storage[MbStorageTable::REF_STORAGE_ID->value] ])->get()->json()[0]; ?>
-

value] ?> value] ?>

+

value] ?> value] ?>

- value] ?> - value] / GIGA) ?>GB + value] ?> + value] / GIGA) ?>GB

-

value] ?>

+

value] ?>

-

value] / GIGA) ?>GB

+

value] / GIGA) ?>GB

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value] ?>

+

value] ?>

-

value]) ?>

+

value]) ?>

- value]): ?> + value]): ?>

Yes

@@ -482,7 +482,7 @@
-

value] ?>

+

value] ?>

diff --git a/public/contact.php b/public/contact.php index 8d02550..26dc109 100644 --- a/public/contact.php +++ b/public/contact.php @@ -5,12 +5,12 @@ use VLW\Client\API; use VLW\API\Endpoints; - use VLW\API\Databases\VLWdb\Models\Messages\MessagesModel; + use VLW\Database\Tables\Messages\MessagesTable; require_once VV::root("src/client/API.php"); require_once VV::root("api/src/Endpoints.php"); - require_once VV::root("api/src/databases/models/Messages/Messages.php"); + require_once VV::root("api/src/Database/Models/Messages/Messages.php"); // Connect to VLW API $api = new API(); @@ -104,8 +104,8 @@ // Send message via API $send = $api->call(Endpoints::MESSAGES->value)->post([ - MessagesModel::EMAIL->value => $_POST[MessagesModel::EMAIL->value], - MessagesModel::MESSAGE->value => $_POST[MessagesModel::MESSAGE->value] + MessagesTable::EMAIL->value => $_POST[MessagesTable::EMAIL->value], + MessagesTable::MESSAGE->value => $_POST[MessagesTable::MESSAGE->value] ]); ?> @@ -128,11 +128,11 @@
- + - + +
diff --git a/public/work.php b/public/work.php index 85f7bb8..6aae4f1 100644 --- a/public/work.php +++ b/public/work.php @@ -5,12 +5,12 @@ use VLW\Client\API; use VLW\API\Endpoints; - use VLW\API\Databases\VLWdb\Models\Work\WorkModel; + use VLW\Database\Tables\Work\WorkTable; require_once VV::root("src/client/API.php"); require_once VV::root("api/src/Endpoints.php"); - require_once VV::root("api/src/databases/models/Work/Work.php"); + require_once VV::root("api/src/Database/Models/Work/Work.php"); // Number of items from the timeline to display on this page const TIMELINE_PREVIEW_LIMIT = 5; @@ -25,17 +25,17 @@ // Get work items from endpoint $this->resp = $this->call(Endpoints::WORK->value)->params([ - WorkModel::IS_LISTED->value => true + WorkTable::IS_LISTED->value => true ])->get(); } private function get_item(string $key): array { - $idx = array_search($key, array_column($this->resp->json(), WorkModel::ID->value)); + $idx = array_search($key, array_column($this->resp->json(), WorkTable::ID->value)); return $this->resp->json()[$idx]; } public function get_summary(string $key): string { - return $this->resp->ok ? $this->get_item($key)[WorkModel::SUMMARY->value] : self::ERROR_MSG; + return $this->resp->ok ? $this->get_item($key)[WorkTable::SUMMARY->value] : self::ERROR_MSG; } } diff --git a/public/work/timeline.php b/public/work/timeline.php index 3b38358..55ea9bb 100644 --- a/public/work/timeline.php +++ b/public/work/timeline.php @@ -6,18 +6,18 @@ use VLW\Client\API; use VLW\API\Endpoints; - use VLW\API\Databases\VLWdb\Models\Work\{ - WorkModel, - WorkTagsModel, - WorkActionsModel + use VLW\Database\Tables\Work\{ + WorkTable, + TagsTable, + ActionsTable }; require_once VV::root("src/client/API.php"); require_once VV::root("api/src/Endpoints.php"); - require_once VV::root("api/src/databases/models/Work/Work.php"); - require_once VV::root("api/src/databases/models/Work/WorkTags.php"); - require_once VV::root("api/src/databases/models/Work/WorkActions.php"); + require_once VV::root("api/src/Database/Models/Work/Work.php"); + require_once VV::root("api/src/Database/Models/Work/WorkTags.php"); + require_once VV::root("api/src/Database/Models/Work/WorkActions.php"); $work = new class extends API { private const API_PARAM_LIMIT = "limit"; @@ -30,7 +30,7 @@ parent::__construct(); $this->resp = $this->call(Endpoints::WORK->value)->params([ - WorkModel::IS_LISTED->value => true, + WorkTable::IS_LISTED->value => true, self::API_PARAM_LIMIT => $_GET[self::API_PARAM_LIMIT] ?? null ])->get(); @@ -56,22 +56,22 @@ // Create array of arrays ordered by decending year, month, day, items foreach ($this->resp->json() as $row) { // Create array for current year if it doesn't exist - if (!array_key_exists($row[WorkModel::DATE_YEAR->value], $timeline)) { - $timeline[$row[WorkModel::DATE_YEAR->value]] = []; + if (!array_key_exists($row[WorkTable::DATE_YEAR->value], $timeline)) { + $timeline[$row[WorkTable::DATE_YEAR->value]] = []; } // Create array for current month if it doesn't exist - if (!array_key_exists($row[WorkModel::DATE_MONTH->value], $timeline[$row[WorkModel::DATE_YEAR->value]])) { - $timeline[$row[WorkModel::DATE_YEAR->value]][$row[WorkModel::DATE_MONTH->value]] = []; + if (!array_key_exists($row[WorkTable::DATE_MONTH->value], $timeline[$row[WorkTable::DATE_YEAR->value]])) { + $timeline[$row[WorkTable::DATE_YEAR->value]][$row[WorkTable::DATE_MONTH->value]] = []; } // Create array for current day if it doesn't exist - if (!array_key_exists($row[WorkModel::DATE_DAY->value], $timeline[$row[WorkModel::DATE_YEAR->value]][$row[WorkModel::DATE_MONTH->value]])) { - $timeline[$row[WorkModel::DATE_YEAR->value]][$row[WorkModel::DATE_MONTH->value]][$row[WorkModel::DATE_DAY->value]] = []; + if (!array_key_exists($row[WorkTable::DATE_DAY->value], $timeline[$row[WorkTable::DATE_YEAR->value]][$row[WorkTable::DATE_MONTH->value]])) { + $timeline[$row[WorkTable::DATE_YEAR->value]][$row[WorkTable::DATE_MONTH->value]][$row[WorkTable::DATE_DAY->value]] = []; } // Append item to ordered array - $timeline[$row[WorkModel::DATE_YEAR->value]][$row[WorkModel::DATE_MONTH->value]][$row[WorkModel::DATE_DAY->value]][] = $row; + $timeline[$row[WorkTable::DATE_YEAR->value]][$row[WorkTable::DATE_MONTH->value]][$row[WorkTable::DATE_DAY->value]][] = $row; } return $timeline; @@ -142,35 +142,35 @@
- get_tags($item[WorkModel::ID->value])): ?> + get_tags($item[WorkTable::ID->value])): ?>
- get_tags($item[WorkModel::ID->value]) as $tag): ?> -

value] ?>

+ get_tags($item[WorkTable::ID->value]) as $tag): ?> +

value] ?>

- value])): ?> -

value] ?>

+ value])): ?> +

value] ?>

-

value] ?>

+

value] ?>

- get_actions($item[WorkModel::ID->value])): ?> + get_actions($item[WorkTable::ID->value])): ?> - get_actions($item[WorkModel::ID->value]) as $action): ?> - - diff --git a/src/client/API.php b/src/API/API.php similarity index 70% rename from src/client/API.php rename to src/API/API.php index bb314eb..2f5dd7d 100644 --- a/src/client/API.php +++ b/src/API/API.php @@ -1,10 +1,10 @@ db = new MySQL( + $_ENV["api_database"]["host"], + $_ENV["api_database"]["user"], + $_ENV["api_database"]["pass"], + $_ENV["api_database"]["db"], + ); + } + + // Return all rows from a table using $_GET paramters as the WHERE clause as a Reflect\Response + public function list(string $table, array $columns, array $order = null): Response { + $resp = $this->for($table)->where($_GET); + + // Optionally order rows by columns + if ($order) { + $resp = $resp->order($order); + } + + // Return all matched rows or a 404 with an empty array if there were not results + $resp = $resp->select($columns); + return $resp && $resp->num_rows > 0 + ? new Response($resp->fetch_all(MYSQLI_ASSOC)) + : new Response([], 404); + } + } \ No newline at end of file diff --git a/src/Database/Models/Model.php b/src/Database/Models/Model.php new file mode 100644 index 0000000..79327cf --- /dev/null +++ b/src/Database/Models/Model.php @@ -0,0 +1,34 @@ +row = self::first(self::list($endpoint, $params)); + } + + public static function first(array $array): array { + return $array && is_array(array_values($array)[0]) ? $array[0] : $array; + } + + public static function list(Endpoints $endpoint, array $params = []): array { + $resp = (new API())->call($endpoint->value)->params($params)->get(); + return $resp->ok ? $resp->json() : []; + } + + public function get(string $key): mixed { + return $this->data[$key] ?? null; + } + } \ No newline at end of file diff --git a/src/Database/Models/Timeline/Timeline.php b/src/Database/Models/Timeline/Timeline.php new file mode 100644 index 0000000..02ab358 --- /dev/null +++ b/src/Database/Models/Timeline/Timeline.php @@ -0,0 +1,41 @@ +value => $this->id + ]); + } + + public static function list(): array { + return array_map(fn(array $item): Timeline => new Timeline($item[TimelineTable::ID->value]), parent::list(Endpoints::TIMELINE)); + } + + public function work(): Work { + return new Work($this->get(TimelineTable::REF_WORK_ID->value)); + } + + public function year(): int { + return $this->get(TimelineTable::YEAR->value); + } + + public function month(): int { + return $this->get(TimelineTable::MONTH->value); + } + + public function day(): int { + return $this->get(TimelineTable::DAY->value); + } + } \ No newline at end of file diff --git a/src/Database/Models/Work/Work.php b/src/Database/Models/Work/Work.php new file mode 100644 index 0000000..1d33d21 --- /dev/null +++ b/src/Database/Models/Work/Work.php @@ -0,0 +1,5 @@ +