Agenturdaten fertig

This commit is contained in:
holger.trampe 2021-05-23 18:05:42 +02:00
parent e78a8abd1e
commit b2e61c67fb
6 changed files with 130 additions and 20 deletions

View File

@ -31,6 +31,7 @@ class AgencyController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param int $id
*/
@ -47,19 +48,20 @@ class AgencyController extends Controller {
* @param string $title
* @param string $content
*/
public function create(string $name) {
return $this->service->create($name);
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) {
return $this->handleNotFound(function () use ($id, $name) {
return $this->service->update($id, $name);
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);
});
}

View File

@ -8,6 +8,12 @@ use OCP\AppFramework\Db\Entity;
class Agency extends Entity implements JsonSerializable {
protected $name;
protected $inhaber;
protected $street;
protected $plz;
protected $city;
protected $agencymail;
protected $phone;
public function __construct() {
$this->addType('id','integer');
@ -16,7 +22,13 @@ class Agency extends Entity implements JsonSerializable {
public function jsonSerialize() {
return [
'id' => $this->id,
'name' => $this->title,
'name' => $this->name,
'inhaber' => $this->inhaber,
'street' => $this->street,
'plz' => $this->plz,
'city' => $this->city,
'agencymail' => $this->agencymail,
'phone' => $this->phone,
];
}
}

View File

@ -7,7 +7,7 @@ use OCP\AppFramework\Db\QBMapper;
class AgencyMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'agencys', Note::class);
parent::__construct($db, 'agencys', Agency::class);
}
public function find(int $id) {

View File

@ -21,6 +21,7 @@
if (!$schema->hasTable('agencys')) {
$table = $schema->createTable('agencys');
$table->addColumn('id', 'integer', [
'autoincrement' => true,
'notnull' => true,
@ -50,7 +51,7 @@
'length' => 5
]);
$table->addColumn('agency_email', 'string', [
$table->addColumn('agencymail', 'string', [
'notnull' => false,
'length' => 200
]);
@ -71,12 +72,12 @@
'notnull' => true,
]);
$table->rColumn('agency', 'integer', [
$table->addColumn('agency', 'integer', [
'notnull' => true,
'length' => 64
]);
$table->rColumn('user', 'integer', [
$table->addColumn('user', 'integer', [
'notnull' => true,
'length' => 64
]);

View File

@ -27,6 +27,7 @@ class AgencyService {
}
}
//Find an Agency
public function find(int $id) {
try {
return $this->mapper->find($id);
@ -35,10 +36,33 @@ class AgencyService {
}
}
public function create(string $name) {
//Create an Agency
public function create(string $name, string $inhaber, string $street, string $plz, string $city, string $agencymail, string $phone) {
$agency = new Agency();
$agency->setName($name);
$agency->setInhaber($inhaber);
$agency->setStreet($street);
$agency->setPlz($plz);
$agency->setCity($city);
$agency->setAgencymail($agencymail);
$agency->setPhone($phone);
return $this->mapper->insert($agency);
}
//Update an Agency
public function update(int $id, string $name, string $inhaber, string $street, string $plz, string $city, string $agencymail, string $phone) {
try {
$agency = $this->mapper->find($id);
} catch(Exception $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$agency->setName($name);
$agency->setInhaber($inhaber);
$agency->setStreet($street);
$agency->setPlz($plz);
$agency->setCity($city);
$agency->setAgencymail($agencymail);
$agency->setPhone($phone);
return $this->mapper->update($agency);
}
}

View File

@ -1,18 +1,81 @@
<template>
<Content app-name="AgencyData">
<b-container class="bv-example-row">
<h3>Agenturdaten</h3>
<FormulateForm
v-model="agency"
@submit="submitHandler">
<b-row cols="1"
cols-sm="1"
cols-md="2"
cols-lg="4">
<b-col>
<FormulateInput name="name"
label="Agenturname"
type="text" />
</b-col>
<b-col>
<FormulateInput name="inhaber"
label="Agenturinhaber"
type="text" />
</b-col>
</b-row>
<b-row cols="1"
cols-sm="1"
cols-md="2"
cols-lg="4">
<b-col>
<FormulateInput name="street"
label="Straße"
type="text" />
</b-col>
<b-col>
<FormulateInput name="city"
label="Stadt"
type="text" />
</b-col>
</b-row>
<b-row cols="1"
cols-sm="1"
cols-md="2"
cols-lg="4">
<b-col>
<FormulateInput name="plz"
label="PLZ"
validation="required|max:5|min:5"
type="text" />
</b-col>
<b-col>
<FormulateInput name="agencymail"
label="Agentur-Email-Adresse"
type="text" />
</b-col>
</b-row>
<b-row cols="1"
cols-sm="1"
cols-md="2"
cols-lg="4">
<b-col>
<FormulateInput name="phone"
label="Telefonnummer"
type="text" />
</b-col>
</b-row>
<b-row class="mt-2">
<b-col>
<FormulateInput
type="submit"
label="Aktualisieren" />
</b-col>
</b-row>
</FormulateForm>
</b-container>
</Content>
</template>
<script>
import Content from '@nextcloud/vue/dist/Components/Content'
import { generateUrl } from '@nextcloud/router'
import '@braid/vue-formulate/themes/snow/snow.scss'
const axios = require('axios').default
export default ({
@ -22,11 +85,19 @@ export default ({
},
data() {
return {
agency: null,
}
},
created() {
this.fetchData()
},
methods: {
async fetchData() {
const agencydata = await axios.get(generateUrl('/apps/agency/agencys/4'))
this.agency = agencydata.data
},
async submitHandler(data) {
const response = await axios.post(generateUrl('/apps/agency/agencys'), data)
const response = await axios.put(generateUrl('/apps/agency/agencys/4'), data)
console.log(response)
},
},