diff --git a/controllers/locations.php b/controllers/locations.php index b9b1b66..c0067c4 100644 --- a/controllers/locations.php +++ b/controllers/locations.php @@ -1,26 +1,26 @@ person_id, $body->job_type, $body->company_id); + $newLocation = new Location(null, $body->street, $body->city, $body->state); - $allJobs = Jobs::create($newJob); + $allLocations = Locations::create($newLocation); - echo json_encode($allJobs); + echo json_encode($allLocations); } else if ($_REQUEST['action'] === 'delete'){ - $allJobs = Jobs::delete($_REQUEST['id']); - echo json_encode($allJobs); + $allLocations = Locations::delete($_REQUEST['id']); + echo json_encode($allLocations); } else if ($_REQUEST['action'] === 'update'){ $requestBody = file_get_contents('php://input'); $body = json_decode($requestBody); - $updatedJob = new Job(null, $body->person_id, $body->job_type, $body->company_id); - $allJobs = Jobs::update($_REQUEST['id'], $updatedJob); + $updatedLocation = new Location(null, $body->street, $body->city, $body->state); + $allLocations = Locations::update($_REQUEST['id'], $updatedLocation); - echo json_encode($allJobs); + echo json_encode($allLocations); } diff --git a/database/sql/locations/create.sql b/database/sql/locations/create.sql index 546737f..f7e5ca8 100644 --- a/database/sql/locations/create.sql +++ b/database/sql/locations/create.sql @@ -1 +1 @@ -INSERT INTO jobs (person_id, job_type, company_id) VALUES ($1, $2, $3) +INSERT INTO locations (street, city, state) VALUES ($1, $2, $3) diff --git a/database/sql/locations/delete.sql b/database/sql/locations/delete.sql index 837e636..8598016 100644 --- a/database/sql/locations/delete.sql +++ b/database/sql/locations/delete.sql @@ -1 +1 @@ -DELETE FROM jobs WHERE id = $1 +DELETE FROM locations WHERE id = $1 diff --git a/database/sql/locations/find.sql b/database/sql/locations/find.sql index 898df78..bdba063 100644 --- a/database/sql/locations/find.sql +++ b/database/sql/locations/find.sql @@ -1 +1 @@ -SELECT * FROM jobs +SELECT * FROM locations diff --git a/database/sql/locations/update.sql b/database/sql/locations/update.sql index 1d9c94e..b0531ea 100644 --- a/database/sql/locations/update.sql +++ b/database/sql/locations/update.sql @@ -1 +1 @@ -UPDATE jobs SET person_id = $1, job_type = $2, company_id = $3 WHERE id = $4 +UPDATE locations SET street = $1, city = $2, state = $3 WHERE id = $4 diff --git a/models/location.php b/models/location.php index 9d66df1..52be2b8 100644 --- a/models/location.php +++ b/models/location.php @@ -1,47 +1,45 @@ id = $id; - if($person_id){ - $this->person_id = $person_id; - } - $this->job_type = $job_type; - if($company_id){ - $this->company_id = $company_id; - } + $this->street = $street; + $this->city = $city; + $this->state = $state; } } -class Jobs { +class Locations { static function find(){ - $query = file_get_contents(__DIR__ . '/../database/sql/jobs/find.sql'); + $query = file_get_contents(__DIR__ . '/../database/sql/locations/find.sql'); $result = pg_query($query); - $jobs = array(); + $locations = array(); while($data = pg_fetch_object($result)){ - $jobs[] = new Job(intval($data->id), intval($data->person_id), $data->job_type, intval($data->company_id)); + $locations[] = new Location(intval($data->id), $data->street, $data->city, $data->state); } - return $jobs; + return $locations; } - static function create($job){ - $query = file_get_contents(__DIR__ . '/../database/sql/jobs/create.sql'); - $result = pg_query_params($query, array($job->person_id, $job->job_type, $job->company_id)); + static function create($location){ + $query = file_get_contents(__DIR__ . '/../database/sql/locations/create.sql'); + $result = pg_query_params($query, array($location->street, $location->city, $location->state)); return self::find(); } static function delete($id){ - $query = file_get_contents(__DIR__ . '/../database/sql/jobs/delete.sql'); + $query = file_get_contents(__DIR__ . '/../database/sql/locations/delete.sql'); $result = pg_query_params($query, array($id)); return self::find(); } - static function update($id, $updatedJob){ - $query = file_get_contents(__DIR__ . '/../database/sql/jobs/update.sql'); - $result = pg_query_params($query, array($updatedJob->person_id, $updatedJob->job_type, $updatedJob->company_id, $id)); + static function update($id, $updatedLocation){ + $query = file_get_contents(__DIR__ . '/../database/sql/locations/update.sql'); + $result = pg_query_params($query, array($updatedLocation->street, $updatedLocation->city, $updatedLocation->state, $id)); return self::find(); }