feat: Enhance API interactions and user entity configuration
This commit is contained in:
parent
fcfda9d9be
commit
465515191f
@ -229,11 +229,31 @@ const errors = ref({});
|
||||
const fetchUsers = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await fetch('/api/users');
|
||||
const response = await fetch('/api/users', {
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Accept': 'application/ld+json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error('API Error:', response.status, errorText);
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
users.value = data['hydra:member'] || data;
|
||||
|
||||
// API Platform JSON-LD uses 'member' (hydra:member becomes 'member' in JS)
|
||||
users.value = data.member || data['hydra:member'] || [];
|
||||
} catch (error) {
|
||||
toast.add({ severity: 'error', summary: 'Fehler', detail: 'Benutzer konnten nicht geladen werden', life: 3000 });
|
||||
console.error('Error fetching users:', error);
|
||||
toast.add({
|
||||
severity: 'error',
|
||||
summary: 'Fehler',
|
||||
detail: 'Benutzer konnten nicht geladen werden: ' + error.message,
|
||||
life: 5000
|
||||
});
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
@ -297,7 +317,11 @@ const saveUser = async () => {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/ld+json',
|
||||
'Accept': 'application/ld+json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
@ -328,7 +352,8 @@ const deleteUser = async () => {
|
||||
deleting.value = true;
|
||||
try {
|
||||
const response = await fetch(`/api/users/${userToDelete.value.id}`, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
credentials: 'same-origin'
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Fehler beim Löschen');
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
api_platform:
|
||||
title: Hello API Platform
|
||||
title: myCRM API
|
||||
version: 1.0.0
|
||||
defaults:
|
||||
stateless: true
|
||||
stateless: false
|
||||
cache_headers:
|
||||
vary: ['Content-Type', 'Authorization', 'Origin']
|
||||
formats:
|
||||
jsonld: ['application/ld+json']
|
||||
json: ['application/json']
|
||||
html: ['text/html']
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
framework:
|
||||
asset_mapper:
|
||||
enabled: false
|
||||
# The paths to make available to the asset mapper.
|
||||
paths:
|
||||
- assets/
|
||||
@ -8,4 +9,5 @@ framework:
|
||||
when@prod:
|
||||
framework:
|
||||
asset_mapper:
|
||||
enabled: false
|
||||
missing_import_mode: warn
|
||||
|
||||
@ -8,7 +8,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
#[Route('/{reactRouting}', name: 'app_home', requirements: ['reactRouting' => '(?!login|logout|api).*'], defaults: ['reactRouting' => null], priority: -1)]
|
||||
#[Route('/{reactRouting}', name: 'app_home', requirements: ['reactRouting' => '(?!login|logout|api|bundles).*'], defaults: ['reactRouting' => null], priority: -1)]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('base.html.twig');
|
||||
|
||||
@ -21,11 +21,11 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new GetCollection(),
|
||||
new Get(),
|
||||
new Post(security: "is_granted('ROLE_ADMIN')"),
|
||||
new Put(security: "is_granted('ROLE_ADMIN') or object == user"),
|
||||
new Delete(security: "is_granted('ROLE_ADMIN')")
|
||||
new GetCollection(stateless: false),
|
||||
new Get(stateless: false),
|
||||
new Post(security: "is_granted('ROLE_ADMIN')", stateless: false),
|
||||
new Put(security: "is_granted('ROLE_ADMIN') or object == user", stateless: false),
|
||||
new Delete(security: "is_granted('ROLE_ADMIN')", stateless: false)
|
||||
],
|
||||
normalizationContext: ['groups' => ['user:read']],
|
||||
denormalizationContext: ['groups' => ['user:write']]
|
||||
@ -204,10 +204,17 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
return trim($this->firstName . ' ' . $this->lastName);
|
||||
}
|
||||
|
||||
#[Groups(['user:read', 'user:write'])]
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->isActive;
|
||||
}
|
||||
|
||||
// Alias for Symfony Serializer (which expects get* prefix)
|
||||
public function getIsActive(): bool
|
||||
{
|
||||
return $this->isActive;
|
||||
}
|
||||
|
||||
public function setIsActive(bool $isActive): static
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user