97 lines
2.7 KiB
PHP
97 lines
2.7 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\Agency\AgencyManager;
|
|
use OCP\IDBConnection;
|
|
|
|
class AgencyController extends Controller {
|
|
|
|
protected $userManager;
|
|
private $service;
|
|
private $Id;
|
|
protected $userSession;
|
|
protected $request;
|
|
protected $agencyManager;
|
|
|
|
use Errors;
|
|
|
|
public function __construct(string $AppName, IRequest $request, IUserSession $userSession, AgencyService $service, IDBConnection $connection, AgencyManager $agencymanager){
|
|
parent::__construct($AppName, $request);
|
|
$this->service = $service;
|
|
$this->userSession = $userSession;
|
|
$this->request = $request;
|
|
$this->agencyManager = $agencymanager;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*/
|
|
public function index() {
|
|
return new DataResponse($this->service->findAll($this->Id));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
*/
|
|
public function show() {
|
|
return $this->agencyManager->getAgencyByUser($this->userSession);
|
|
#return $this->handleNotFound(function () use ($id) {
|
|
# return $this->service->find($id);
|
|
#});
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param string $name
|
|
* @param string $inhaber
|
|
* @param string $street
|
|
* @param string $plz
|
|
* @param string $city
|
|
* @param string $agencymail
|
|
* @param string $phone
|
|
* @param string $agencygid
|
|
* @param string $agencydirid
|
|
* @param string $standarddirid
|
|
*
|
|
*/
|
|
public function create(string $agencygid, string $agencydirid, string $standarddirid) {
|
|
return $this->service->create($name, $inhaber, $street, $plz, $city, $agencymail, $phone, $agencygid, $agencydirid, $standarddirid);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
*/
|
|
public function updateagencydata(string $name = null, string $inhaber = null, string $street = null, string $plz = null, string $city = null, string $agencymail = null, string $phone = null) {
|
|
|
|
$id = $this->agencyManager->getAgencyByUser($this->userSession)->getId();
|
|
|
|
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);
|
|
});
|
|
}
|
|
|
|
} |