diff --git a/.eslintrc.js b/.eslintrc.js index 7471118..eda5d6e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,3 +6,5 @@ module.exports = { 'no-console': 'off', }, }; + + diff --git a/appinfo/routes.php b/appinfo/routes.php index 370d168..2c8f1e9 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -1,5 +1,8 @@ [ + 'agency' => ['url' => '/agencys'], + ], 'routes' => [ ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], ] diff --git a/lib/Controller/AgencyController.php b/lib/Controller/AgencyController.php new file mode 100644 index 0000000..fa1c459 --- /dev/null +++ b/lib/Controller/AgencyController.php @@ -0,0 +1,77 @@ +service = $service; + } + + /** + * @NoAdminRequired + */ + public function index() { + return new DataResponse($this->service->findAll($this->Id)); + } + + /** + * @NoAdminRequired + * + * @param int $id + */ + public function show(int $id) { + return $this->handleNotFound(function () use ($id) { + return $this->service->find($id); + }); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + * + * @param string $title + * @param string $content + */ + public function create(string $name) { + return $this->service->create($name); + } + + /** + * @NoAdminRequired + * + * @param int $id + * @param string $title + */ + public function update(int $id, string $name) { + return $this->handleNotFound(function () use ($id, $name) { + return $this->service->update($id, $name); + }); + } + + /** + * @NoAdminRequired + * + * @param int $id + */ + public function destroy(int $id) { + return $this->handleNotFound(function () use ($id) { + return $this->service->delete($id); + }); + } + +} \ No newline at end of file diff --git a/lib/Controller/Errors.php b/lib/Controller/Errors.php new file mode 100644 index 0000000..c730dc1 --- /dev/null +++ b/lib/Controller/Errors.php @@ -0,0 +1,24 @@ + $e->getMessage()]; + return new DataResponse($message, Http::STATUS_NOT_FOUND); + } + } + +} \ No newline at end of file diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 91084fd..eec7c1c 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -8,19 +8,24 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Controller; use OCP\Util; +use OCA\Agency\Service\AgencyService; + class PageController extends Controller { protected $appName; + private $service; - public function __construct($appName, IRequest $request) { + public function __construct($appName, IRequest $request, AgencyService $service) { parent::__construct($appName, $request); $this->appName = $appName; - } + $this->service = $service; + } /** * @NoAdminRequired * @NoCSRFRequired */ + public function index() { Util::addScript($this->appName, 'agency-main'); Util::addStyle($this->appName, 'icons'); @@ -28,4 +33,4 @@ class PageController extends Controller { $response = new TemplateResponse($this->appName, 'main'); return $response; } -} +} \ No newline at end of file diff --git a/lib/Db/Agency.php b/lib/Db/Agency.php new file mode 100644 index 0000000..0114048 --- /dev/null +++ b/lib/Db/Agency.php @@ -0,0 +1,22 @@ +addType('id','integer'); + } + + public function jsonSerialize() { + return [ + 'id' => $this->id, + 'name' => $this->title, + ]; + } +} \ No newline at end of file diff --git a/lib/Db/AgencyMapper.php b/lib/Db/AgencyMapper.php new file mode 100644 index 0000000..7c8bc83 --- /dev/null +++ b/lib/Db/AgencyMapper.php @@ -0,0 +1,25 @@ +db->getQueryBuilder(); + + $qb->select('*') + ->from($this->getTableName()) + ->where( + $qb->expr()->eq('id', $qb->createNamedParameter($id)) + ); + + return $this->findEntity($qb); + } + +} \ No newline at end of file diff --git a/lib/Migration/Version000001Date20210521125400.php b/lib/Migration/Version000001Date20210521125400.php new file mode 100644 index 0000000..3cc2f3d --- /dev/null +++ b/lib/Migration/Version000001Date20210521125400.php @@ -0,0 +1,88 @@ +hasTable('agencys')) { + $table = $schema->createTable('agencys'); + $table->addColumn('id', 'integer', [ + 'autoincrement' => true, + 'notnull' => true, + ]); + $table->addColumn('name', 'string', [ + 'notnull' => true, + 'length' => 200 + ]); + + $table->addColumn('inhaber', 'string', [ + 'notnull' => false, + 'length' => 200 + ]); + + $table->addColumn('street', 'string', [ + 'notnull' => false, + 'length' => 200 + ]); + + $table->addColumn('city', 'string', [ + 'notnull' => false, + 'length' => 200 + ]); + + $table->addColumn('plz', 'string', [ + 'notnull' => false, + 'length' => 5 + ]); + + $table->addColumn('agency_email', 'string', [ + 'notnull' => false, + 'length' => 200 + ]); + + $table->addColumn('phone', 'string', [ + 'notnull' => false, + 'length' => 200 + ]); + + $table->setPrimaryKey(['id']); + } + + if (!$schema->hasTable('agency_user')) { + $table = $schema->createTable('agency_user'); + + $table->addColumn('id', 'integer', [ + 'autoincrement' => true, + 'notnull' => true, + ]); + + $table->rColumn('agency', 'integer', [ + 'notnull' => true, + 'length' => 64 + ]); + + $table->rColumn('user', 'integer', [ + 'notnull' => true, + 'length' => 64 + ]); + + $table->setPrimaryKey(['id']); + } + return $schema; + } +} \ No newline at end of file diff --git a/lib/Service/AgencyService.php b/lib/Service/AgencyService.php new file mode 100644 index 0000000..87902ff --- /dev/null +++ b/lib/Service/AgencyService.php @@ -0,0 +1,44 @@ +mapper = $mapper; + } + + private function handleException ($e) { + if ($e instanceof DoesNotExistException || + $e instanceof MultipleObjectsReturnedException) { + throw new NotFoundException($e->getMessage()); + } else { + throw $e; + } + } + + public function find(int $id) { + try { + return $this->mapper->find($id); + } catch(Exception $e) { + $this->handleException($e); + } + } + + public function create(string $name) { + $agency = new Agency(); + $agency->setName($name); + return $this->mapper->insert($agency); + } + +} \ No newline at end of file diff --git a/lib/Service/NotFoundException.php b/lib/Service/NotFoundException.php new file mode 100644 index 0000000..b483beb --- /dev/null +++ b/lib/Service/NotFoundException.php @@ -0,0 +1,4 @@ + diff --git a/src/main.js b/src/main.js index 99de136..32411b4 100644 --- a/src/main.js +++ b/src/main.js @@ -2,8 +2,20 @@ import Vue from 'vue' import App from './App' import VueRouter from 'vue-router' import Routes from './router/routes' +import VueFormulate from '@braid/vue-formulate' +import { de } from '@braid/vue-formulate-i18n' +import { BootstrapVue, IconsPlugin } from 'bootstrap-vue' +import 'bootstrap/dist/css/bootstrap.css' +import 'bootstrap-vue/dist/bootstrap-vue.css' Vue.use(VueRouter) +Vue.use(VueFormulate, { + plugins: [de], + locale: 'de', +}) +Vue.use(BootstrapVue) +Vue.use(IconsPlugin) +Vue.prototype.$hostname = 'http://localhost:8080' const router = new VueRouter({ routes: Routes, diff --git a/src/router/routes.js b/src/router/routes.js index 854b779..4047631 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -1,9 +1,9 @@ -import Dashboard from '../views/Dashboard' +import AgencyData from '../views/AgencyData' export default [ { path: '/', - name: 'dashboard', - component: Dashboard, + name: 'agencydata', + component: AgencyData, }, ] diff --git a/src/views/AgencyData.vue b/src/views/AgencyData.vue new file mode 100644 index 0000000..8e33e4d --- /dev/null +++ b/src/views/AgencyData.vue @@ -0,0 +1,34 @@ + + diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue deleted file mode 100644 index 81f0350..0000000 --- a/src/views/Dashboard.vue +++ /dev/null @@ -1,15 +0,0 @@ - -