예제 #1
0
 /**
  * @SWG\Property(name="type", type="AddonsType", required=true)
  */
 public function get()
 {
     $addonsType = $this->_model->type()->first();
     $addonsTypeView = new ModelViews\AddonsType($addonsType);
     $result = ['id' => $this->_model->id, 'name' => $this->_model->name, 'image' => $this->_model->image, 'price_type' => $this->_model->price_type, 'price' => $this->_model->price, 'type' => $addonsTypeView->get()];
     return $result;
 }
예제 #2
0
 /**
  * @SWG\Api(
  *   path="/addon/get/{id}",
  *   @SWG\Operation(
  *     nickname="Get addon",
  *     method="GET",
  *     summary="Find addon by ID",
  *     notes="Returns addon",
  *     type="Addon",
  *     authorizations={},
  *     @SWG\Parameter(
  *       name="id",
  *       description="ID of addon",
  *       required=true,
  *       type="integer",
  *       format="int64",
  *       paramType="path",
  *       allowMultiple=false
  *     ),
  *     @SWG\ResponseMessage(code=404, message="Format not found"),
  *     @SWG\ResponseMessage(code=500, message="Internal server error")
  *   )
  * )
  */
 public function get($id)
 {
     $statusCode = 200;
     $response = [];
     try {
         $validator = Validator::make(['id' => $id], ['id' => 'required|numeric']);
         if ($validator->fails()) {
             $response = ['error' => $validator->errors()];
             $statusCode = 500;
         } else {
             $addonModel = Models\Addon::where('id', $id)->first();
             if (!isset($addonModel)) {
                 throw new ModelNotFoundException();
             }
             $addonView = new ModelViews\Addon($addonModel);
             $addonsTypeView = new ModelViews\AddonsType($addonModel->type()->first());
             $addon = $addonView->get();
             $addon['type'] = $addonsTypeView->get();
             $response = $addon;
         }
     } catch (ModelNotFoundException $e) {
         $response = ['error' => 'Addon doesn\'t exists'];
         $statusCode = 404;
     } finally {
         return \Response::json($response, $statusCode);
     }
 }
예제 #3
0
 /**
  * @SWG\Api(
  *   path="/addons_type/all",
  *   @SWG\Operation(
  *     nickname="Get all addons type",
  *     method="GET",
  *     summary="Find all addons type",
  *     notes="Returns all addons type",
  *     type="array",
  *     @SWG\Items("AddonsType"),
  *     authorizations={}
  *   )
  * )
  */
 public function all()
 {
     $statusCode = 200;
     $response = [];
     $addonstypeModels = Models\AddonsType::all();
     foreach ($addonstypeModels as $addonstypeModel) {
         $addonsTypeView = new ModelViews\AddonsType($addonstypeModel);
         $response[] = $addonsTypeView->get();
     }
     return \Response::json($response, $statusCode);
 }