AgencyUser angebunden
This commit is contained in:
parent
b2e61c67fb
commit
69cd61db9e
|
|
@ -5,5 +5,6 @@ return [
|
||||||
],
|
],
|
||||||
'routes' => [
|
'routes' => [
|
||||||
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
||||||
|
['name' => 'agency#getagencyidbyuser', 'url' => '/getagencyidbyuser', 'verb' => 'GET'],
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,31 @@ declare(strict_types=1);
|
||||||
namespace OCA\Agency\Controller;
|
namespace OCA\Agency\Controller;
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
use OCP\IUserSession;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
|
|
||||||
use OCA\Agency\Service\AgencyService;
|
use OCA\Agency\Service\AgencyService;
|
||||||
|
use OCA\Agency\Service\AgencyUserService;
|
||||||
|
|
||||||
class AgencyController extends Controller {
|
class AgencyController extends Controller {
|
||||||
|
|
||||||
|
protected $userManager;
|
||||||
private $service;
|
private $service;
|
||||||
|
private $agencyuserservice;
|
||||||
private $Id;
|
private $Id;
|
||||||
|
protected $userSession;
|
||||||
|
protected $request;
|
||||||
|
|
||||||
use Errors;
|
use Errors;
|
||||||
|
|
||||||
public function __construct(string $AppName, IRequest $request,
|
public function __construct(string $AppName, IRequest $request, IUserSession $userSession, AgencyService $service, AgencyUserService $agencyuserservice){
|
||||||
AgencyService $service){
|
|
||||||
parent::__construct($AppName, $request);
|
parent::__construct($AppName, $request);
|
||||||
$this->service = $service;
|
$this->service = $service;
|
||||||
|
$this->agencyuserservice = $agencyuserservice;
|
||||||
|
$this->userSession = $userSession;
|
||||||
|
$this->request = $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -29,6 +38,16 @@ class AgencyController extends Controller {
|
||||||
return new DataResponse($this->service->findAll($this->Id));
|
return new DataResponse($this->service->findAll($this->Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
*/
|
||||||
|
public function getagencyidbyuser() {
|
||||||
|
$user = $this->userSession->getUser()->getUid();
|
||||||
|
$params = $this->agencyuserservice->getAgencyIdByUserUid($user);
|
||||||
|
return new JSONResponse($params);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
|
|
@ -43,7 +62,6 @@ class AgencyController extends Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
|
||||||
*
|
*
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string $content
|
* @param string $content
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace OCA\Agency\Controller;
|
||||||
|
|
||||||
|
use OCP\IRequest;
|
||||||
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
use OCP\AppFramework\Controller;
|
||||||
|
|
||||||
|
use OCA\Agency\Service\GroupService;
|
||||||
|
|
||||||
|
class GroupControllerController extends Controller {
|
||||||
|
|
||||||
|
private $service;
|
||||||
|
private $Id;
|
||||||
|
|
||||||
|
use Errors;
|
||||||
|
|
||||||
|
public function __construct(string $AppName, IRequest $request,
|
||||||
|
GroupService $service){
|
||||||
|
parent::__construct($AppName, $request);
|
||||||
|
$this->service = $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*/
|
||||||
|
public function index() {
|
||||||
|
return new DataResponse($this->service->findAll($this->Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
*/
|
||||||
|
public function show(int $id) {
|
||||||
|
return $this->handleNotFound(function () use ($id) {
|
||||||
|
return $this->service->find($id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
*/
|
||||||
|
public function destroy(int $id) {
|
||||||
|
return $this->handleNotFound(function () use ($id) {
|
||||||
|
return $this->service->delete($id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -21,5 +21,4 @@ class AgencyMapper extends QBMapper {
|
||||||
|
|
||||||
return $this->findEntity($qb);
|
return $this->findEntity($qb);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
namespace OCA\Agency\Db;
|
||||||
|
|
||||||
|
use JsonSerializable;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Db\Entity;
|
||||||
|
|
||||||
|
class AgencyUser extends Entity implements JsonSerializable {
|
||||||
|
|
||||||
|
protected $agency;
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->addType('id','integer');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize() {
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'agency' => $this->agency,
|
||||||
|
'user' => $this->user,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
namespace OCA\Agency\Db;
|
||||||
|
|
||||||
|
use OCP\IDBConnection;
|
||||||
|
use OCP\AppFramework\Db\QBMapper;
|
||||||
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
|
|
||||||
|
class AgencyUserMapper extends QBMapper {
|
||||||
|
|
||||||
|
public function __construct(IDBConnection $db) {
|
||||||
|
parent::__construct($db, 'agency_user', AgencyUser::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function find(int $id) {
|
||||||
|
$qb = $this->db->getQueryBuilder();
|
||||||
|
|
||||||
|
$qb->select('*')
|
||||||
|
->from($this->getTableName())
|
||||||
|
->where(
|
||||||
|
$qb->expr()->eq('id', $qb->createNamedParameter($id))
|
||||||
|
);
|
||||||
|
return $this->findEntity($qb);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAgencyIdByUserUid(string $useruid) {
|
||||||
|
$qb = $this->db->getQueryBuilder();
|
||||||
|
$qb->select('*')
|
||||||
|
->from($this->getTableName())
|
||||||
|
->where(
|
||||||
|
$qb->expr()->eq('user', $qb->createNamedParameter($useruid))
|
||||||
|
);
|
||||||
|
return $this->findEntity($qb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -77,9 +77,9 @@
|
||||||
'length' => 64
|
'length' => 64
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$table->addColumn('user', 'integer', [
|
$table->addColumn('user', 'string', [
|
||||||
'notnull' => true,
|
'notnull' => true,
|
||||||
'length' => 64
|
'length' => 200
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$table->setPrimaryKey(['id']);
|
$table->setPrimaryKey(['id']);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
namespace OCA\Agency\Service;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||||
|
|
||||||
|
use OCA\Agency\Db\AgencyUser;
|
||||||
|
use OCA\Agency\Db\AgencyUserMapper;
|
||||||
|
|
||||||
|
|
||||||
|
class AgencyUserService {
|
||||||
|
|
||||||
|
private $mapper;
|
||||||
|
|
||||||
|
public function __construct(AgencyUserMapper $mapper){
|
||||||
|
$this->mapper = $mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleException ($e) {
|
||||||
|
if ($e instanceof DoesNotExistException ||
|
||||||
|
$e instanceof MultipleObjectsReturnedException) {
|
||||||
|
throw new NotFoundException($e->getMessage());
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Find an Agency
|
||||||
|
public function find(int $id) {
|
||||||
|
try {
|
||||||
|
return $this->mapper->find($id);
|
||||||
|
} catch(Exception $e) {
|
||||||
|
$this->handleException($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Find an Agency
|
||||||
|
public function getAgencyIdByUserUid(string $useruid) {
|
||||||
|
return $this->mapper->getAgencyIdByUserUid($useruid);
|
||||||
|
//try {
|
||||||
|
// return $this->mapper->getAgencyIdByUserUid($useruid);
|
||||||
|
//} catch(Exception $e) {
|
||||||
|
// $this->handleException($e);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
namespace OCA\Agency\Service;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||||
|
|
||||||
|
use OCA\Agency\Db\Agency;
|
||||||
|
use OCA\Agency\Db\AgencyMapper;
|
||||||
|
|
||||||
|
|
||||||
|
class GroupService {
|
||||||
|
|
||||||
|
|
||||||
|
private function handleException ($e) {
|
||||||
|
if ($e instanceof DoesNotExistException ||
|
||||||
|
$e instanceof MultipleObjectsReturnedException) {
|
||||||
|
throw new NotFoundException($e->getMessage());
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Find an Agency
|
||||||
|
public function find(int $id) {
|
||||||
|
try {
|
||||||
|
return $this->mapper->find($id);
|
||||||
|
} catch(Exception $e) {
|
||||||
|
$this->handleException($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,9 @@
|
||||||
<AppNavigationItem to="/"
|
<AppNavigationItem to="/"
|
||||||
title="Agenturdaten"
|
title="Agenturdaten"
|
||||||
icon="icon-category-customization" />
|
icon="icon-category-customization" />
|
||||||
|
<AppNavigationItem to="/groupmanagement"
|
||||||
|
title="Gruppenverwaltung"
|
||||||
|
icon="icon-category-customization" />
|
||||||
</template>
|
</template>
|
||||||
</AppNavigation>
|
</AppNavigation>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import AgencyData from '../views/AgencyData'
|
import AgencyData from '../views/AgencyData'
|
||||||
|
import GroupManagement from '../views/GroupManagement'
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
|
|
@ -6,4 +7,9 @@ export default [
|
||||||
name: 'agencydata',
|
name: 'agencydata',
|
||||||
component: AgencyData,
|
component: AgencyData,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/groupmanagement',
|
||||||
|
name: 'groupmanagemenet',
|
||||||
|
component: GroupManagement,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<Content app-name="AgencyData">
|
<Content app-name="AgencyData">
|
||||||
<b-container class="bv-example-row">
|
<b-container v-if="isLoading" class="">
|
||||||
<h3>Agenturdaten</h3>
|
<h3>Agenturdaten</h3>
|
||||||
<FormulateForm
|
<FormulateForm
|
||||||
v-model="agency"
|
v-model="agency"
|
||||||
|
|
@ -42,7 +42,6 @@
|
||||||
<b-col>
|
<b-col>
|
||||||
<FormulateInput name="plz"
|
<FormulateInput name="plz"
|
||||||
label="PLZ"
|
label="PLZ"
|
||||||
validation="required|max:5|min:5"
|
|
||||||
type="text" />
|
type="text" />
|
||||||
</b-col>
|
</b-col>
|
||||||
<b-col>
|
<b-col>
|
||||||
|
|
@ -70,6 +69,9 @@
|
||||||
</b-row>
|
</b-row>
|
||||||
</FormulateForm>
|
</FormulateForm>
|
||||||
</b-container>
|
</b-container>
|
||||||
|
<b-container v-if="!isLoading" class="mx-auto">
|
||||||
|
<b-spinner type="grow" />
|
||||||
|
</b-container>
|
||||||
</Content>
|
</Content>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -86,6 +88,8 @@ export default ({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
agency: null,
|
agency: null,
|
||||||
|
agencyid: null,
|
||||||
|
isLoading: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|
@ -93,11 +97,14 @@ export default ({
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async fetchData() {
|
async fetchData() {
|
||||||
const agencydata = await axios.get(generateUrl('/apps/agency/agencys/4'))
|
const agencyidresp = await axios.get(generateUrl('/apps/agency/getagencyidbyuser'))
|
||||||
|
this.agencyid = agencyidresp.data.agency
|
||||||
|
const agencydata = await axios.get(generateUrl('/apps/agency/agencys/' + this.agencyid))
|
||||||
this.agency = agencydata.data
|
this.agency = agencydata.data
|
||||||
|
this.isLoading = true
|
||||||
},
|
},
|
||||||
async submitHandler(data) {
|
async submitHandler(data) {
|
||||||
const response = await axios.put(generateUrl('/apps/agency/agencys/4'), data)
|
const response = await axios.put(generateUrl('/apps/agency/agencys/' + this.agencyid), data)
|
||||||
console.log(response)
|
console.log(response)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
<template>
|
||||||
|
<Content app-name="GroupManagement">
|
||||||
|
<b-container class="bv-example-row">
|
||||||
|
<h3>Gruppenverwaltung</h3>
|
||||||
|
</b-container>
|
||||||
|
</Content>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import Content from '@nextcloud/vue/dist/Components/Content'
|
||||||
|
import '@braid/vue-formulate/themes/snow/snow.scss'
|
||||||
|
// import { generateUrl } from '@nextcloud/router'
|
||||||
|
// const axios = require('axios').default
|
||||||
|
|
||||||
|
export default ({
|
||||||
|
name: 'GroupManagement',
|
||||||
|
components: {
|
||||||
|
Content,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.loadUserData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async loadUserData() {
|
||||||
|
// const userdata = await axios.get(generateUrl('/apps/agency/getagencyidbyuser'))
|
||||||
|
// console.log(userdata)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue