You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.6 KiB

  1. <?php
  2. namespace api\controllers;
  3. use api\logic\Helper;
  4. use backend\modules\shop\models\ars\Collection;
  5. use Throwable;
  6. use Yii;
  7. /**
  8. * @author iron
  9. * @email weiriron@gmail.com
  10. */
  11. class CollectionController extends CommonController
  12. {
  13. public $modelClass = 'backend\modules\shop\models\ars\Collection';
  14. public $className = 'api\logic\CollectionLogic';
  15. public function actions()
  16. {
  17. $action = parent::actions();
  18. unset($action['delete']);
  19. unset($action['view']);
  20. $action['options'] = [
  21. 'class' => 'yii\rest\OptionsAction',
  22. 'collectionOptions' => ['DELETE', 'PUT', 'OPTIONS']
  23. ];
  24. return $action;
  25. }
  26. /**
  27. * @return object
  28. * @throws yii\base\InvalidConfigException
  29. */
  30. public function actionIndex()
  31. {
  32. $query = Collection::find()->where(['user_id' => Yii::$app->user->getId()]);
  33. return Helper::index($query);
  34. }
  35. /**
  36. * @return bool
  37. * @throws Yii\base\InvalidConfigException
  38. * @throws Yii\db\StaleObjectException
  39. * @throws Throwable
  40. * @throws yii\base\Exception
  41. * @throws yii\web\BadRequestHttpException
  42. * @throws yii\web\NotFoundHttpException
  43. * @throws yii\web\ServerErrorHttpException
  44. */
  45. public function actionUpdate()
  46. {
  47. return $this->object->update();
  48. }
  49. /**
  50. * @throws Throwable
  51. * @throws Yii\db\StaleObjectException
  52. * @throws yii\web\BadRequestHttpException
  53. * @throws yii\web\NotFoundHttpException
  54. * @throws yii\web\ServerErrorHttpException
  55. */
  56. public function actionDelete()
  57. {
  58. return $this->object->delete();
  59. }
  60. }