Browse Source

added api folder donde el adminstrador se conecta al db dentro del servidor

Luis Ortiz 1 year ago
parent
commit
a515175b92
5 changed files with 126 additions and 0 deletions
  1. 15
    0
      .expo/README.md
  2. 9
    0
      .expo/packager-info.json
  3. 10
    0
      .expo/settings.json
  4. 4
    0
      api/.htaccess
  5. 88
    0
      api/index.php

+ 15
- 0
.expo/README.md View File

@@ -0,0 +1,15 @@
1
+> Why do I have a folder named ".expo" in my project?
2
+
3
+The ".expo" folder is created when an Expo project is started using "expo start" command.
4
+
5
+> What do the files contain?
6
+
7
+- "devices.json": contains information about devices that have recently opened this project. This is used to populate the "Development sessions" list in your development builds.
8
+- "packager-info.json": contains port numbers and process PIDs that are used to serve the application to the mobile device/simulator.
9
+- "settings.json": contains the server configuration that is used to serve the application manifest.
10
+
11
+> Should I commit the ".expo" folder?
12
+
13
+No, you should not share the ".expo" folder. It does not contain any information that is relevant for other developers working on the project, it is specific to your machine.
14
+
15
+Upon project creation, the ".expo" folder is already added to your ".gitignore" file.

+ 9
- 0
.expo/packager-info.json View File

@@ -0,0 +1,9 @@
1
+{
2
+  "expoServerPort": null,
3
+  "packagerPort": 19000,
4
+  "packagerPid": null,
5
+  "expoServerNgrokUrl": null,
6
+  "packagerNgrokUrl": null,
7
+  "ngrokPid": null,
8
+  "webpackServerPort": null
9
+}

+ 10
- 0
.expo/settings.json View File

@@ -0,0 +1,10 @@
1
+{
2
+  "hostType": "lan",
3
+  "lanType": "ip",
4
+  "dev": true,
5
+  "minify": false,
6
+  "urlRandomness": null,
7
+  "https": false,
8
+  "scheme": null,
9
+  "devClient": false
10
+}

+ 4
- 0
api/.htaccess View File

@@ -0,0 +1,4 @@
1
+RewriteEngine On
2
+RewriteCond %{REQUEST_FILENAME} !-d
3
+RewriteCond %{REQUEST_FILENAME} !-f
4
+RewriteRule ^ index.php [L]

+ 88
- 0
api/index.php View File

@@ -0,0 +1,88 @@
1
+<?PHP
2
+  header('Access-Control-Allow-Origin: *');
3
+  header('Access-Control-Allow-Headers: *');
4
+  header('Access-Control-Allow-Methods: *');
5
+  header('Content-Type: application/json; charset=UTF-8');
6
+
7
+  //Database Connection
8
+  $host = 'localhost';
9
+  $dbname = 'censo';
10
+  $user = 'luis.ortiz79';
11
+  $passw = '27gnpXrDmPUPzEPQ';
12
+
13
+  try{
14
+    $connection = mysqli_connect($host, $user, $passw, $dbname) or $error = 1;
15
+  }
16
+  catch(Exception $ex){
17
+    print("Error connecting to database: ". $ex->getMessage()) and die();
18
+  }
19
+
20
+  $method = $_SERVER['REQUEST_METHOD'];
21
+  switch($method){
22
+    case "GET":
23
+        $sql = "SELECT * FROM noticias";
24
+        $path = explode('/', $_SERVER['REQUEST_URI']);
25
+        if(isset($path[3]) && is_numeric($path[3])) {
26
+            $sql .= " WHERE id = :id";
27
+            $stmt = $conn->prepare($sql);
28
+            $stmt->bindParam(':id', $path[3]);
29
+            $stmt->execute();
30
+            $users = $stmt->fetch(PDO::FETCH_ASSOC);
31
+        } else {
32
+            $stmt = $conn->prepare($sql);
33
+            $stmt->execute();
34
+            $users = $stmt->fetchAll(PDO::FETCH_ASSOC);
35
+        }
36
+
37
+        echo json_encode($users);
38
+        break;
39
+
40
+    case "POST":
41
+      $user = json_decode(file_get_contents('php://input') );
42
+      $sql = "INSERT INTO noticias(id, title, subject, created_at) VALUES(null, :title, :subject, :created_at)";
43
+      $stmt = $conn->prepare($sql);
44
+      $created_at = date('Y-m-d');
45
+      $stmt->bindParam(':title', $user->title);
46
+      $stmt->bindParam(':subject', $user->subject);
47
+      $stmt->bindParam(':created_at', $created_at);
48
+
49
+      if($stmt->execute()) {
50
+          $response = ['status' => 1, 'message' => 'Record updated successfully.'];
51
+      } else {
52
+          $response = ['status' => 0, 'message' => 'Failed to update record.'];
53
+      }
54
+      echo json_encode($response);
55
+      break;
56
+
57
+    case "PUT":
58
+      $user = json_decode( file_get_contents('php://input') );
59
+      $sql = "UPDATE noticias SET title= :title, subject = :subject, updated_at = :updated_at WHERE id = :id";
60
+      $stmt = $conn->prepare($sql);
61
+      $updated_at = date('Y-m-d');
62
+      $stmt->bindParam(':title', $user->title);
63
+      $stmt->bindParam(':subject', $user->subject);
64
+      $stmt->bindParam(':updated_at', $updated_at);
65
+
66
+      if($stmt->execute()) {
67
+          $response = ['status' => 1, 'message' => 'Record updated successfully.'];
68
+      } else {
69
+          $response = ['status' => 0, 'message' => 'Failed to update record.'];
70
+      }
71
+      echo json_encode($response);
72
+      break;
73
+
74
+      case "DELETE":
75
+          $sql = "DELETE FROM noticias WHERE id = :id";
76
+          $path = explode('/', $_SERVER['REQUEST_URI']);
77
+
78
+          $stmt = $conn->prepare($sql);
79
+          $stmt->bindParam(':id', $path[3]);
80
+          if($stmt->execute()) {
81
+              $response = ['status' => 1, 'message' => 'Record deleted successfully.'];
82
+          } else {
83
+              $response = ['status' => 0, 'message' => 'Failed to delete record.'];
84
+          }
85
+          echo json_encode($response);
86
+          break;
87
+    }
88
+?>