Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
asilvafx committed Dec 24, 2024
1 parent 53b482d commit a9a1276
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
$f3->route('GET|POST /' . $f3->get('SITE.uri_backend') . '/@slug*', 'Backend->Base');

// Load api routes
$f3->route('GET|POST|DELETE /v1/@slug', 'Api->Base');
$f3->route('GET|PUT /v1/@slug/@search/@value', 'Api->Base');
$f3->route('GET|POST|PUT|DELETE /v1/@slug', 'Api->Base');
$f3->route('GET|PUT|DELETE /v1/@slug/@search/@value', 'Api->Base');

// Load WebAuthn Routes
$f3->route('GET|POST /web/authn/attestation/options', 'WebAuthn->Options');
Expand Down
26 changes: 18 additions & 8 deletions app/core/models/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ function Base($f3, $args)
$fields_cast = $siteDb->exec('SELECT * FROM ' . $requestData["collection"] . ' ' . $set_limit);
}

if ($fields_cast) {
$response->json('success', $fields_cast);
} else {
$response->json('error', null);
}
$response->json('success', $fields_cast);

} elseif ($requestData["method"] === 'post') {
if ($requestData["collection"] === 'UPLOAD' && isset($_FILES['file'])) {
Expand Down Expand Up @@ -221,9 +217,23 @@ function Base($f3, $args)
$response->json('error', 'Missing data or values.');
}
} elseif ($requestData["method"] === 'delete') {
if ($data) {
$siteDb->exec('DELETE FROM ' . $requestData["collection"] . ' WHERE ' . $data);
$response->json('success', 'Removed from collection.');

if (!empty($search) && !empty($value)) {
$tableName = $requestData["collection"];

// Prepare the SQL statement
$sql = "DELETE FROM $tableName WHERE $search = :value";

// Prepare and execute the statement
$stmt = $siteDb->prepare($sql);
$stmt->bindParam(':value', $value); // Bind the search value
$result = $stmt->execute();

if ($result) {
$response->json('success', 'Deleted from collection successfully.');
} else {
$response->json('error', 'Failed to delete data.');
}
} else {
$response->json('error', 'Missing data.');
}
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/routes/database/collections/view.htm
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ <h2 class="accordion-header" id="devConsoleTitle">
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));`,
PUT: `fetch('${uri}', {
PUT: `fetch('${uri}/id/xxx', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand All @@ -414,7 +414,7 @@ <h2 class="accordion-header" id="devConsoleTitle">
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));`,
DELETE: `fetch('${uri}', {
DELETE: `fetch('${uri}/id/xxx', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Expand Down
Empty file added ui/assets/index.css
Empty file.
Empty file added ui/assets/index.js
Empty file.
8 changes: 7 additions & 1 deletion ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@

</head>
<body>
<div id="root"></div>
<div id="root">

<h1>Free-API</h1>

</div>


</body>
</html>

0 comments on commit a9a1276

Please sign in to comment.