/** * This just deletes the newly create shift to keep redundant clutter out of the schema table */ private function deleteShiftExample($response) { $obj = json_decode($response->getBody()); $shift = WiwShift::findOne($obj->id); $shift->delete(); return true; }
/** * Updates and existing shift * * This function handles a few possibilities: * As a manager, I want to be able to change a shift, by updating the time details. * As a manager, I want to be able to assign a shift, by changing the employee that will work a shift. * @example PUT http://api.domain.com/shifts/update/155 --data '{"start_time":"2015-08-01 01:00:00"}' * NOTE: When testing with Postman, I have to use x-www-form-urlencode to submit body data * * @param integer $id The id of the shift to update * * @return array On success the updated shift is returned * */ public function actionUpdate($id) { $shift = WiwShift::findOne($id); $shift->attributes = \Yii::$app->request->getBodyParams(); if($shift->save()){ $shift->refresh(); return $shift; } else { $list = ''; foreach ($shift->errors as $error) { $list .= $error[0]; } throw new \yii\web\HttpException(422, 'Data validation failed. ' .$list); } }