97 lines
2.6 KiB
PHP
97 lines
2.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\Agency\Controller;
|
|
|
|
use OCP\IRequest;
|
|
use OCP\IUserSession;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCA\Agency\Service\AgencyService;
|
|
use OCA\Agency\Service\AgencyUserService;
|
|
|
|
class AgencyController extends Controller {
|
|
|
|
protected $userManager;
|
|
private $service;
|
|
private $agencyuserservice;
|
|
private $Id;
|
|
protected $userSession;
|
|
protected $request;
|
|
|
|
use Errors;
|
|
|
|
public function __construct(string $AppName, IRequest $request, IUserSession $userSession, AgencyService $service, AgencyUserService $agencyuserservice){
|
|
parent::__construct($AppName, $request);
|
|
$this->service = $service;
|
|
$this->agencyuserservice = $agencyuserservice;
|
|
$this->userSession = $userSession;
|
|
$this->request = $request;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*/
|
|
public function index() {
|
|
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
|
|
* @NoCSRFRequired
|
|
*
|
|
* @param int $id
|
|
*/
|
|
public function show(int $id) {
|
|
return $this->handleNotFound(function () use ($id) {
|
|
return $this->service->find($id);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param string $title
|
|
* @param string $content
|
|
*/
|
|
public function create(string $name, string $inhaber, string $street, string $plz, string $city, string $agencymail, string $phone) {
|
|
return $this->service->create($name, $inhaber, $street, $plz, $city, $agencymail, $phone);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*
|
|
* @param int $id
|
|
* @param string $title
|
|
*/
|
|
public function update(int $id, string $name, string $inhaber, string $street, string $plz, string $city, string $agencymail, string $phone) {
|
|
return $this->handleNotFound(function () use ($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone) {
|
|
return $this->service->update($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param int $id
|
|
*/
|
|
public function destroy(int $id) {
|
|
return $this->handleNotFound(function () use ($id) {
|
|
return $this->service->delete($id);
|
|
});
|
|
}
|
|
|
|
} |