Compare commits

..

9 Commits

Author SHA1 Message Date
gitea-actions 386242c84d chore: bump version to v0.4.38
Auto Tag Develop / tag (push) Successful in 8s
Build & Push Docker Image / build (push) Successful in 3m5s
2026-06-24 19:12:19 +00:00
matthieu 41a98f93ee Merge pull request 'feat(mcp) : outils MCP Directory (prestataires, contacts, adresses, rapports)' (#24) from feat/mcp-directory-prestataire-contact-address-report into develop
Auto Tag Develop / tag (push) Successful in 11s
Reviewed-on: #24
2026-06-24 19:12:07 +00:00
matthieu aad949c10c test(directory) : tests fonctionnels MCP pour Prestataire/Contact/Address/CommercialReport
Pull Request — Quality gate / Frontend (build) (pull_request) Successful in 40s
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m20s
Couvre les 20 nouveaux outils MCP Directory (5 par entite : create/get/list/
update/delete) avec un focus sur les guards et invariants :
- exactly-one-parent (Contact/Address/CommercialReport)
- ROLE_ADMIN
- ISO 3166 alpha-2 + normalisation uppercase (Address)
- enum ReportType + defaults note/today + parsing date (CommercialReport)
- author auto-rempli par CommercialReportAuthorListener (token storage)
- collections vides dans get-prestataire enrichi
- ordre DESC sur occurredAt pour list-commercial-reports
- delete renvoie null apres em.clear()

38 tests / 105 assertions. Suite complete passe a 217/217.
2026-06-24 21:08:06 +02:00
matthieu ad029f5c7d chore(directory) : ferme contrats Repository (findBy) + bindings DI MCP Directory
Pull Request — Quality gate / Frontend (build) (pull_request) Successful in 1m15s
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m34s
Plumbing complementaire des outils MCP ajoutes en 99626b8 :
- declare findBy() sur Address/Contact/CommercialReport RepositoryInterface
  (Prestataire l'avait deja) pour exposer la methode au contrat DDD
- bindings explicites des 4 repos dans services.yaml (cohrence avec
  Client/Prospect, meme si Symfony auto-alias l'interface vers l'unique
  implementation)
2026-06-24 20:53:17 +02:00
matthieu 99626b89da feat(mcp) : outils MCP Directory pour prestataires, contacts, adresses et rapports
Pull Request — Quality gate / Frontend (build) (pull_request) Successful in 41s
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 59s
Ajoute 20 nouveaux outils MCP pour permettre à Claude (ou tout client MCP) de
remplir un dossier client / prospect / prestataire complet — onglets
Information, Contact, Adresse et Rapport — sans passer par l'UI.

Entités couvertes (CRUD complet, 5 outils chacune) :
- Prestataire : create / update / get / list / delete
- Contact : create / update / get / list / delete
- Address : create / update / get / list / delete
- CommercialReport : create / update / get / list / delete

Détails :
- Contact / Address / CommercialReport doivent être rattachés à exactement
  un parent parmi clientId, prospectId, prestataireId (validation côté tool).
- get-client, get-prospect et get-prestataire renvoient désormais un payload
  enrichi avec la liste de leurs contacts, adresses et rapports liés : un
  seul appel pour reconstruire l'onglet entier.
- Pour CommercialReport, le type (note / call / meeting / email) et la date
  occurredAt sont validés ; l'auteur est rempli automatiquement par le
  listener existant.
- Sécurité : ROLE_ADMIN aligné sur les autres outils MCP de Directory (pas
  de migration vers les permissions RBAC fines pour rester cohérent).

Plumbing :
- Repositories Contact / Address / CommercialReport : ajout de findBy() sur
  les interfaces (l'implémentation Doctrine l'a déjà via ServiceEntityRepository).
- Bindings interface -> implémentation Doctrine ajoutés dans services.yaml
  pour Prestataire / Contact / Address / CommercialReport.
- Sérialiseur partagé étendu : prestataire / contact / address /
  commercialReport / reportDocument.

Vérification : 86 outils MCP exposés au total (66 avant + 20 ajoutés), test
end-to-end via le transport HTTP (create-prestataire + create-contact +
create-address + create-commercial-report + get-prestataire renvoyant le
dossier complet). Suite PHPUnit verte.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-24 20:36:46 +02:00
gitea-actions 94e6abcbaa chore: bump version to v0.4.37
Auto Tag Develop / tag (push) Successful in 17s
Build & Push Docker Image / build (push) Successful in 40s
2026-06-24 16:07:56 +00:00
matthieu 04be081ffd Merge pull request 'feat(directory) : type prestataire, validateurs front, autocomplete adresse BAN' (#23) from feat/directory-prestataire into develop
Auto Tag Develop / tag (push) Successful in 14s
Reviewed-on: #23
2026-06-24 16:07:40 +00:00
Matthieu 435c7fcfc2 fix(directory) : ville absente du select corrigée (option courante conservée) + matching suggestion BAN par libellé
Pull Request — Quality gate / Frontend (build) (pull_request) Successful in 38s
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m23s
2026-06-24 18:05:16 +02:00
Matthieu 5764d8f472 feat(directory) : type prestataire, validateurs front, autocomplete adresse BAN
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m20s
Pull Request — Quality gate / Frontend (build) (pull_request) Successful in 1m26s
- Prestataire : entité/repo + ressource API Platform (RBAC directory.providers.*),
  ownership prestataire sur contacts/adresses/comptes-rendus (CHECK XOR à 3),
  DTO/service/drawer/fiche détail + onglet dédié dans le répertoire.
- Prospect : société uniquement (suppression du champ name, company requis) ;
  migration de backfill, conversion prospect→client et MCP adaptés.
- Champ site web sur client/prospect/prestataire (entités, DTO, onglet Information, MCP).
- Validateurs front email / téléphone FR (0549200910) / URL sur Information et Contacts,
  enregistrement bloqué tant qu'un champ est invalide.
- Autocomplete adresse branché sur la Base Adresse Nationale (api-adresse.data.gouv.fr)
  avec mode dégradé en saisie libre.
- Administration : retrait de l'onglet Clients.
2026-06-24 17:55:09 +02:00
79 changed files with 3469 additions and 135 deletions
+8
View File
@@ -113,6 +113,14 @@ services:
App\Module\Directory\Domain\Repository\ProspectRepositoryInterface: '@App\Module\Directory\Infrastructure\Doctrine\DoctrineProspectRepository'
App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface: '@App\Module\Directory\Infrastructure\Doctrine\DoctrinePrestataireRepository'
App\Module\Directory\Domain\Repository\ContactRepositoryInterface: '@App\Module\Directory\Infrastructure\Doctrine\DoctrineContactRepository'
App\Module\Directory\Domain\Repository\AddressRepositoryInterface: '@App\Module\Directory\Infrastructure\Doctrine\DoctrineAddressRepository'
App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface: '@App\Module\Directory\Infrastructure\Doctrine\DoctrineCommercialReportRepository'
App\Module\Directory\Infrastructure\EventListener\CommercialReportAuthorListener:
tags:
- { name: doctrine.orm.entity_listener, entity: 'App\Module\Directory\Domain\Entity\CommercialReport', event: prePersist }
+1 -1
View File
@@ -1,2 +1,2 @@
parameters:
app.version: '0.4.36'
app.version: '0.4.38'
+31 -3
View File
@@ -917,6 +917,7 @@
"company": "Société",
"email": "Email",
"phone": "Téléphone",
"website": "Site web",
"street": "Rue",
"city": "Ville",
"postalCode": "Code postal",
@@ -932,7 +933,23 @@
"lost": "Perdu"
},
"validation": {
"nameRequired": "Le nom est requis"
"nameRequired": "Le nom est requis",
"companyRequired": "La société est requise"
}
},
"prestataires": {
"created": "Prestataire créé avec succès.",
"updated": "Prestataire mis à jour avec succès.",
"deleted": "Prestataire supprimé avec succès.",
"addPrestataire": "Ajouter un prestataire",
"editPrestataire": "Modifier un prestataire",
"deleteConfirmTitle": "Supprimer le prestataire",
"deleteConfirmMessage": "Êtes-vous sûr de vouloir supprimer le prestataire « {name} » ? Cette action est irréversible.",
"fields": {
"name": "Nom / Société",
"email": "Email",
"phone": "Téléphone",
"website": "Site web"
}
},
"directory": {
@@ -941,6 +958,7 @@
"info": "Informations",
"clients": "Clients",
"prospects": "Prospects",
"prestataires": "Prestataires",
"contact": "Contact",
"address": "Adresse",
"report": "Rapport"
@@ -949,12 +967,16 @@
"fields": {
"name": "Nom",
"email": "Email",
"phone": "Téléphone"
"phone": "Téléphone",
"website": "Site web"
}
},
"validation": {
"nameRequired": "Le nom est requis.",
"subjectRequired": "L'objet est requis."
"subjectRequired": "L'objet est requis.",
"emailInvalid": "Adresse email invalide.",
"phoneInvalid": "Numéro de téléphone invalide (ex. 0549200910).",
"urlInvalid": "URL invalide (ex. https://exemple.fr)."
},
"clients": {
"add": "Ajouter un client",
@@ -965,6 +987,10 @@
"empty": "Aucun prospect trouvé.",
"allStatuses": "Tous les statuts"
},
"prestataires": {
"add": "Ajouter un prestataire",
"empty": "Aucun prestataire trouvé."
},
"contacts": {
"add": "Ajouter un contact",
"item": "Contact {n}",
@@ -984,6 +1010,8 @@
"item": "Adresse {n}",
"saved": "Adresse enregistrée.",
"deleted": "Adresse supprimée.",
"streetNotFound": "Aucune adresse trouvée — saisie libre possible.",
"autocompleteUnavailable": "Recherche d'adresse indisponible : saisissez l'adresse manuellement.",
"fields": {
"label": "Libellé",
"street": "Rue",
@@ -54,7 +54,7 @@ import { useCommercialReportService } from '~/modules/directory/services/commerc
const props = defineProps<{
modelValue: boolean
report: CommercialReport | null
owner: { client?: string, prospect?: string }
owner: { client?: string, prospect?: string, prestataire?: string }
}>()
const emit = defineEmits<{
@@ -141,7 +141,7 @@ import { useCommercialReportService } from '~/modules/directory/services/commerc
import { useReportDocumentService } from '~/modules/directory/services/report-documents'
const props = defineProps<{
owner: { client?: string, prospect?: string }
owner: { client?: string, prospect?: string, prestataire?: string }
canManage: boolean
}>()
@@ -19,13 +19,33 @@
:readonly="readonly"
@update:model-value="update('label', $event)"
/>
<MalioInputText
class="col-span-2"
:label="$t('directory.addresses.fields.street')"
:model-value="modelValue.street ?? ''"
:readonly="readonly"
@update:model-value="update('street', $event)"
/>
<!-- Rue : saisie assistée (BAN) en édition, champ texte en lecture seule.
allow-create conserve le texte saisi si la BAN ne propose rien
(erreur/timeout). Choisir une suggestion remplit rue + CP + ville. -->
<div class="col-span-2">
<MalioInputAutocomplete
v-if="!readonly"
:model-value="modelValue.street ?? ''"
:options="addressOptions"
:loading="addressLoading"
:min-search-length="3"
:allow-create="true"
:label="$t('directory.addresses.fields.street')"
:no-results-text="$t('directory.addresses.streetNotFound')"
@update:model-value="(v) => update('street', v === null ? '' : String(v))"
@search="onAddressSearch"
@select="onAddressSelect"
/>
<MalioInputText
v-else
:label="$t('directory.addresses.fields.street')"
:model-value="modelValue.street ?? ''"
:readonly="readonly"
@update:model-value="update('street', $event)"
/>
</div>
<MalioInputText
class="col-span-2"
:label="$t('directory.addresses.fields.streetComplement')"
@@ -33,13 +53,27 @@
:readonly="readonly"
@update:model-value="update('streetComplement', $event)"
/>
<MalioInputText
:label="$t('directory.addresses.fields.postalCode')"
:model-value="modelValue.postalCode ?? ''"
:readonly="readonly"
@update:model-value="update('postalCode', $event)"
@update:model-value="onPostalCodeInput"
/>
<!-- Ville : select alimenté par le code postal (BAN). En mode dégradé
(BAN indispo) ou lecture seule, on bascule en saisie libre. -->
<MalioSelect
v-if="!readonly && !degraded"
:model-value="modelValue.city ?? ''"
:options="cityOptions"
:label="$t('directory.addresses.fields.city')"
empty-option-label=""
group-class="w-full"
@update:model-value="(v) => update('city', v === null ? '' : String(v))"
/>
<MalioInputText
v-else
:label="$t('directory.addresses.fields.city')"
:model-value="modelValue.city ?? ''"
:readonly="readonly"
@@ -50,6 +84,10 @@
<script setup lang="ts">
import type { Address } from '~/modules/directory/services/dto/address'
import {
useAddressAutocomplete,
type AddressSuggestion,
} from '~/modules/directory/composables/useAddressAutocomplete'
const props = defineProps<{
modelValue: Address
@@ -63,7 +101,98 @@ const emit = defineEmits<{
'remove': []
}>()
const { t } = useI18n()
const toast = useToast()
const autocomplete = useAddressAutocomplete()
type Option = { label: string, value: string | number }
const addressOptions = ref<Option[]>([])
// Villes renvoyées par la BAN pour le code postal courant.
const fetchedCityOptions = ref<Option[]>([])
const addressLoading = ref(false)
// Le select Ville n'affiche que les valeurs présentes dans ses options : on
// garantit donc que la ville déjà enregistrée (chargement d'une fiche) ou
// pré-remplie par l'autocomplétion d'adresse figure toujours dans la liste,
// même avant toute recherche par code postal — sinon elle s'afficherait vide.
const cityOptions = computed<Option[]>(() => {
const current = (props.modelValue.city ?? '').trim()
const options = [...fetchedCityOptions.value]
if (current && !options.some(o => o.value === current)) {
options.unshift({ value: current, label: current })
}
return options
})
// Mode dégradé : BAN indisponible → la ville passe en saisie libre.
const degraded = ref(false)
let lastAddressSuggestions: AddressSuggestion[] = []
let notified = false
function update(field: keyof Address, value: string): void {
emit('update:modelValue', { ...props.modelValue, [field]: value === '' ? null : value })
}
// Avertit une seule fois que l'autocomplétion est indisponible (saisie libre).
function notifyUnavailable(): void {
if (notified) return
notified = true
toast.info({ title: '', message: t('directory.addresses.autocompleteUnavailable') })
}
/** Recherche d'adresse assistée (event de MalioInputAutocomplete). */
async function onAddressSearch(query: string): Promise<void> {
if (query.trim().length < 3) {
addressOptions.value = []
return
}
addressLoading.value = true
try {
const postalCode = (props.modelValue.postalCode ?? '').replace(/\D/g, '') || undefined
const suggestions = await autocomplete.searchAddress(query, postalCode)
lastAddressSuggestions = suggestions
addressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
}
catch {
addressOptions.value = []
notifyUnavailable()
}
finally {
addressLoading.value = false
}
}
/** Sélection d'une suggestion → remplit rue + ville + code postal. */
function onAddressSelect(option: Option | null): void {
if (option === null) return
// Matching par `label` (adresse complète, unique côté BAN) plutôt que par
// rue : deux communes peuvent partager le même libellé de voie.
const suggestion = lastAddressSuggestions.find(s => s.label === option.label)
if (!suggestion) {
update('street', String(option.value))
return
}
emit('update:modelValue', {
...props.modelValue,
street: suggestion.street,
city: suggestion.city || props.modelValue.city,
postalCode: suggestion.postalCode || props.modelValue.postalCode,
})
}
/** Saisie du code postal → met à jour le champ + interroge la BAN pour la ville. */
async function onPostalCodeInput(value: string): Promise<void> {
update('postalCode', value)
const digits = (value ?? '').replace(/\D/g, '')
if (digits.length < 5) return
try {
const suggestions = await autocomplete.searchCity(digits)
fetchedCityOptions.value = suggestions.map(s => ({ value: s.city, label: s.city }))
degraded.value = false
}
catch {
degraded.value = true
notifyUnavailable()
}
}
</script>
@@ -35,18 +35,21 @@
:label="$t('directory.contacts.fields.email')"
:model-value="modelValue.email ?? ''"
:readonly="readonly"
:error="emailError"
@update:model-value="update('email', $event)"
/>
<MalioInputText
:label="$t('directory.contacts.fields.phonePrimary')"
:model-value="modelValue.phonePrimary ?? ''"
:readonly="readonly"
:error="phonePrimaryError"
@update:model-value="update('phonePrimary', $event)"
/>
<MalioInputText
:label="$t('directory.contacts.fields.phoneSecondary')"
:model-value="modelValue.phoneSecondary ?? ''"
:readonly="readonly"
:error="phoneSecondaryError"
@update:model-value="update('phoneSecondary', $event)"
/>
</div>
@@ -54,6 +57,7 @@
<script setup lang="ts">
import type { Contact } from '~/modules/directory/services/dto/contact'
import { isValidEmail, isValidFrPhone } from '~/modules/directory/utils/validation'
const props = defineProps<{
modelValue: Contact
@@ -67,6 +71,18 @@ const emit = defineEmits<{
'remove': []
}>()
const { t } = useI18n()
const emailError = computed(() =>
isValidEmail(props.modelValue.email) ? '' : t('directory.validation.emailInvalid'),
)
const phonePrimaryError = computed(() =>
isValidFrPhone(props.modelValue.phonePrimary) ? '' : t('directory.validation.phoneInvalid'),
)
const phoneSecondaryError = computed(() =>
isValidFrPhone(props.modelValue.phoneSecondary) ? '' : t('directory.validation.phoneInvalid'),
)
function update(field: keyof Contact, value: string): void {
emit('update:modelValue', { ...props.modelValue, [field]: value === '' ? null : value })
}
@@ -0,0 +1,88 @@
<template>
<MalioDrawer v-model="isOpen">
<template #header>
<h2 class="text-xl font-bold">{{ isEditing ? $t('prestataires.editPrestataire') : $t('prestataires.addPrestataire') }}</h2>
</template>
<form @submit.prevent="handleSubmit" class="flex flex-col gap-2">
<MalioInputText
v-model="form.name"
:label="$t('prestataires.fields.name')"
input-class="w-full"
:error="touched.name && !form.name.trim() ? $t('directory.validation.nameRequired') : ''"
@blur="touched.name = true"
/>
<div class="mt-6 flex justify-end">
<MalioButton
:label="$t('common.save')"
button-class="w-auto px-6"
:disabled="isSubmitting"
@click="handleSubmit"
/>
</div>
</form>
</MalioDrawer>
</template>
<script setup lang="ts">
import type { Prestataire, PrestataireWrite } from '~/modules/directory/services/dto/prestataire'
import { usePrestataireService } from '~/modules/directory/services/prestataires'
const props = defineProps<{
modelValue: boolean
prestataire: Prestataire | null
}>()
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void
(e: 'saved'): void
}>()
const isOpen = computed({
get: () => props.modelValue,
set: (v) => emit('update:modelValue', v),
})
const isEditing = computed(() => !!props.prestataire)
const isSubmitting = ref(false)
const form = reactive({
name: '',
})
const touched = reactive({
name: false,
})
watch(() => props.modelValue, (open) => {
if (open) {
form.name = props.prestataire?.name ?? ''
touched.name = false
}
})
const { create, update } = usePrestataireService()
async function handleSubmit() {
touched.name = true
if (!form.name.trim()) return
isSubmitting.value = true
try {
const payload: PrestataireWrite = {
name: form.name.trim(),
}
if (isEditing.value && props.prestataire) {
await update(props.prestataire.id, payload)
} else {
await create(payload)
}
emit('saved')
isOpen.value = false
} finally {
isSubmitting.value = false
}
}
</script>
@@ -5,11 +5,11 @@
</template>
<form @submit.prevent="handleSubmit" class="flex flex-col gap-2">
<MalioInputText
v-model="form.name"
label="Nom société"
v-model="form.company"
:label="$t('prospects.fields.company')"
input-class="w-full"
:error="touched.name && !form.name.trim() ? $t('prospects.validation.nameRequired') : ''"
@blur="touched.name = true"
:error="touched.company && !form.company.trim() ? $t('prospects.validation.companyRequired') : ''"
@blur="touched.company = true"
/>
<div class="mt-6 flex items-center justify-between gap-2">
@@ -62,30 +62,30 @@ const isConverted = computed(() => !!props.prospect?.convertedClient)
const isSubmitting = ref(false)
const form = reactive({
name: '',
company: '',
})
const touched = reactive({
name: false,
company: false,
})
watch(() => props.modelValue, (open) => {
if (open) {
form.name = props.prospect?.name ?? ''
touched.name = false
form.company = props.prospect?.company ?? ''
touched.company = false
}
})
const { create, update, convert } = useProspectService()
async function handleSubmit() {
touched.name = true
if (!form.name.trim()) return
touched.company = true
if (!form.company.trim()) return
isSubmitting.value = true
try {
const payload: ProspectWrite = {
name: form.name.trim(),
company: form.company.trim(),
}
if (isEditing.value && props.prospect) {
@@ -0,0 +1,113 @@
import { httpExternal } from '~/utils/httpExternal'
// Autocomplétion d'adresse branchée sur la Base Adresse Nationale (BAN),
// `api-adresse.data.gouv.fr` — service public français, gratuit, CORS ouvert.
//
// Appel HTTP DIRECT depuis le front (pas de proxy back) : la BAN est un domaine
// externe, sans cookie de session ni enveloppe Hydra → on passe par
// `httpExternal` et NON `useApi()`.
//
// Contrat :
// searchCity(postalCode) -> liste { city, postalCode }
// searchAddress(query, cp?) -> liste { label, street, postalCode, city }
// En cas d'erreur/timeout, la méthode THROW une
// AddressAutocompleteUnavailableError. Le composant consommateur catch,
// avertit l'utilisateur et bascule en saisie libre.
/** URL de l'endpoint de recherche BAN. */
const BAN_SEARCH_URL = 'https://api-adresse.data.gouv.fr/search/'
/** Une suggestion de ville renvoyée à partir d'un code postal. */
export interface CitySuggestion {
city: string
postalCode: string
}
/** Une suggestion d'adresse complète (saisie assistée du champ « Rue »). */
export interface AddressSuggestion {
label: string
street: string
postalCode: string
city: string
}
export interface AddressAutocomplete {
searchCity(postalCode: string): Promise<CitySuggestion[]>
searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]>
}
/** Erreur signalant que le service d'autocomplétion BAN n'est pas disponible. */
export class AddressAutocompleteUnavailableError extends Error {
constructor() {
super('Address autocomplete (BAN) is not available.')
this.name = 'AddressAutocompleteUnavailableError'
}
}
/** Propriétés d'une « feature » GeoJSON renvoyée par la BAN (champs utilisés). */
interface BanFeatureProperties {
label?: string
name?: string
street?: string
postcode?: string
city?: string
}
/** Réponse GeoJSON FeatureCollection de la BAN. */
interface BanResponse {
features?: { properties?: BanFeatureProperties }[]
}
export function useAddressAutocomplete(): AddressAutocomplete {
return {
async searchCity(postalCode: string): Promise<CitySuggestion[]> {
let res: BanResponse
try {
res = await httpExternal<BanResponse>(BAN_SEARCH_URL, {
query: { q: postalCode, type: 'municipality' },
})
}
catch {
throw new AddressAutocompleteUnavailableError()
}
return (res.features ?? []).map((feature) => {
const props = feature.properties ?? {}
return {
city: props.city ?? props.name ?? '',
postalCode: props.postcode ?? '',
}
})
},
async searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]> {
// Pas de `type=housenumber` ici : sans filtre, la BAN classe rues +
// numéros par pertinence (comportement d'autocomplétion attendu).
// On n'ajoute `postcode` que s'il est fourni (sinon recherche large).
const banQuery: Record<string, string> = { q: query }
if (postalCode) {
banQuery.postcode = postalCode
}
let res: BanResponse
try {
res = await httpExternal<BanResponse>(BAN_SEARCH_URL, { query: banQuery })
}
catch {
throw new AddressAutocompleteUnavailableError()
}
return (res.features ?? []).map((feature) => {
const props = feature.properties ?? {}
return {
label: props.label ?? '',
// `name` porte la ligne d'adresse complète (numéro + voie) ;
// `street` ne contient que la voie. On privilégie `name`.
street: props.name ?? props.street ?? '',
postalCode: props.postcode ?? '',
city: props.city ?? '',
}
})
},
}
}
@@ -3,7 +3,7 @@ import type { Address } from '~/modules/directory/services/dto/address'
import { useContactService } from '~/modules/directory/services/contacts'
import { useAddressService } from '~/modules/directory/services/addresses'
type Owner = { client?: string, prospect?: string }
type Owner = { client?: string, prospect?: string, prestataire?: string }
/**
* Logique partagée des fiches détail Client/Prospect : blocs répétables Contact
@@ -21,17 +21,25 @@
<MalioInputText
v-model="info.email"
:label="$t('directory.info.fields.email')"
:error="emailError"
/>
<MalioInputText
v-model="info.phone"
:label="$t('directory.info.fields.phone')"
:error="phoneError"
/>
<MalioInputText
v-model="info.website"
class="col-span-2"
:label="$t('directory.info.fields.website')"
:error="websiteError"
/>
</div>
<div class="flex justify-center pt-2">
<MalioButton
button-class="w-auto px-6"
:label="$t('common.save')"
:disabled="savingInfo"
:disabled="savingInfo || !infoValid"
@click="saveInfo"
/>
</div>
@@ -109,6 +117,7 @@
<script setup lang="ts">
import type { Client } from '~/modules/directory/services/dto/client'
import { useClientService } from '~/modules/directory/services/clients'
import { isValidEmail, isValidFrPhone, isValidUrl } from '~/modules/directory/utils/validation'
definePageMeta({ middleware: ['admin'] })
@@ -153,19 +162,25 @@ const tabs = [
// Champs de base de la fiche, édités en mémoire et persistés au clic sur
// « Enregistrer » (PATCH), comme les onglets Contact/Adresse.
const info = reactive({ name: '', email: '', phone: '' })
const info = reactive({ name: '', email: '', phone: '', website: '' })
const infoTouched = reactive({ name: false })
const savingInfo = ref(false)
const emailError = computed(() => (isValidEmail(info.email) ? '' : t('directory.validation.emailInvalid')))
const phoneError = computed(() => (isValidFrPhone(info.phone) ? '' : t('directory.validation.phoneInvalid')))
const websiteError = computed(() => (isValidUrl(info.website) ? '' : t('directory.validation.urlInvalid')))
const infoValid = computed(() => !emailError.value && !phoneError.value && !websiteError.value)
async function saveInfo(): Promise<void> {
infoTouched.name = true
if (!info.name.trim() || savingInfo.value) return
if (!info.name.trim() || !infoValid.value || savingInfo.value) return
savingInfo.value = true
try {
client.value = await clientService.update(id, {
name: info.name.trim(),
email: info.email.trim() || null,
phone: info.phone.trim() || null,
website: info.website.trim() || null,
})
} finally {
savingInfo.value = false
@@ -181,6 +196,7 @@ onMounted(async () => {
info.name = client.value.name ?? ''
info.email = client.value.email ?? ''
info.phone = client.value.phone ?? ''
info.website = client.value.website ?? ''
await load()
loading.value = false
})
@@ -107,6 +107,46 @@
</MalioDataTable>
</div>
</template>
<!-- Prestataires -->
<template #prestataires>
<div class="flex min-h-[30rem] flex-col gap-4 pt-10">
<div class="flex items-center justify-end">
<MalioButton
icon-name="mdi:plus"
icon-position="left"
button-class="w-auto px-4"
:label="$t('directory.prestataires.add')"
@click="openCreatePrestataire"
/>
</div>
<MalioDataTable
:columns="prestataireColumns"
:items="prestataires"
:total-items="prestataires.length"
:empty-message="$t('directory.prestataires.empty')"
@row-click="openEditPrestataire"
>
<template #cell-email="{ item }">
{{ (item as Prestataire).email ?? '—' }}
</template>
<template #cell-phone="{ item }">
{{ (item as Prestataire).phone ?? '—' }}
</template>
<template #cell-actions="{ item }">
<div class="flex justify-end" @click.stop>
<MalioButtonIcon
icon="mdi:trash-can-outline"
:aria-label="$t('common.delete')"
button-class="!bg-red-100 !text-red-700"
:icon-size="18"
@click="askDeletePrestataire(item as Prestataire)"
/>
</div>
</template>
</MalioDataTable>
</div>
</template>
</MalioTabList>
<ClientDrawer
@@ -119,6 +159,11 @@
:prospect="selectedProspect"
@saved="onProspectSaved"
/>
<PrestataireDrawer
v-model="prestataireDrawerOpen"
:prestataire="selectedPrestataire"
@saved="loadPrestataires"
/>
<ConfirmDeleteModal
v-model="deleteModalOpen"
@@ -134,6 +179,8 @@ import type { Client } from '~/modules/directory/services/dto/client'
import { useClientService } from '~/modules/directory/services/clients'
import type { Prospect, ProspectStatus } from '~/modules/directory/services/dto/prospect'
import { useProspectService } from '~/modules/directory/services/prospects'
import type { Prestataire } from '~/modules/directory/services/dto/prestataire'
import { usePrestataireService } from '~/modules/directory/services/prestataires'
definePageMeta({ middleware: ['admin'] })
@@ -144,11 +191,13 @@ useHead({ title: t('directory.title') })
const clientService = useClientService()
const prospectService = useProspectService()
const prestataireService = usePrestataireService()
const activeTab = ref('clients')
const tabs = [
{ key: 'clients', label: t('directory.tabs.clients'), icon: 'mdi:account-tie-outline' },
{ key: 'prospects', label: t('directory.tabs.prospects'), icon: 'mdi:account-search-outline' },
{ key: 'prestataires', label: t('directory.tabs.prestataires'), icon: 'mdi:account-hard-hat-outline' },
]
// --- Clients ---
@@ -157,7 +206,7 @@ const clientDrawerOpen = ref(false)
const selectedClient = ref<Client | null>(null)
const clientColumns = [
{ key: 'name', label: t('prospects.fields.name') },
{ key: 'name', label: t('prospects.fields.company') },
{ key: 'email', label: t('prospects.fields.email') },
{ key: 'phone', label: t('prospects.fields.phone') },
{ key: 'actions', label: '' },
@@ -191,7 +240,6 @@ const statusOptions = [
]
const prospectColumns = [
{ key: 'name', label: t('prospects.fields.name') },
{ key: 'company', label: t('prospects.fields.company') },
{ key: 'status', label: t('prospects.fields.status') },
{ key: 'email', label: t('prospects.fields.email') },
@@ -247,26 +295,62 @@ async function onProspectSaved() {
await Promise.all([loadProspects(), loadClients()])
}
// --- Suppression (clients & prospects) ---
// --- Prestataires ---
const prestataires = ref<Prestataire[]>([])
const prestataireDrawerOpen = ref(false)
const selectedPrestataire = ref<Prestataire | null>(null)
const prestataireColumns = [
{ key: 'name', label: t('prospects.fields.company') },
{ key: 'email', label: t('prospects.fields.email') },
{ key: 'phone', label: t('prospects.fields.phone') },
{ key: 'actions', label: '' },
]
async function loadPrestataires() {
prestataires.value = await prestataireService.getAll()
}
function openCreatePrestataire() {
selectedPrestataire.value = null
prestataireDrawerOpen.value = true
}
function openEditPrestataire(item: Record<string, unknown>) {
navigateTo(`/directory/prestataires/${(item as Prestataire).id}`)
}
// --- Suppression (clients, prospects & prestataires) ---
type DeleteTarget =
| { type: 'client'; item: Client }
| { type: 'prospect'; item: Prospect }
| { type: 'prestataire'; item: Prestataire }
const deleteModalOpen = ref(false)
const deleteTarget = ref<DeleteTarget | null>(null)
const deleteModalTitle = computed(() =>
deleteTarget.value?.type === 'prospect'
? t('prospects.deleteConfirmTitle')
: t('clients.deleteConfirmTitle'),
)
const deleteModalTitle = computed(() => {
switch (deleteTarget.value?.type) {
case 'prospect':
return t('prospects.deleteConfirmTitle')
case 'prestataire':
return t('prestataires.deleteConfirmTitle')
default:
return t('clients.deleteConfirmTitle')
}
})
const deleteModalMessage = computed(() => {
if (!deleteTarget.value) return ''
const name = deleteTarget.value.item.name
return deleteTarget.value.type === 'prospect'
? t('prospects.deleteConfirmMessage', { name })
: t('clients.deleteConfirmMessage', { name })
const target = deleteTarget.value
if (!target) return ''
switch (target.type) {
case 'prospect':
return t('prospects.deleteConfirmMessage', { name: target.item.company })
case 'prestataire':
return t('prestataires.deleteConfirmMessage', { name: target.item.name })
default:
return t('clients.deleteConfirmMessage', { name: target.item.name })
}
})
function askDeleteClient(item: Client) {
@@ -279,6 +363,11 @@ function askDeleteProspect(item: Prospect) {
deleteModalOpen.value = true
}
function askDeletePrestataire(item: Prestataire) {
deleteTarget.value = { type: 'prestataire', item }
deleteModalOpen.value = true
}
async function confirmDelete() {
const target = deleteTarget.value
if (!target) return
@@ -286,9 +375,12 @@ async function confirmDelete() {
if (target.type === 'client') {
await clientService.remove(target.item.id)
await loadClients()
} else {
} else if (target.type === 'prospect') {
await prospectService.remove(target.item.id)
await loadProspects()
} else {
await prestataireService.remove(target.item.id)
await loadPrestataires()
}
deleteModalOpen.value = false
@@ -298,7 +390,7 @@ async function confirmDelete() {
watch(statusFilter, loadProspects)
onMounted(async () => {
await Promise.all([loadClients(), loadProspects()])
await Promise.all([loadClients(), loadProspects(), loadPrestataires()])
})
</script>
@@ -0,0 +1,201 @@
<template>
<div class="flex flex-col gap-6">
<div class="flex items-center gap-3 pt-4">
<MalioButtonIcon icon="mdi:arrow-left" :aria-label="$t('common.back')" @click="goBack" />
<h1 class="text-2xl font-bold text-neutral-900">{{ prestataire?.name ?? '…' }}</h1>
</div>
<p v-if="loading">{{ $t('common.loading') }}</p>
<template v-else-if="prestataire">
<MalioTabList v-model="activeTab" :tabs="tabs">
<template #info>
<div class="flex flex-col gap-4 pt-6">
<div class="relative grid grid-cols-2 gap-x-[44px] gap-y-4 rounded-lg bg-white px-7 py-5 shadow-[0_4px_4px_0_rgba(0,0,0,0.10)]">
<MalioInputText
v-model="info.name"
class="col-span-2"
:label="$t('directory.info.fields.name')"
:error="infoTouched.name && !info.name.trim() ? $t('directory.validation.nameRequired') : ''"
@blur="infoTouched.name = true"
/>
<MalioInputText
v-model="info.email"
:label="$t('directory.info.fields.email')"
:error="emailError"
/>
<MalioInputText
v-model="info.phone"
:label="$t('directory.info.fields.phone')"
:error="phoneError"
/>
<MalioInputText
v-model="info.website"
class="col-span-2"
:label="$t('directory.info.fields.website')"
:error="websiteError"
/>
</div>
<div class="flex justify-center pt-2">
<MalioButton
button-class="w-auto px-6"
:label="$t('common.save')"
:disabled="savingInfo || !infoValid"
@click="saveInfo"
/>
</div>
</div>
</template>
<template #contact>
<div class="flex flex-col gap-4 pt-6">
<DirectoryContactBlock
v-for="(contact, i) in contacts"
:key="contact.id || `new-${i}`"
:model-value="contact"
:title="$t('directory.contacts.item', { n: i + 1 })"
:removable="contacts.length > 0"
@update:model-value="(v) => onContactInput(i, v)"
@remove="removeContact(i)"
/>
<div class="flex justify-center gap-3 pt-2">
<MalioButton
variant="tertiary"
icon-name="mdi:plus"
icon-position="left"
button-class="w-auto px-4"
:label="$t('directory.contacts.add')"
@click="addContact"
/>
<MalioButton
button-class="w-auto px-6"
:label="$t('common.save')"
:disabled="savingContacts"
@click="saveContacts"
/>
</div>
</div>
</template>
<template #address>
<div class="flex flex-col gap-4 pt-6">
<DirectoryAddressBlock
v-for="(address, i) in addresses"
:key="address.id || `new-${i}`"
:model-value="address"
:title="$t('directory.addresses.item', { n: i + 1 })"
:removable="addresses.length > 0"
@update:model-value="(v) => onAddressInput(i, v)"
@remove="removeAddress(i)"
/>
<div class="flex justify-center gap-3 pt-2">
<MalioButton
variant="tertiary"
icon-name="mdi:plus"
icon-position="left"
button-class="w-auto px-4"
:label="$t('directory.addresses.add')"
@click="addAddress"
/>
<MalioButton
button-class="w-auto px-6"
:label="$t('common.save')"
:disabled="savingAddresses"
@click="saveAddresses"
/>
</div>
</div>
</template>
<template #report>
<CommercialReportTab :owner="owner" :can-manage="canManage" />
</template>
</MalioTabList>
</template>
</div>
</template>
<script setup lang="ts">
import type { Prestataire } from '~/modules/directory/services/dto/prestataire'
import { usePrestataireService } from '~/modules/directory/services/prestataires'
import { isValidEmail, isValidFrPhone, isValidUrl } from '~/modules/directory/utils/validation'
definePageMeta({ middleware: ['admin'] })
const route = useRoute()
const router = useRouter()
const { t } = useI18n()
const id = Number(route.params.id)
const ownerIri = `/api/prestataires/${id}`
const owner = { prestataire: ownerIri }
const prestataireService = usePrestataireService()
const {
contacts,
addresses,
savingContacts,
savingAddresses,
onContactInput,
addContact,
removeContact,
saveContacts,
onAddressInput,
addAddress,
removeAddress,
saveAddresses,
load,
} = useDirectoryDetail(owner)
const { can } = usePermissions()
const canManage = computed(() => can('directory.providers.manage'))
const prestataire = ref<Prestataire | null>(null)
const loading = ref(true)
const activeTab = ref('info')
const tabs = [
{ key: 'info', label: t('directory.tabs.info'), icon: 'mdi:information-outline' },
{ key: 'contact', label: t('directory.tabs.contact'), icon: 'mdi:account-outline' },
{ key: 'address', label: t('directory.tabs.address'), icon: 'mdi:map-marker-outline' },
{ key: 'report', label: t('directory.tabs.report'), icon: 'mdi:file-document-outline' },
]
const info = reactive({ name: '', email: '', phone: '', website: '' })
const infoTouched = reactive({ name: false })
const savingInfo = ref(false)
const emailError = computed(() => (isValidEmail(info.email) ? '' : t('directory.validation.emailInvalid')))
const phoneError = computed(() => (isValidFrPhone(info.phone) ? '' : t('directory.validation.phoneInvalid')))
const websiteError = computed(() => (isValidUrl(info.website) ? '' : t('directory.validation.urlInvalid')))
const infoValid = computed(() => !emailError.value && !phoneError.value && !websiteError.value)
async function saveInfo(): Promise<void> {
infoTouched.name = true
if (!info.name.trim() || !infoValid.value || savingInfo.value) return
savingInfo.value = true
try {
prestataire.value = await prestataireService.update(id, {
name: info.name.trim(),
email: info.email.trim() || null,
phone: info.phone.trim() || null,
website: info.website.trim() || null,
})
} finally {
savingInfo.value = false
}
}
function goBack(): void {
router.push('/directory')
}
onMounted(async () => {
prestataire.value = await prestataireService.getById(id)
info.name = prestataire.value.name ?? ''
info.email = prestataire.value.email ?? ''
info.phone = prestataire.value.phone ?? ''
info.website = prestataire.value.website ?? ''
await load()
loading.value = false
})
</script>
@@ -2,7 +2,7 @@
<div class="flex flex-col gap-6">
<div class="flex items-center gap-3 pt-4">
<MalioButtonIcon icon="mdi:arrow-left" :aria-label="$t('common.back')" @click="goBack" />
<h1 class="text-2xl font-bold text-neutral-900">{{ prospect?.name ?? '…' }}</h1>
<h1 class="text-2xl font-bold text-neutral-900">{{ prospect?.company ?? '…' }}</h1>
</div>
<p v-if="loading">{{ $t('common.loading') }}</p>
@@ -11,16 +11,12 @@
<template #info>
<div class="flex flex-col gap-4 pt-6">
<div class="relative grid grid-cols-2 gap-x-[44px] gap-y-4 rounded-lg bg-white px-7 py-5 shadow-[0_4px_4px_0_rgba(0,0,0,0.10)]">
<MalioInputText
v-model="info.name"
class="col-span-2"
:label="$t('prospects.fields.name')"
:error="infoTouched.name && !info.name.trim() ? $t('prospects.validation.nameRequired') : ''"
@blur="infoTouched.name = true"
/>
<MalioInputText
v-model="info.company"
class="col-span-2"
:label="$t('prospects.fields.company')"
:error="infoTouched.company && !info.company.trim() ? $t('prospects.validation.companyRequired') : ''"
@blur="infoTouched.company = true"
/>
<MalioSelect
v-model="info.status"
@@ -28,13 +24,20 @@
:options="statusOptions"
group-class="w-full"
/>
<MalioInputText
v-model="info.website"
:label="$t('prospects.fields.website')"
:error="websiteError"
/>
<MalioInputText
v-model="info.email"
:label="$t('prospects.fields.email')"
:error="emailError"
/>
<MalioInputText
v-model="info.phone"
:label="$t('prospects.fields.phone')"
:error="phoneError"
/>
<MalioInputText
v-model="info.source"
@@ -51,7 +54,7 @@
<MalioButton
button-class="w-auto px-6"
:label="$t('common.save')"
:disabled="savingInfo"
:disabled="savingInfo || !infoValid"
@click="saveInfo"
/>
</div>
@@ -129,6 +132,7 @@
<script setup lang="ts">
import type { Prospect, ProspectStatus } from '~/modules/directory/services/dto/prospect'
import { useProspectService } from '~/modules/directory/services/prospects'
import { isValidEmail, isValidFrPhone, isValidUrl } from '~/modules/directory/utils/validation'
definePageMeta({ middleware: ['admin'] })
@@ -182,27 +186,32 @@ const statusOptions = [
// Champs de base de la fiche, édités en mémoire et persistés au clic sur
// « Enregistrer » (PATCH), comme les onglets Contact/Adresse.
const info = reactive<{
name: string
company: string
email: string
phone: string
website: string
status: ProspectStatus
source: string
notes: string
}>({ name: '', company: '', email: '', phone: '', status: 'new', source: '', notes: '' })
const infoTouched = reactive({ name: false })
}>({ company: '', email: '', phone: '', website: '', status: 'new', source: '', notes: '' })
const infoTouched = reactive({ company: false })
const savingInfo = ref(false)
const emailError = computed(() => (isValidEmail(info.email) ? '' : t('directory.validation.emailInvalid')))
const phoneError = computed(() => (isValidFrPhone(info.phone) ? '' : t('directory.validation.phoneInvalid')))
const websiteError = computed(() => (isValidUrl(info.website) ? '' : t('directory.validation.urlInvalid')))
const infoValid = computed(() => !emailError.value && !phoneError.value && !websiteError.value)
async function saveInfo(): Promise<void> {
infoTouched.name = true
if (!info.name.trim() || savingInfo.value) return
infoTouched.company = true
if (!info.company.trim() || !infoValid.value || savingInfo.value) return
savingInfo.value = true
try {
prospect.value = await prospectService.update(id, {
name: info.name.trim(),
company: info.company.trim() || null,
company: info.company.trim(),
email: info.email.trim() || null,
phone: info.phone.trim() || null,
website: info.website.trim() || null,
status: info.status,
source: info.source.trim() || null,
notes: info.notes.trim() || null,
@@ -218,10 +227,10 @@ function goBack(): void {
onMounted(async () => {
prospect.value = await prospectService.getById(id)
info.name = prospect.value.name ?? ''
info.company = prospect.value.company ?? ''
info.email = prospect.value.email ?? ''
info.phone = prospect.value.phone ?? ''
info.website = prospect.value.website ?? ''
info.status = prospect.value.status ?? 'new'
info.source = prospect.value.source ?? ''
info.notes = prospect.value.notes ?? ''
@@ -2,7 +2,7 @@ import type { Address, AddressWrite } from './dto/address'
import type { HydraCollection } from '~/utils/api'
import { extractHydraMembers } from '~/utils/api'
type Owner = { client?: string, prospect?: string }
type Owner = { client?: string, prospect?: string, prestataire?: string }
export function useAddressService() {
const api = useApi()
@@ -2,7 +2,7 @@ import type { CommercialReport, CommercialReportWrite } from './dto/commercial-r
import type { HydraCollection } from '~/utils/api'
import { extractHydraMembers } from '~/utils/api'
type Owner = { client?: string, prospect?: string }
type Owner = { client?: string, prospect?: string, prestataire?: string }
export function useCommercialReportService() {
const api = useApi()
@@ -2,7 +2,7 @@ import type { Contact, ContactWrite } from './dto/contact'
import type { HydraCollection } from '~/utils/api'
import { extractHydraMembers } from '~/utils/api'
type Owner = { client?: string, prospect?: string }
type Owner = { client?: string, prospect?: string, prestataire?: string }
export function useContactService() {
const api = useApi()
@@ -9,6 +9,7 @@ export type Address = {
country: string
client?: string | null
prospect?: string | null
prestataire?: string | null
}
export type AddressWrite = {
@@ -20,4 +21,5 @@ export type AddressWrite = {
country: string
client?: string | null
prospect?: string | null
prestataire?: string | null
}
@@ -4,10 +4,12 @@ export type Client = {
name: string
email: string | null
phone: string | null
website: string | null
}
export type ClientWrite = {
name: string
email?: string | null
phone?: string | null
website?: string | null
}
@@ -12,6 +12,7 @@ export type CommercialReport = {
author?: { id: number, username: string } | null
client?: string | null
prospect?: string | null
prestataire?: string | null
documents?: ReportDocument[]
createdAt?: string
updatedAt?: string
@@ -24,4 +25,5 @@ export type CommercialReportWrite = {
type: ReportType
client?: string | null
prospect?: string | null
prestataire?: string | null
}
@@ -9,6 +9,7 @@ export type Contact = {
phoneSecondary: string | null
client?: string | null
prospect?: string | null
prestataire?: string | null
}
export type ContactWrite = {
@@ -20,4 +21,5 @@ export type ContactWrite = {
phoneSecondary: string | null
client?: string | null
prospect?: string | null
prestataire?: string | null
}
@@ -0,0 +1,15 @@
export type Prestataire = {
id: number
'@id'?: string
name: string
email: string | null
phone: string | null
website: string | null
}
export type PrestataireWrite = {
name: string
email?: string | null
phone?: string | null
website?: string | null
}
@@ -5,10 +5,10 @@ export type ProspectStatus = 'new' | 'contacted' | 'qualified' | 'won' | 'lost'
export type Prospect = {
id: number
'@id'?: string
name: string
company: string | null
company: string
email: string | null
phone: string | null
website: string | null
status: ProspectStatus
source: string | null
notes: string | null
@@ -18,10 +18,10 @@ export type Prospect = {
}
export type ProspectWrite = {
name: string
company?: string | null
company: string
email?: string | null
phone?: string | null
website?: string | null
status?: ProspectStatus
source?: string | null
notes?: string | null
@@ -0,0 +1,36 @@
import type { Prestataire, PrestataireWrite } from './dto/prestataire'
import type { HydraCollection } from '~/utils/api'
import { extractHydraMembers } from '~/utils/api'
export function usePrestataireService() {
const api = useApi()
async function getAll(): Promise<Prestataire[]> {
const data = await api.get<HydraCollection<Prestataire>>('/prestataires')
return extractHydraMembers(data)
}
async function getById(id: number): Promise<Prestataire> {
return api.get<Prestataire>(`/prestataires/${id}`)
}
async function create(payload: PrestataireWrite): Promise<Prestataire> {
return api.post<Prestataire>('/prestataires', payload as Record<string, unknown>, {
toastSuccessKey: 'prestataires.created',
})
}
async function update(id: number, payload: Partial<PrestataireWrite>): Promise<Prestataire> {
return api.patch<Prestataire>(`/prestataires/${id}`, payload as Record<string, unknown>, {
toastSuccessKey: 'prestataires.updated',
})
}
async function remove(id: number): Promise<void> {
await api.delete(`/prestataires/${id}`, {}, {
toastSuccessKey: 'prestataires.deleted',
})
}
return { getAll, getById, create, update, remove }
}
@@ -0,0 +1,40 @@
// Validateurs partagés du répertoire (annuaire). Chaque validateur considère
// une valeur VIDE comme valide : les champs email/téléphone/site web sont
// facultatifs — la validation ne porte que sur le format quand c'est renseigné.
/** Email basique (présence d'un @ entouré de caractères, un point dans le domaine). */
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
/**
* Téléphone français : 10 chiffres commençant par 0 (ex. `0549200910`) — format
* saisi par l'utilisateur, sans séparateurs — ou notation internationale
* `+33XXXXXXXXX` (9 chiffres après l'indicatif). Les espaces, points et tirets
* sont tolérés à la frappe (retirés avant contrôle).
*/
const FR_PHONE_NATIONAL_RE = /^0\d{9}$/
const FR_PHONE_INTL_RE = /^\+33\d{9}$/
const URL_RE = /^https?:\/\/[^\s.]+\.[^\s]+$/
/** Retire les séparateurs usuels d'un numéro (espaces, points, tirets, parenthèses). */
export function stripPhoneSeparators(value: string): string {
return value.replace(/[\s.\-()]/g, '')
}
export function isValidEmail(value: string | null | undefined): boolean {
const v = (value ?? '').trim()
if (v === '') return true
return EMAIL_RE.test(v)
}
export function isValidFrPhone(value: string | null | undefined): boolean {
const v = stripPhoneSeparators((value ?? '').trim())
if (v === '') return true
return FR_PHONE_NATIONAL_RE.test(v) || FR_PHONE_INTL_RE.test(v)
}
export function isValidUrl(value: string | null | undefined): boolean {
const v = (value ?? '').trim()
if (v === '') return true
return URL_RE.test(v)
}
+1 -3
View File
@@ -21,7 +21,6 @@
</div>
<div>
<AdminClientTab v-if="activeTab === 'clients'" />
<AdminWorkflowTab v-if="activeTab === 'workflows'" />
<AdminEffortTab v-if="activeTab === 'efforts'" />
<AdminPriorityTab v-if="activeTab === 'priorities'" />
@@ -50,7 +49,6 @@ const canViewRoles = computed(() => can('core.roles.view'))
const canViewAudit = computed(() => can('core.audit_log.view'))
const tabs = [
{ key: 'clients', label: 'Clients' },
{ key: 'workflows', label: 'Workflows' },
{ key: 'efforts', label: 'Efforts' },
{ key: 'priorities', label: 'Priorités' },
@@ -72,5 +70,5 @@ const visibleTabs = computed(() =>
tabs.filter((tab) => !('permission' in tab) || can(tab.permission)),
)
const activeTab = ref<TabKey>('clients')
const activeTab = ref<TabKey>('workflows')
</script>
+26
View File
@@ -0,0 +1,26 @@
import { $fetch } from 'ofetch'
/**
* Appel HTTP vers un service EXTERNE (hors API Lesstime) : pas de cookie de
* session, pas d'enveloppe Hydra, timeout court. Utilisé par l'autocomplétion
* d'adresse branchée sur la Base Adresse Nationale (api-adresse.data.gouv.fr).
* Ne jamais passer par `useApi()` pour ces domaines tiers.
*/
export interface HttpExternalOptions {
/** Paramètres de query string (encodés par ofetch). */
query?: Record<string, string | number | undefined>
/** Timeout en millisecondes avant abandon (défaut 5000). */
timeoutMs?: number
}
export async function httpExternal<T>(
url: string,
opts: HttpExternalOptions = {},
): Promise<T> {
return $fetch<T>(url, {
query: opts.query,
credentials: 'omit',
retry: 0,
timeout: opts.timeoutMs ?? 5000,
})
}
+89
View File
@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260624153709 extends AbstractMigration
{
public function getDescription(): string
{
return 'Directory: prestataire entity + website on client/prospect/prestataire + prestataire ownership on contacts/addresses/reports + prospect company-only';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE prestataire (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) DEFAULT NULL, phone VARCHAR(50) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_by INT DEFAULT NULL, updated_by INT DEFAULT NULL, PRIMARY KEY (id))');
$this->addSql('CREATE INDEX IDX_60A26480DE12AB56 ON prestataire (created_by)');
$this->addSql('CREATE INDEX IDX_60A2648016FE72E1 ON prestataire (updated_by)');
$this->addSql('ALTER TABLE prestataire ADD CONSTRAINT FK_60A26480DE12AB56 FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER TABLE prestataire ADD CONSTRAINT FK_60A2648016FE72E1 FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER TABLE client ADD website VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE commercial_report ADD prestataire_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE commercial_report ADD CONSTRAINT FK_886919D8BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('CREATE INDEX IDX_886919D8BE3DB2B7 ON commercial_report (prestataire_id)');
$this->addSql('ALTER TABLE directory_address ADD prestataire_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE directory_address ADD CONSTRAINT FK_6E5D9707BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('CREATE INDEX IDX_6E5D9707BE3DB2B7 ON directory_address (prestataire_id)');
$this->addSql('ALTER TABLE directory_contact ADD prestataire_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE directory_contact ADD CONSTRAINT FK_2F711EBEBE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('CREATE INDEX IDX_2F711EBEBE3DB2B7 ON directory_contact (prestataire_id)');
// Prospect désormais société-only : on conserve la donnée existante en
// recopiant le nom dans la société quand celle-ci est vide, avant de
// rendre la colonne obligatoire et de supprimer la colonne name.
$this->addSql('ALTER TABLE prospect ADD website VARCHAR(255) DEFAULT NULL');
$this->addSql("UPDATE prospect SET company = name WHERE company IS NULL OR company = ''");
$this->addSql('ALTER TABLE prospect ALTER company SET NOT NULL');
$this->addSql('ALTER TABLE prospect DROP name');
// Ownership CHECK constraints: chaque ligne appartient à un client,
// un prospect OU un prestataire.
$this->addSql('ALTER TABLE directory_contact DROP CONSTRAINT chk_contact_owner');
$this->addSql('ALTER TABLE directory_contact ADD CONSTRAINT chk_contact_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL OR prestataire_id IS NOT NULL)');
$this->addSql('ALTER TABLE directory_address DROP CONSTRAINT chk_address_owner');
$this->addSql('ALTER TABLE directory_address ADD CONSTRAINT chk_address_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL OR prestataire_id IS NOT NULL)');
$this->addSql('ALTER TABLE commercial_report DROP CONSTRAINT chk_report_owner');
$this->addSql('ALTER TABLE commercial_report ADD CONSTRAINT chk_report_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL OR prestataire_id IS NOT NULL)');
}
public function down(Schema $schema): void
{
// Rétablit les contraintes d'ownership client/prospect (sans prestataire).
$this->addSql('ALTER TABLE directory_contact DROP CONSTRAINT chk_contact_owner');
$this->addSql('ALTER TABLE directory_address DROP CONSTRAINT chk_address_owner');
$this->addSql('ALTER TABLE commercial_report DROP CONSTRAINT chk_report_owner');
$this->addSql('ALTER TABLE commercial_report DROP CONSTRAINT FK_886919D8BE3DB2B7');
$this->addSql('DROP INDEX IDX_886919D8BE3DB2B7');
$this->addSql('ALTER TABLE commercial_report DROP prestataire_id');
$this->addSql('ALTER TABLE directory_address DROP CONSTRAINT FK_6E5D9707BE3DB2B7');
$this->addSql('DROP INDEX IDX_6E5D9707BE3DB2B7');
$this->addSql('ALTER TABLE directory_address DROP prestataire_id');
$this->addSql('ALTER TABLE directory_contact DROP CONSTRAINT FK_2F711EBEBE3DB2B7');
$this->addSql('DROP INDEX IDX_2F711EBEBE3DB2B7');
$this->addSql('ALTER TABLE directory_contact DROP prestataire_id');
$this->addSql('ALTER TABLE directory_contact ADD CONSTRAINT chk_contact_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL)');
$this->addSql('ALTER TABLE directory_address ADD CONSTRAINT chk_address_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL)');
$this->addSql('ALTER TABLE commercial_report ADD CONSTRAINT chk_report_owner CHECK (client_id IS NOT NULL OR prospect_id IS NOT NULL)');
$this->addSql('ALTER TABLE prestataire DROP CONSTRAINT FK_60A26480DE12AB56');
$this->addSql('ALTER TABLE prestataire DROP CONSTRAINT FK_60A2648016FE72E1');
$this->addSql('DROP TABLE prestataire');
$this->addSql('ALTER TABLE client DROP website');
// Restaure la colonne name (recopiée depuis company) puis l'oblige.
$this->addSql('ALTER TABLE prospect ADD name VARCHAR(255) DEFAULT NULL');
$this->addSql('UPDATE prospect SET name = company');
$this->addSql('ALTER TABLE prospect ALTER name SET NOT NULL');
$this->addSql('ALTER TABLE prospect DROP website');
$this->addSql('ALTER TABLE prospect ALTER company DROP NOT NULL');
}
}
-3
View File
@@ -127,7 +127,6 @@ class AppFixtures extends Fixture
// Prospects
$prospectLead = new Prospect();
$prospectLead->setName('Marie Dupont');
$prospectLead->setCompany('Atelier Dupont');
$prospectLead->setEmail('marie@atelier-dupont.fr');
$prospectLead->setPhone('06 11 22 33 44');
@@ -145,7 +144,6 @@ class AppFixtures extends Fixture
$manager->persist($addressLead);
$prospectQualified = new Prospect();
$prospectQualified->setName('Jean Martin');
$prospectQualified->setCompany('Martin & Fils');
$prospectQualified->setEmail('contact@martin-fils.fr');
$prospectQualified->setPhone('07 55 66 77 88');
@@ -163,7 +161,6 @@ class AppFixtures extends Fixture
$manager->persist($addressQualified);
$prospectWon = new Prospect();
$prospectWon->setName('Sophie Bernard');
$prospectWon->setCompany('ACME Corp');
$prospectWon->setEmail('contact@acme.com');
$prospectWon->setPhone('01 23 45 67 89');
+2
View File
@@ -38,6 +38,8 @@ final class DirectoryModule implements ModuleInterface
['code' => 'directory.clients.manage', 'label' => 'Gérer les clients'],
['code' => 'directory.prospects.view', 'label' => 'Voir les prospects'],
['code' => 'directory.prospects.manage', 'label' => 'Gérer les prospects'],
['code' => 'directory.providers.view', 'label' => 'Voir les prestataires'],
['code' => 'directory.providers.manage', 'label' => 'Gérer les prestataires'],
];
}
}
+23 -6
View File
@@ -23,17 +23,17 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[Auditable]
#[ApiResource(
operations: [
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
],
normalizationContext: ['groups' => ['address:read']],
denormalizationContext: ['groups' => ['address:write']],
order: ['id' => 'ASC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact'])]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact', 'prestataire' => 'exact'])]
#[ORM\Entity(repositoryClass: DoctrineAddressRepository::class)]
#[ORM\Table(name: 'directory_address')]
class Address implements TimestampableInterface, BlamableInterface
@@ -80,6 +80,11 @@ class Address implements TimestampableInterface, BlamableInterface
#[Groups(['address:read', 'address:write'])]
private ?Prospect $prospect = null;
#[ORM\ManyToOne(targetEntity: Prestataire::class)]
#[ORM\JoinColumn(name: 'prestataire_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
#[Groups(['address:read', 'address:write'])]
private ?Prestataire $prestataire = null;
public function getId(): ?int
{
return $this->id;
@@ -180,4 +185,16 @@ class Address implements TimestampableInterface, BlamableInterface
return $this;
}
public function getPrestataire(): ?Prestataire
{
return $this->prestataire;
}
public function setPrestataire(?Prestataire $prestataire): static
{
$this->prestataire = $prestataire;
return $this;
}
}
@@ -58,6 +58,10 @@ class Client implements ClientInterface, TimestampableInterface, BlamableInterfa
#[Groups(['client:read', 'client:write'])]
private ?string $phone = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['client:read', 'client:write'])]
private ?string $website = null;
/** @var Collection<int, ProjectInterface> */
#[ORM\OneToMany(targetEntity: ProjectInterface::class, mappedBy: 'client')]
private Collection $projects;
@@ -108,6 +112,18 @@ class Client implements ClientInterface, TimestampableInterface, BlamableInterfa
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): static
{
$this->website = $website;
return $this;
}
/** @return Collection<int, ProjectInterface> */
public function getProjects(): Collection
{
@@ -26,17 +26,17 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[ApiResource(
operations: [
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
],
normalizationContext: ['groups' => ['commercial_report:read']],
denormalizationContext: ['groups' => ['commercial_report:write']],
order: ['occurredAt' => 'DESC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact'])]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact', 'prestataire' => 'exact'])]
#[ORM\Entity(repositoryClass: DoctrineCommercialReportRepository::class)]
#[ORM\Table(name: 'commercial_report')]
class CommercialReport implements TimestampableInterface
@@ -80,6 +80,11 @@ class CommercialReport implements TimestampableInterface
#[Groups(['commercial_report:read', 'commercial_report:write'])]
private ?Prospect $prospect = null;
#[ORM\ManyToOne(targetEntity: Prestataire::class)]
#[ORM\JoinColumn(name: 'prestataire_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
#[Groups(['commercial_report:read', 'commercial_report:write'])]
private ?Prestataire $prestataire = null;
/** @var Collection<int, ReportDocument> */
#[ORM\OneToMany(targetEntity: ReportDocument::class, mappedBy: 'commercialReport', cascade: ['remove'])]
#[Groups(['commercial_report:read'])]
@@ -179,6 +184,18 @@ class CommercialReport implements TimestampableInterface
return $this;
}
public function getPrestataire(): ?Prestataire
{
return $this->prestataire;
}
public function setPrestataire(?Prestataire $prestataire): static
{
$this->prestataire = $prestataire;
return $this;
}
/** @return Collection<int, ReportDocument> */
public function getDocuments(): Collection
{
+23 -6
View File
@@ -23,17 +23,17 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[Auditable]
#[ApiResource(
operations: [
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage')"),
new GetCollection(paginationEnabled: false, security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Get(security: "is_granted('directory.clients.view') or is_granted('directory.prospects.view') or is_granted('directory.providers.view')"),
new Post(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Patch(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
new Delete(security: "is_granted('directory.clients.manage') or is_granted('directory.prospects.manage') or is_granted('directory.providers.manage')"),
],
normalizationContext: ['groups' => ['contact:read']],
denormalizationContext: ['groups' => ['contact:write']],
order: ['lastName' => 'ASC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact'])]
#[ApiFilter(SearchFilter::class, properties: ['client' => 'exact', 'prospect' => 'exact', 'prestataire' => 'exact'])]
#[ORM\Entity(repositoryClass: DoctrineContactRepository::class)]
#[ORM\Table(name: 'directory_contact')]
class Contact implements TimestampableInterface, BlamableInterface
@@ -80,6 +80,11 @@ class Contact implements TimestampableInterface, BlamableInterface
#[Groups(['contact:read', 'contact:write'])]
private ?Prospect $prospect = null;
#[ORM\ManyToOne(targetEntity: Prestataire::class)]
#[ORM\JoinColumn(name: 'prestataire_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
#[Groups(['contact:read', 'contact:write'])]
private ?Prestataire $prestataire = null;
public function getId(): ?int
{
return $this->id;
@@ -180,4 +185,16 @@ class Contact implements TimestampableInterface, BlamableInterface
return $this;
}
public function getPrestataire(): ?Prestataire
{
return $this->prestataire;
}
public function setPrestataire(?Prestataire $prestataire): static
{
$this->prestataire = $prestataire;
return $this;
}
}
@@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Module\Directory\Infrastructure\Doctrine\DoctrinePrestataireRepository;
use App\Shared\Domain\Attribute\Auditable;
use App\Shared\Domain\Contract\BlamableInterface;
use App\Shared\Domain\Contract\TimestampableInterface;
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[Auditable]
#[ApiResource(
operations: [
new GetCollection(paginationEnabled: false, security: "is_granted('directory.providers.view')"),
new Get(security: "is_granted('directory.providers.view')"),
new Post(security: "is_granted('directory.providers.manage')"),
new Patch(security: "is_granted('directory.providers.manage')"),
new Delete(security: "is_granted('directory.providers.manage')"),
],
normalizationContext: ['groups' => ['prestataire:read']],
denormalizationContext: ['groups' => ['prestataire:write']],
order: ['name' => 'ASC'],
)]
#[ORM\Entity(repositoryClass: DoctrinePrestataireRepository::class)]
#[ORM\Table(name: 'prestataire')]
class Prestataire implements TimestampableInterface, BlamableInterface
{
use TimestampableBlamableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['prestataire:read'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['prestataire:read', 'prestataire:write'])]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['prestataire:read', 'prestataire:write'])]
private ?string $email = null;
#[ORM\Column(length: 50, nullable: true)]
#[Groups(['prestataire:read', 'prestataire:write'])]
private ?string $phone = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['prestataire:read', 'prestataire:write'])]
private ?string $website = null;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): static
{
$this->website = $website;
return $this;
}
}
+18 -18
View File
@@ -40,7 +40,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
],
normalizationContext: ['groups' => ['prospect:read']],
denormalizationContext: ['groups' => ['prospect:write']],
order: ['name' => 'ASC'],
order: ['company' => 'ASC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['status' => 'exact'])]
#[ORM\Entity(repositoryClass: DoctrineProspectRepository::class)]
@@ -57,10 +57,6 @@ class Prospect implements TimestampableInterface, BlamableInterface
#[ORM\Column(length: 255)]
#[Groups(['prospect:read', 'prospect:write'])]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['prospect:read', 'prospect:write'])]
private ?string $company = null;
#[ORM\Column(length: 255, nullable: true)]
@@ -71,6 +67,10 @@ class Prospect implements TimestampableInterface, BlamableInterface
#[Groups(['prospect:read', 'prospect:write'])]
private ?string $phone = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['prospect:read', 'prospect:write'])]
private ?string $website = null;
#[ORM\Column(type: Types::STRING, length: 32, enumType: ProspectStatus::class)]
#[Groups(['prospect:read', 'prospect:write'])]
private ProspectStatus $status = ProspectStatus::New;
@@ -93,24 +93,12 @@ class Prospect implements TimestampableInterface, BlamableInterface
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(?string $company): static
public function setCompany(string $company): static
{
$this->company = $company;
@@ -141,6 +129,18 @@ class Prospect implements TimestampableInterface, BlamableInterface
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): static
{
$this->website = $website;
return $this;
}
public function getStatus(): ProspectStatus
{
return $this->status;
@@ -9,4 +9,12 @@ use App\Module\Directory\Domain\Entity\Address;
interface AddressRepositoryInterface
{
public function findById(int $id): ?Address;
/**
* @param array<string, mixed> $criteria
* @param null|array<string, string> $orderBy
*
* @return Address[]
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
}
@@ -9,4 +9,12 @@ use App\Module\Directory\Domain\Entity\CommercialReport;
interface CommercialReportRepositoryInterface
{
public function findById(int $id): ?CommercialReport;
/**
* @param array<string, mixed> $criteria
* @param null|array<string, string> $orderBy
*
* @return CommercialReport[]
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
}
@@ -9,4 +9,12 @@ use App\Module\Directory\Domain\Entity\Contact;
interface ContactRepositoryInterface
{
public function findById(int $id): ?Contact;
/**
* @param array<string, mixed> $criteria
* @param null|array<string, string> $orderBy
*
* @return Contact[]
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Domain\Repository;
use App\Module\Directory\Domain\Entity\Prestataire;
interface PrestataireRepositoryInterface
{
public function findById(int $id): ?Prestataire;
/**
* @param array<string, mixed> $criteria
* @param null|array<string, string> $orderBy
*
* @return Prestataire[]
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
}
@@ -46,9 +46,10 @@ final readonly class ConvertProspectProcessor implements ProcessorInterface
}
$client = new Client();
$client->setName($prospect->getCompany() ?: (string) $prospect->getName());
$client->setName((string) $prospect->getCompany());
$client->setEmail($prospect->getEmail());
$client->setPhone($prospect->getPhone());
$client->setWebsite($prospect->getWebsite());
$this->entityManager->persist($client);
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Doctrine;
use App\Module\Directory\Domain\Entity\Prestataire;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Prestataire>
*/
final class DoctrinePrestataireRepository extends ServiceEntityRepository implements PrestataireRepositoryInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Prestataire::class);
}
public function findById(int $id): ?Prestataire
{
return $this->find($id);
}
}
@@ -42,9 +42,10 @@ class ConvertProspectTool
if (null === $prospect->getConvertedClient()) {
$client = new Client();
$client->setName($prospect->getCompany() ?: (string) $prospect->getName());
$client->setName((string) $prospect->getCompany());
$client->setEmail($prospect->getEmail());
$client->setPhone($prospect->getPhone());
$client->setWebsite($prospect->getWebsite());
$this->entityManager->persist($client);
@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Entity\Address;
use App\Module\Directory\Domain\Repository\ClientRepositoryInterface;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(
name: 'create-address',
description: 'Create an address (admin) attached to exactly one of clientId / prospectId / prestataireId. Country defaults to FR (ISO 3166 alpha-2).'
)]
class CreateAddressTool
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly ClientRepositoryInterface $clientRepository,
private readonly ProspectRepositoryInterface $prospectRepository,
private readonly PrestataireRepositoryInterface $prestataireRepository,
private readonly Security $security,
) {}
public function __invoke(
?int $clientId = null,
?int $prospectId = null,
?int $prestataireId = null,
?string $label = null,
?string $street = null,
?string $streetComplement = null,
?string $postalCode = null,
?string $city = null,
?string $country = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$parents = array_filter([$clientId, $prospectId, $prestataireId], static fn ($v) => null !== $v);
if (1 !== count($parents)) {
throw new InvalidArgumentException('Exactly one of clientId, prospectId or prestataireId must be provided.');
}
$address = new Address();
if (null !== $clientId) {
$client = $this->clientRepository->findById($clientId);
if (null === $client) {
throw new InvalidArgumentException(sprintf('Client with ID %d not found.', $clientId));
}
$address->setClient($client);
}
if (null !== $prospectId) {
$prospect = $this->prospectRepository->findById($prospectId);
if (null === $prospect) {
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $prospectId));
}
$address->setProspect($prospect);
}
if (null !== $prestataireId) {
$prestataire = $this->prestataireRepository->findById($prestataireId);
if (null === $prestataire) {
throw new InvalidArgumentException(sprintf('Prestataire with ID %d not found.', $prestataireId));
}
$address->setPrestataire($prestataire);
}
$address->setLabel($label);
$address->setStreet($street);
$address->setStreetComplement($streetComplement);
$address->setPostalCode($postalCode);
$address->setCity($city);
if (null !== $country) {
if (2 !== strlen($country)) {
throw new InvalidArgumentException('country must be a 2-letter ISO 3166 alpha-2 code (e.g., FR, BE).');
}
$address->setCountry(strtoupper($country));
}
$this->entityManager->persist($address);
$this->entityManager->flush();
return json_encode(Serializer::address($address));
}
}
@@ -23,6 +23,7 @@ class CreateClientTool
string $name,
?string $email = null,
?string $phone = null,
?string $website = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
@@ -32,6 +33,7 @@ class CreateClientTool
$client->setName($name);
$client->setEmail($email);
$client->setPhone($phone);
$client->setWebsite($website);
$this->entityManager->persist($client);
$this->entityManager->flush();
@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Entity\CommercialReport;
use App\Module\Directory\Domain\Enum\ReportType;
use App\Module\Directory\Domain\Repository\ClientRepositoryInterface;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(
name: 'create-commercial-report',
description: 'Create a commercial report (admin) attached to exactly one of clientId / prospectId / prestataireId. Type defaults to "note". Allowed types: note, call, meeting, email. Date defaults to today if omitted.'
)]
class CreateCommercialReportTool
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly ClientRepositoryInterface $clientRepository,
private readonly ProspectRepositoryInterface $prospectRepository,
private readonly PrestataireRepositoryInterface $prestataireRepository,
private readonly Security $security,
) {}
public function __invoke(
string $subject,
?int $clientId = null,
?int $prospectId = null,
?int $prestataireId = null,
?string $body = null,
?string $occurredAt = null,
?string $type = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$parents = array_filter([$clientId, $prospectId, $prestataireId], static fn ($v) => null !== $v);
if (1 !== count($parents)) {
throw new InvalidArgumentException('Exactly one of clientId, prospectId or prestataireId must be provided.');
}
$report = new CommercialReport();
$report->setSubject($subject);
$report->setBody($body);
if (null !== $clientId) {
$client = $this->clientRepository->findById($clientId);
if (null === $client) {
throw new InvalidArgumentException(sprintf('Client with ID %d not found.', $clientId));
}
$report->setClient($client);
}
if (null !== $prospectId) {
$prospect = $this->prospectRepository->findById($prospectId);
if (null === $prospect) {
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $prospectId));
}
$report->setProspect($prospect);
}
if (null !== $prestataireId) {
$prestataire = $this->prestataireRepository->findById($prestataireId);
if (null === $prestataire) {
throw new InvalidArgumentException(sprintf('Prestataire with ID %d not found.', $prestataireId));
}
$report->setPrestataire($prestataire);
}
try {
$date = null === $occurredAt
? new DateTimeImmutable('today')
: new DateTimeImmutable($occurredAt);
} catch (Exception $e) {
throw new InvalidArgumentException(sprintf('Invalid occurredAt "%s": %s', $occurredAt, $e->getMessage()));
}
$report->setOccurredAt($date);
if (null !== $type) {
$typeEnum = ReportType::tryFrom($type);
if (null === $typeEnum) {
throw new InvalidArgumentException(sprintf('Invalid type "%s". Allowed: note, call, meeting, email.', $type));
}
$report->setType($typeEnum);
}
$this->entityManager->persist($report);
$this->entityManager->flush();
return json_encode(Serializer::commercialReport($report));
}
}
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Entity\Contact;
use App\Module\Directory\Domain\Repository\ClientRepositoryInterface;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(
name: 'create-contact',
description: 'Create a contact (admin) attached to exactly one of clientId / prospectId / prestataireId. All fields except the parent are optional.'
)]
class CreateContactTool
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly ClientRepositoryInterface $clientRepository,
private readonly ProspectRepositoryInterface $prospectRepository,
private readonly PrestataireRepositoryInterface $prestataireRepository,
private readonly Security $security,
) {}
public function __invoke(
?int $clientId = null,
?int $prospectId = null,
?int $prestataireId = null,
?string $firstName = null,
?string $lastName = null,
?string $jobTitle = null,
?string $email = null,
?string $phonePrimary = null,
?string $phoneSecondary = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$parents = array_filter([$clientId, $prospectId, $prestataireId], static fn ($v) => null !== $v);
if (1 !== count($parents)) {
throw new InvalidArgumentException('Exactly one of clientId, prospectId or prestataireId must be provided.');
}
$contact = new Contact();
if (null !== $clientId) {
$client = $this->clientRepository->findById($clientId);
if (null === $client) {
throw new InvalidArgumentException(sprintf('Client with ID %d not found.', $clientId));
}
$contact->setClient($client);
}
if (null !== $prospectId) {
$prospect = $this->prospectRepository->findById($prospectId);
if (null === $prospect) {
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $prospectId));
}
$contact->setProspect($prospect);
}
if (null !== $prestataireId) {
$prestataire = $this->prestataireRepository->findById($prestataireId);
if (null === $prestataire) {
throw new InvalidArgumentException(sprintf('Prestataire with ID %d not found.', $prestataireId));
}
$contact->setPrestataire($prestataire);
}
$contact->setFirstName($firstName);
$contact->setLastName($lastName);
$contact->setJobTitle($jobTitle);
$contact->setEmail($email);
$contact->setPhonePrimary($phonePrimary);
$contact->setPhoneSecondary($phoneSecondary);
$this->entityManager->persist($contact);
$this->entityManager->flush();
return json_encode(Serializer::contact($contact));
}
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Entity\Prestataire;
use App\Shared\Infrastructure\Mcp\Serializer;
use Doctrine\ORM\EntityManagerInterface;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
#[McpTool(name: 'create-prestataire', description: 'Create a prestataire / service provider (admin). Only name is required.')]
class CreatePrestataireTool
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(
string $name,
?string $email = null,
?string $phone = null,
?string $website = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$prestataire = new Prestataire();
$prestataire->setName($name);
$prestataire->setEmail($email);
$prestataire->setPhone($phone);
$prestataire->setWebsite($website);
$this->entityManager->persist($prestataire);
$this->entityManager->flush();
return json_encode(Serializer::prestataire($prestataire));
}
}
@@ -15,7 +15,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'create-prospect', description: 'Create a prospect (admin). Only name is required. Status defaults to "new".')]
#[McpTool(name: 'create-prospect', description: 'Create a prospect (admin). Only company is required. Status defaults to "new".')]
class CreateProspectTool
{
public function __construct(
@@ -24,10 +24,10 @@ class CreateProspectTool
) {}
public function __invoke(
string $name,
?string $company = null,
string $company,
?string $email = null,
?string $phone = null,
?string $website = null,
?string $status = null,
?string $source = null,
?string $notes = null,
@@ -37,10 +37,10 @@ class CreateProspectTool
}
$prospect = new Prospect();
$prospect->setName($name);
$prospect->setCompany($company);
$prospect->setEmail($email);
$prospect->setPhone($phone);
$prospect->setWebsite($website);
$prospect->setSource($source);
$prospect->setNotes($notes);
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'delete-address', description: 'Delete an address (admin).')]
class DeleteAddressTool
{
public function __construct(
private readonly AddressRepositoryInterface $addressRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(int $id): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$address = $this->addressRepository->findById($id);
if (null === $address) {
throw new InvalidArgumentException(sprintf('Address with ID %d not found.', $id));
}
$this->entityManager->remove($address);
$this->entityManager->flush();
return json_encode(['success' => true, 'message' => sprintf('Address #%d deleted.', $id)]);
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'delete-commercial-report', description: 'Delete a commercial report (admin). Cascade removes its attached documents.')]
class DeleteCommercialReportTool
{
public function __construct(
private readonly CommercialReportRepositoryInterface $reportRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(int $id): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$report = $this->reportRepository->findById($id);
if (null === $report) {
throw new InvalidArgumentException(sprintf('CommercialReport with ID %d not found.', $id));
}
$this->entityManager->remove($report);
$this->entityManager->flush();
return json_encode(['success' => true, 'message' => sprintf('CommercialReport #%d deleted.', $id)]);
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'delete-contact', description: 'Delete a contact (admin).')]
class DeleteContactTool
{
public function __construct(
private readonly ContactRepositoryInterface $contactRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(int $id): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$contact = $this->contactRepository->findById($id);
if (null === $contact) {
throw new InvalidArgumentException(sprintf('Contact with ID %d not found.', $id));
}
$this->entityManager->remove($contact);
$this->entityManager->flush();
return json_encode(['success' => true, 'message' => sprintf('Contact #%d deleted.', $id)]);
}
}
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'delete-prestataire', description: 'Delete a prestataire (admin). Cascade removes its contacts, addresses and reports.')]
class DeletePrestataireTool
{
public function __construct(
private readonly PrestataireRepositoryInterface $prestataireRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(int $id): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$prestataire = $this->prestataireRepository->findById($id);
if (null === $prestataire) {
throw new InvalidArgumentException(sprintf('Prestataire with ID %d not found.', $id));
}
$name = $prestataire->getName();
$this->entityManager->remove($prestataire);
$this->entityManager->flush();
return json_encode(['success' => true, 'message' => sprintf('Prestataire "%s" deleted.', $name)]);
}
}
@@ -33,10 +33,10 @@ class DeleteProspectTool
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $id));
}
$name = $prospect->getName();
$company = $prospect->getCompany();
$this->entityManager->remove($prospect);
$this->entityManager->flush();
return json_encode(['success' => true, 'message' => sprintf('Prospect "%s" deleted.', $name)]);
return json_encode(['success' => true, 'message' => sprintf('Prospect "%s" deleted.', $company)]);
}
}
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'get-address', description: 'Get an address by ID.')]
class GetAddressTool
{
public function __construct(
private readonly AddressRepositoryInterface $addressRepository,
private readonly Security $security,
) {}
public function __invoke(int $id): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$address = $this->addressRepository->findById($id);
if (null === $address) {
throw new InvalidArgumentException(sprintf('Address with ID %d not found.', $id));
}
return json_encode(Serializer::address($address));
}
}
@@ -4,7 +4,10 @@ declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use App\Module\Directory\Domain\Repository\ClientRepositoryInterface;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
@@ -13,11 +16,14 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'get-client', description: 'Get a client by ID with full contact details.')]
#[McpTool(name: 'get-client', description: 'Get a client by ID, with its linked contacts, addresses, and commercial reports.')]
class GetClientTool
{
public function __construct(
private readonly ClientRepositoryInterface $clientRepository,
private readonly ContactRepositoryInterface $contactRepository,
private readonly AddressRepositoryInterface $addressRepository,
private readonly CommercialReportRepositoryInterface $reportRepository,
private readonly Security $security,
) {}
@@ -32,6 +38,20 @@ class GetClientTool
throw new InvalidArgumentException(sprintf('Client with ID %d not found.', $id));
}
return json_encode(Serializer::client($client));
$payload = Serializer::client($client);
$payload['contacts'] = array_map(
fn ($c) => Serializer::contact($c),
$this->contactRepository->findBy(['client' => $client], ['lastName' => 'ASC'])
);
$payload['addresses'] = array_map(
fn ($a) => Serializer::address($a),
$this->addressRepository->findBy(['client' => $client], ['id' => 'ASC'])
);
$payload['reports'] = array_map(
fn ($r) => Serializer::commercialReport($r),
$this->reportRepository->findBy(['client' => $client], ['occurredAt' => 'DESC'])
);
return json_encode($payload);
}
}
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'get-commercial-report', description: 'Get a commercial report by ID, including its attached documents.')]
class GetCommercialReportTool
{
public function __construct(
private readonly CommercialReportRepositoryInterface $reportRepository,
private readonly Security $security,
) {}
public function __invoke(int $id): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$report = $this->reportRepository->findById($id);
if (null === $report) {
throw new InvalidArgumentException(sprintf('CommercialReport with ID %d not found.', $id));
}
return json_encode(Serializer::commercialReport($report));
}
}
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'get-contact', description: 'Get a contact by ID.')]
class GetContactTool
{
public function __construct(
private readonly ContactRepositoryInterface $contactRepository,
private readonly Security $security,
) {}
public function __invoke(int $id): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$contact = $this->contactRepository->findById($id);
if (null === $contact) {
throw new InvalidArgumentException(sprintf('Contact with ID %d not found.', $id));
}
return json_encode(Serializer::contact($contact));
}
}
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'get-prestataire', description: 'Get a prestataire by ID, with its linked contacts, addresses, and commercial reports.')]
class GetPrestataireTool
{
public function __construct(
private readonly PrestataireRepositoryInterface $prestataireRepository,
private readonly ContactRepositoryInterface $contactRepository,
private readonly AddressRepositoryInterface $addressRepository,
private readonly CommercialReportRepositoryInterface $reportRepository,
private readonly Security $security,
) {}
public function __invoke(int $id): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$prestataire = $this->prestataireRepository->findById($id);
if (null === $prestataire) {
throw new InvalidArgumentException(sprintf('Prestataire with ID %d not found.', $id));
}
$payload = Serializer::prestataire($prestataire);
$payload['contacts'] = array_map(
fn ($c) => Serializer::contact($c),
$this->contactRepository->findBy(['prestataire' => $prestataire], ['lastName' => 'ASC'])
);
$payload['addresses'] = array_map(
fn ($a) => Serializer::address($a),
$this->addressRepository->findBy(['prestataire' => $prestataire], ['id' => 'ASC'])
);
$payload['reports'] = array_map(
fn ($r) => Serializer::commercialReport($r),
$this->reportRepository->findBy(['prestataire' => $prestataire], ['occurredAt' => 'DESC'])
);
return json_encode($payload);
}
}
@@ -4,6 +4,9 @@ declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
@@ -13,11 +16,14 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'get-prospect', description: 'Get a prospect by ID with full details.')]
#[McpTool(name: 'get-prospect', description: 'Get a prospect by ID, with its linked contacts, addresses, and commercial reports.')]
class GetProspectTool
{
public function __construct(
private readonly ProspectRepositoryInterface $prospectRepository,
private readonly ContactRepositoryInterface $contactRepository,
private readonly AddressRepositoryInterface $addressRepository,
private readonly CommercialReportRepositoryInterface $reportRepository,
private readonly Security $security,
) {}
@@ -32,6 +38,20 @@ class GetProspectTool
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $id));
}
return json_encode(Serializer::prospect($prospect));
$payload = Serializer::prospect($prospect);
$payload['contacts'] = array_map(
fn ($c) => Serializer::contact($c),
$this->contactRepository->findBy(['prospect' => $prospect], ['lastName' => 'ASC'])
);
$payload['addresses'] = array_map(
fn ($a) => Serializer::address($a),
$this->addressRepository->findBy(['prospect' => $prospect], ['id' => 'ASC'])
);
$payload['reports'] = array_map(
fn ($r) => Serializer::commercialReport($r),
$this->reportRepository->findBy(['prospect' => $prospect], ['occurredAt' => 'DESC'])
);
return json_encode($payload);
}
}
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
#[McpTool(
name: 'list-addresses',
description: 'List addresses, optionally filtered by parent (at most one of clientId / prospectId / prestataireId).'
)]
class ListAddressesTool
{
public function __construct(
private readonly AddressRepositoryInterface $addressRepository,
private readonly Security $security,
) {}
public function __invoke(
?int $clientId = null,
?int $prospectId = null,
?int $prestataireId = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$filters = array_filter([$clientId, $prospectId, $prestataireId], static fn ($v) => null !== $v);
if (count($filters) > 1) {
throw new InvalidArgumentException('At most one of clientId, prospectId or prestataireId can be provided.');
}
$criteria = [];
if (null !== $clientId) {
$criteria['client'] = $clientId;
}
if (null !== $prospectId) {
$criteria['prospect'] = $prospectId;
}
if (null !== $prestataireId) {
$criteria['prestataire'] = $prestataireId;
}
$addresses = $this->addressRepository->findBy($criteria, ['id' => 'ASC']);
return json_encode(array_map(fn ($a) => Serializer::address($a), $addresses));
}
}
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
#[McpTool(
name: 'list-commercial-reports',
description: 'List commercial reports, optionally filtered by parent (at most one of clientId / prospectId / prestataireId). Returns reports ordered by occurredAt DESC.'
)]
class ListCommercialReportsTool
{
public function __construct(
private readonly CommercialReportRepositoryInterface $reportRepository,
private readonly Security $security,
) {}
public function __invoke(
?int $clientId = null,
?int $prospectId = null,
?int $prestataireId = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$filters = array_filter([$clientId, $prospectId, $prestataireId], static fn ($v) => null !== $v);
if (count($filters) > 1) {
throw new InvalidArgumentException('At most one of clientId, prospectId or prestataireId can be provided.');
}
$criteria = [];
if (null !== $clientId) {
$criteria['client'] = $clientId;
}
if (null !== $prospectId) {
$criteria['prospect'] = $prospectId;
}
if (null !== $prestataireId) {
$criteria['prestataire'] = $prestataireId;
}
$reports = $this->reportRepository->findBy($criteria, ['occurredAt' => 'DESC']);
return json_encode(array_map(fn ($r) => Serializer::commercialReport($r), $reports));
}
}
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
#[McpTool(
name: 'list-contacts',
description: 'List contacts, optionally filtered by parent (at most one of clientId / prospectId / prestataireId).'
)]
class ListContactsTool
{
public function __construct(
private readonly ContactRepositoryInterface $contactRepository,
private readonly Security $security,
) {}
public function __invoke(
?int $clientId = null,
?int $prospectId = null,
?int $prestataireId = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$filters = array_filter([$clientId, $prospectId, $prestataireId], static fn ($v) => null !== $v);
if (count($filters) > 1) {
throw new InvalidArgumentException('At most one of clientId, prospectId or prestataireId can be provided.');
}
$criteria = [];
if (null !== $clientId) {
$criteria['client'] = $clientId;
}
if (null !== $prospectId) {
$criteria['prospect'] = $prospectId;
}
if (null !== $prestataireId) {
$criteria['prestataire'] = $prestataireId;
}
$contacts = $this->contactRepository->findBy($criteria, ['lastName' => 'ASC']);
return json_encode(array_map(fn ($c) => Serializer::contact($c), $contacts));
}
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
#[McpTool(name: 'list-prestataires', description: 'List all prestataires with their IDs, names, and emails. Use this to discover valid prestataire IDs.')]
class ListPrestatairesTool
{
public function __construct(
private readonly PrestataireRepositoryInterface $prestataireRepository,
private readonly Security $security,
) {}
public function __invoke(): string
{
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$prestataires = $this->prestataireRepository->findBy([], ['name' => 'ASC']);
return json_encode(array_map(fn ($p) => [
'id' => $p->getId(),
'name' => $p->getName(),
'email' => $p->getEmail(),
], $prestataires));
}
}
@@ -37,7 +37,7 @@ class ListProspectsTool
$criteria['status'] = $statusEnum;
}
$prospects = $this->prospectRepository->findBy($criteria, ['name' => 'ASC']);
$prospects = $this->prospectRepository->findBy($criteria, ['company' => 'ASC']);
return json_encode(array_map(static fn ($prospect) => Serializer::prospect($prospect), $prospects));
}
@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(
name: 'update-address',
description: 'Update an address (admin). Only provided fields change. Parent (client/prospect/prestataire) is immutable.'
)]
class UpdateAddressTool
{
public function __construct(
private readonly AddressRepositoryInterface $addressRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(
int $id,
?string $label = null,
?string $street = null,
?string $streetComplement = null,
?string $postalCode = null,
?string $city = null,
?string $country = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$address = $this->addressRepository->findById($id);
if (null === $address) {
throw new InvalidArgumentException(sprintf('Address with ID %d not found.', $id));
}
if (null !== $label) {
$address->setLabel($label);
}
if (null !== $street) {
$address->setStreet($street);
}
if (null !== $streetComplement) {
$address->setStreetComplement($streetComplement);
}
if (null !== $postalCode) {
$address->setPostalCode($postalCode);
}
if (null !== $city) {
$address->setCity($city);
}
if (null !== $country) {
if (2 !== strlen($country)) {
throw new InvalidArgumentException('country must be a 2-letter ISO 3166 alpha-2 code (e.g., FR, BE).');
}
$address->setCountry(strtoupper($country));
}
$this->entityManager->flush();
return json_encode(Serializer::address($address));
}
}
@@ -28,6 +28,7 @@ class UpdateClientTool
?string $name = null,
?string $email = null,
?string $phone = null,
?string $website = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
@@ -47,6 +48,9 @@ class UpdateClientTool
if (null !== $phone) {
$client->setPhone($phone);
}
if (null !== $website) {
$client->setWebsite($website);
}
$this->entityManager->flush();
@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Enum\ReportType;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(
name: 'update-commercial-report',
description: 'Update a commercial report (admin). Only provided fields change. Parent (client/prospect/prestataire) is immutable.'
)]
class UpdateCommercialReportTool
{
public function __construct(
private readonly CommercialReportRepositoryInterface $reportRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(
int $id,
?string $subject = null,
?string $body = null,
?string $occurredAt = null,
?string $type = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$report = $this->reportRepository->findById($id);
if (null === $report) {
throw new InvalidArgumentException(sprintf('CommercialReport with ID %d not found.', $id));
}
if (null !== $subject) {
$report->setSubject($subject);
}
if (null !== $body) {
$report->setBody($body);
}
if (null !== $occurredAt) {
try {
$report->setOccurredAt(new DateTimeImmutable($occurredAt));
} catch (Exception $e) {
throw new InvalidArgumentException(sprintf('Invalid occurredAt "%s": %s', $occurredAt, $e->getMessage()));
}
}
if (null !== $type) {
$typeEnum = ReportType::tryFrom($type);
if (null === $typeEnum) {
throw new InvalidArgumentException(sprintf('Invalid type "%s". Allowed: note, call, meeting, email.', $type));
}
$report->setType($typeEnum);
}
$this->entityManager->flush();
return json_encode(Serializer::commercialReport($report));
}
}
@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(
name: 'update-contact',
description: 'Update a contact (admin). Only provided fields change. The parent (client/prospect/prestataire) is immutable — delete then recreate to re-attach.'
)]
class UpdateContactTool
{
public function __construct(
private readonly ContactRepositoryInterface $contactRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(
int $id,
?string $firstName = null,
?string $lastName = null,
?string $jobTitle = null,
?string $email = null,
?string $phonePrimary = null,
?string $phoneSecondary = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$contact = $this->contactRepository->findById($id);
if (null === $contact) {
throw new InvalidArgumentException(sprintf('Contact with ID %d not found.', $id));
}
if (null !== $firstName) {
$contact->setFirstName($firstName);
}
if (null !== $lastName) {
$contact->setLastName($lastName);
}
if (null !== $jobTitle) {
$contact->setJobTitle($jobTitle);
}
if (null !== $email) {
$contact->setEmail($email);
}
if (null !== $phonePrimary) {
$contact->setPhonePrimary($phonePrimary);
}
if (null !== $phoneSecondary) {
$contact->setPhoneSecondary($phoneSecondary);
}
$this->entityManager->flush();
return json_encode(Serializer::contact($contact));
}
}
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Shared\Infrastructure\Mcp\Serializer;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Mcp\Capability\Attribute\McpTool;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use function sprintf;
#[McpTool(name: 'update-prestataire', description: 'Update a prestataire (admin). Only provided fields change.')]
class UpdatePrestataireTool
{
public function __construct(
private readonly PrestataireRepositoryInterface $prestataireRepository,
private readonly EntityManagerInterface $entityManager,
private readonly Security $security,
) {}
public function __invoke(
int $id,
?string $name = null,
?string $email = null,
?string $phone = null,
?string $website = null,
): string {
if (!$this->security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
}
$prestataire = $this->prestataireRepository->findById($id);
if (null === $prestataire) {
throw new InvalidArgumentException(sprintf('Prestataire with ID %d not found.', $id));
}
if (null !== $name) {
$prestataire->setName($name);
}
if (null !== $email) {
$prestataire->setEmail($email);
}
if (null !== $phone) {
$prestataire->setPhone($phone);
}
if (null !== $website) {
$prestataire->setWebsite($website);
}
$this->entityManager->flush();
return json_encode(Serializer::prestataire($prestataire));
}
}
@@ -26,10 +26,10 @@ class UpdateProspectTool
public function __invoke(
int $id,
?string $name = null,
?string $company = null,
?string $email = null,
?string $phone = null,
?string $website = null,
?string $status = null,
?string $source = null,
?string $notes = null,
@@ -43,9 +43,6 @@ class UpdateProspectTool
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $id));
}
if (null !== $name) {
$prospect->setName($name);
}
if (null !== $company) {
$prospect->setCompany($company);
}
@@ -55,6 +52,9 @@ class UpdateProspectTool
if (null !== $phone) {
$prospect->setPhone($phone);
}
if (null !== $website) {
$prospect->setWebsite($website);
}
if (null !== $status) {
$statusEnum = ProspectStatus::tryFrom($status);
if (null === $statusEnum) {
+103 -5
View File
@@ -8,8 +8,13 @@ use App\Module\Absence\Domain\Entity\AbsenceBalance;
use App\Module\Absence\Domain\Entity\AbsencePolicy;
use App\Module\Absence\Domain\Entity\AbsenceRequest;
use App\Module\Core\Domain\Entity\User;
use App\Module\Directory\Domain\Entity\Address;
use App\Module\Directory\Domain\Entity\Client;
use App\Module\Directory\Domain\Entity\CommercialReport;
use App\Module\Directory\Domain\Entity\Contact;
use App\Module\Directory\Domain\Entity\Prestataire;
use App\Module\Directory\Domain\Entity\Prospect;
use App\Module\Directory\Domain\Entity\ReportDocument;
use App\Module\ProjectManagement\Domain\Entity\Project;
use App\Module\ProjectManagement\Domain\Entity\TaskDocument;
use App\Module\ProjectManagement\Domain\Entity\TaskEffort;
@@ -366,10 +371,103 @@ final class Serializer
public static function client(Client $c): array
{
return [
'id' => $c->getId(),
'name' => $c->getName(),
'email' => $c->getEmail(),
'phone' => $c->getPhone(),
'id' => $c->getId(),
'name' => $c->getName(),
'email' => $c->getEmail(),
'phone' => $c->getPhone(),
'website' => $c->getWebsite(),
];
}
/**
* @return array<string, mixed>
*/
public static function prestataire(Prestataire $p): array
{
return [
'id' => $p->getId(),
'name' => $p->getName(),
'email' => $p->getEmail(),
'phone' => $p->getPhone(),
'website' => $p->getWebsite(),
];
}
/**
* @return array<string, mixed>
*/
public static function contact(Contact $c): array
{
return [
'id' => $c->getId(),
'firstName' => $c->getFirstName(),
'lastName' => $c->getLastName(),
'jobTitle' => $c->getJobTitle(),
'email' => $c->getEmail(),
'phonePrimary' => $c->getPhonePrimary(),
'phoneSecondary' => $c->getPhoneSecondary(),
'clientId' => $c->getClient()?->getId(),
'prospectId' => $c->getProspect()?->getId(),
'prestataireId' => $c->getPrestataire()?->getId(),
];
}
/**
* @return array<string, mixed>
*/
public static function address(Address $a): array
{
return [
'id' => $a->getId(),
'label' => $a->getLabel(),
'street' => $a->getStreet(),
'streetComplement' => $a->getStreetComplement(),
'postalCode' => $a->getPostalCode(),
'city' => $a->getCity(),
'country' => $a->getCountry(),
'clientId' => $a->getClient()?->getId(),
'prospectId' => $a->getProspect()?->getId(),
'prestataireId' => $a->getPrestataire()?->getId(),
];
}
/**
* @return array<string, mixed>
*/
public static function reportDocument(ReportDocument $d): array
{
return [
'id' => $d->getId(),
'originalName' => $d->getOriginalName(),
'mimeType' => $d->getMimeType(),
'size' => $d->getSize(),
'createdAt' => $d->getCreatedAt()?->format('c'),
'uploadedBy' => self::user($d->getUploadedBy()),
];
}
/**
* @return array<string, mixed>
*/
public static function commercialReport(CommercialReport $r): array
{
return [
'id' => $r->getId(),
'subject' => $r->getSubject(),
'body' => $r->getBody(),
'occurredAt' => $r->getOccurredAt()?->format('Y-m-d'),
'type' => $r->getType()->value,
'typeLabel' => $r->getType()->label(),
'author' => self::user($r->getAuthor()),
'clientId' => $r->getClient()?->getId(),
'prospectId' => $r->getProspect()?->getId(),
'prestataireId' => $r->getPrestataire()?->getId(),
'documents' => array_map(
fn (ReportDocument $d) => self::reportDocument($d),
$r->getDocuments()->toArray()
),
'createdAt' => $r->getCreatedAt()?->format('c'),
'updatedAt' => $r->getUpdatedAt()?->format('c'),
];
}
@@ -382,10 +480,10 @@ final class Serializer
return [
'id' => $p->getId(),
'name' => $p->getName(),
'company' => $p->getCompany(),
'email' => $p->getEmail(),
'phone' => $p->getPhone(),
'website' => $p->getWebsite(),
'status' => $p->getStatus()->value,
'statusLabel' => $p->getStatus()->label(),
'source' => $p->getSource(),
@@ -0,0 +1,229 @@
<?php
declare(strict_types=1);
namespace App\Tests\Functional\Mcp\Directory;
use App\Module\Core\Domain\Entity\User;
use App\Module\Directory\Domain\Entity\Client;
use App\Module\Directory\Domain\Entity\Prestataire;
use App\Module\Directory\Domain\Entity\Prospect;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use App\Module\Directory\Domain\Repository\ClientRepositoryInterface;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
use App\Module\Directory\Infrastructure\Mcp\Tool\CreateAddressTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\DeleteAddressTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\GetAddressTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\ListAddressesTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\UpdateAddressTool;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\SecurityBundle\Security;
/**
* @internal
*/
class AddressLifecycleTest extends KernelTestCase
{
private EntityManagerInterface $em;
private User $admin;
private Client $client;
private Prospect $prospect;
private Prestataire $prestataire;
protected function setUp(): void
{
self::bootKernel();
$this->em = self::getContainer()->get(EntityManagerInterface::class);
$this->admin = new User();
$this->admin->setUsername('mcp-address-admin-'.uniqid());
$this->admin->setPassword('x');
$this->admin->setRoles(['ROLE_ADMIN']);
$this->em->persist($this->admin);
$this->client = new Client();
$this->client->setName('Test Client '.uniqid());
$this->em->persist($this->client);
$this->prospect = new Prospect();
$this->prospect->setCompany('Test Prospect '.uniqid());
$this->em->persist($this->prospect);
$this->prestataire = new Prestataire();
$this->prestataire->setName('Test Prestataire '.uniqid());
$this->em->persist($this->prestataire);
$this->em->flush();
}
public function testCreateRequiresExactlyOneParent(): void
{
try {
($this->createTool())(null, null, null, 'Home');
self::fail('Expected error when no parent provided.');
} catch (InvalidArgumentException $e) {
self::assertStringContainsString('Exactly one of clientId, prospectId or prestataireId', $e->getMessage());
}
try {
($this->createTool())($this->client->getId(), null, $this->prestataire->getId(), 'Dup');
self::fail('Expected error when two parents provided.');
} catch (InvalidArgumentException $e) {
self::assertStringContainsString('Exactly one of clientId, prospectId or prestataireId', $e->getMessage());
}
}
public function testCreateCountryDefaultsToFRWhenOmitted(): void
{
$data = json_decode(($this->createTool())($this->client->getId(), null, null, 'HQ'), true);
self::assertSame('FR', $data['country']);
}
public function testCreateRejectsNonIso3166Country(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('country must be a 2-letter ISO 3166 alpha-2 code');
($this->createTool())($this->client->getId(), null, null, 'HQ', null, null, null, null, 'France');
}
public function testCreateNormalizesCountryToUppercase(): void
{
$data = json_decode(($this->createTool())($this->client->getId(), null, null, 'HQ', null, null, null, null, 'be'), true);
self::assertSame('BE', $data['country']);
}
public function testCreateOnEachParentWorks(): void
{
$clientAddr = json_decode(($this->createTool())($this->client->getId(), null, null, 'CHQ'), true);
self::assertSame($this->client->getId(), $clientAddr['clientId']);
self::assertNull($clientAddr['prospectId']);
$prospectAddr = json_decode(($this->createTool())(null, $this->prospect->getId(), null, 'PHQ'), true);
self::assertSame($this->prospect->getId(), $prospectAddr['prospectId']);
$prestAddr = json_decode(($this->createTool())(null, null, $this->prestataire->getId(), 'XHQ'), true);
self::assertSame($this->prestataire->getId(), $prestAddr['prestataireId']);
}
public function testGetReturnsAddress(): void
{
$created = json_decode(($this->createTool())($this->client->getId(), null, null, 'Office', '1 rue X', null, '75001', 'Paris', 'FR'), true);
$data = json_decode(($this->getTool())((int) $created['id']), true);
self::assertSame('Office', $data['label']);
self::assertSame('1 rue X', $data['street']);
self::assertSame('75001', $data['postalCode']);
self::assertSame('Paris', $data['city']);
self::assertSame('FR', $data['country']);
}
public function testListFilteredByClient(): void
{
($this->createTool())($this->client->getId(), null, null, 'A');
($this->createTool())($this->client->getId(), null, null, 'B');
($this->createTool())(null, null, $this->prestataire->getId(), 'Z');
$data = json_decode(($this->listTool())($this->client->getId(), null, null), true);
self::assertCount(2, $data);
self::assertSame('A', $data[0]['label']);
self::assertSame('B', $data[1]['label']);
}
public function testUpdateRejectsNonIso3166Country(): void
{
$created = json_decode(($this->createTool())($this->client->getId(), null, null, 'X'), true);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('country must be a 2-letter ISO 3166 alpha-2 code');
($this->updateTool())((int) $created['id'], null, null, null, null, null, 'Belgium');
}
public function testUpdateOnlyTouchesProvidedFields(): void
{
$created = json_decode(($this->createTool())($this->client->getId(), null, null, 'Old', '1 rue X', null, '75001', 'Paris', 'FR'), true);
$data = json_decode(($this->updateTool())((int) $created['id'], 'New', null, null, '75002', null, 'be'), true);
self::assertSame('New', $data['label']); // changed
self::assertSame('1 rue X', $data['street']); // unchanged
self::assertSame('75002', $data['postalCode']); // changed
self::assertSame('Paris', $data['city']); // unchanged
self::assertSame('BE', $data['country']); // changed + uppercased
}
public function testDeleteRemovesAddress(): void
{
$created = json_decode(($this->createTool())($this->client->getId(), null, null, 'Bye'), true);
$id = (int) $created['id'];
$data = json_decode(($this->deleteTool())($id), true);
self::assertTrue($data['success']);
$this->em->clear();
self::assertNull(self::getContainer()->get(AddressRepositoryInterface::class)->findById($id));
}
private function securityFor(bool $admin = true): Security
{
$security = $this->createMock(Security::class);
$security->method('isGranted')->willReturn($admin);
$security->method('getUser')->willReturn($admin ? $this->admin : null);
return $security;
}
private function createTool(): CreateAddressTool
{
$c = self::getContainer();
return new CreateAddressTool(
$this->em,
$c->get(ClientRepositoryInterface::class),
$c->get(ProspectRepositoryInterface::class),
$c->get(PrestataireRepositoryInterface::class),
$this->securityFor(),
);
}
private function getTool(): GetAddressTool
{
return new GetAddressTool(
self::getContainer()->get(AddressRepositoryInterface::class),
$this->securityFor(),
);
}
private function listTool(): ListAddressesTool
{
return new ListAddressesTool(
self::getContainer()->get(AddressRepositoryInterface::class),
$this->securityFor(),
);
}
private function updateTool(): UpdateAddressTool
{
return new UpdateAddressTool(
self::getContainer()->get(AddressRepositoryInterface::class),
$this->em,
$this->securityFor(),
);
}
private function deleteTool(): DeleteAddressTool
{
return new DeleteAddressTool(
self::getContainer()->get(AddressRepositoryInterface::class),
$this->em,
$this->securityFor(),
);
}
}
@@ -0,0 +1,265 @@
<?php
declare(strict_types=1);
namespace App\Tests\Functional\Mcp\Directory;
use App\Module\Core\Domain\Entity\User;
use App\Module\Directory\Domain\Entity\Client;
use App\Module\Directory\Domain\Entity\Prestataire;
use App\Module\Directory\Domain\Entity\Prospect;
use App\Module\Directory\Domain\Enum\ReportType;
use App\Module\Directory\Domain\Repository\ClientRepositoryInterface;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
use App\Module\Directory\Infrastructure\Mcp\Tool\CreateCommercialReportTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\DeleteCommercialReportTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\GetCommercialReportTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\ListCommercialReportsTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\UpdateCommercialReportTool;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
/**
* @internal
*/
class CommercialReportLifecycleTest extends KernelTestCase
{
private EntityManagerInterface $em;
private User $admin;
private Client $client;
private Prospect $prospect;
private Prestataire $prestataire;
protected function setUp(): void
{
self::bootKernel();
$this->em = self::getContainer()->get(EntityManagerInterface::class);
$this->admin = new User();
$this->admin->setUsername('mcp-report-admin-'.uniqid());
$this->admin->setPassword('x');
$this->admin->setRoles(['ROLE_ADMIN']);
$this->em->persist($this->admin);
$this->client = new Client();
$this->client->setName('Test Client '.uniqid());
$this->em->persist($this->client);
$this->prospect = new Prospect();
$this->prospect->setCompany('Test Prospect '.uniqid());
$this->em->persist($this->prospect);
$this->prestataire = new Prestataire();
$this->prestataire->setName('Test Prestataire '.uniqid());
$this->em->persist($this->prestataire);
$this->em->flush();
}
public function testCreateRequiresExactlyOneParent(): void
{
try {
($this->createTool())('subject', null, null, null);
self::fail('Expected error when no parent provided.');
} catch (InvalidArgumentException $e) {
self::assertStringContainsString('Exactly one of clientId, prospectId or prestataireId', $e->getMessage());
}
try {
($this->createTool())('subject', $this->client->getId(), null, $this->prestataire->getId());
self::fail('Expected error when two parents provided.');
} catch (InvalidArgumentException $e) {
self::assertStringContainsString('Exactly one of clientId, prospectId or prestataireId', $e->getMessage());
}
}
public function testCreateRejectsInvalidType(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid type "lunch". Allowed: note, call, meeting, email.');
($this->createTool())('Lunch at noon', $this->client->getId(), null, null, null, null, 'lunch');
}
public function testCreateAcceptsAllValidTypes(): void
{
foreach (['note', 'call', 'meeting', 'email'] as $type) {
$data = json_decode(
($this->createTool())('subject', $this->client->getId(), null, null, null, '2026-01-15', $type),
true,
);
self::assertSame($type, $data['type']);
}
}
public function testCreateDefaultsTypeToNote(): void
{
$data = json_decode(($this->createTool())('subject', $this->client->getId(), null, null), true);
self::assertSame(ReportType::Note->value, $data['type']);
}
public function testCreateRejectsInvalidDate(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid occurredAt "not-a-date"');
($this->createTool())('subject', $this->client->getId(), null, null, null, 'not-a-date');
}
public function testCreateDefaultsOccurredAtToToday(): void
{
$data = json_decode(($this->createTool())('subject', $this->client->getId(), null, null), true);
self::assertSame(new DateTimeImmutable('today')->format('Y-m-d'), $data['occurredAt']);
}
public function testCreateAutoFillsAuthorFromCurrentUser(): void
{
$this->loginAdmin();
$data = json_decode(($this->createTool())('subject', $this->client->getId(), null, null), true);
self::assertNotNull($data['author']);
self::assertSame($this->admin->getId(), $data['author']['id']);
self::assertSame($this->admin->getUsername(), $data['author']['username']);
}
public function testGetReturnsReport(): void
{
$created = json_decode(
($this->createTool())('My subject', $this->prestataire->getId() ? null : null, null, $this->prestataire->getId(), 'body text', '2026-03-01', 'meeting'),
true,
);
$data = json_decode(($this->getTool())((int) $created['id']), true);
self::assertSame('My subject', $data['subject']);
self::assertSame('body text', $data['body']);
self::assertSame('2026-03-01', $data['occurredAt']);
self::assertSame('meeting', $data['type']);
self::assertSame($this->prestataire->getId(), $data['prestataireId']);
self::assertSame([], $data['documents']);
}
public function testListOrderedByOccurredAtDesc(): void
{
($this->createTool())('oldest', $this->client->getId(), null, null, null, '2026-01-01');
($this->createTool())('newest', $this->client->getId(), null, null, null, '2026-12-01');
($this->createTool())('middle', $this->client->getId(), null, null, null, '2026-06-15');
$data = json_decode(($this->listTool())($this->client->getId(), null, null), true);
self::assertCount(3, $data);
self::assertSame('newest', $data[0]['subject']);
self::assertSame('middle', $data[1]['subject']);
self::assertSame('oldest', $data[2]['subject']);
}
public function testListRejectsMultipleFilters(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('At most one of clientId, prospectId or prestataireId');
($this->listTool())($this->client->getId(), $this->prospect->getId(), null);
}
public function testUpdateChangesTypeAndDate(): void
{
$created = json_decode(($this->createTool())('s', $this->client->getId(), null, null, null, '2026-01-01', 'note'), true);
$data = json_decode(($this->updateTool())((int) $created['id'], 'new subject', null, '2026-02-02', 'call'), true);
self::assertSame('new subject', $data['subject']);
self::assertSame('2026-02-02', $data['occurredAt']);
self::assertSame('call', $data['type']);
}
public function testUpdateRejectsInvalidType(): void
{
$created = json_decode(($this->createTool())('s', $this->client->getId(), null, null), true);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid type "lunch"');
($this->updateTool())((int) $created['id'], null, null, null, 'lunch');
}
public function testDeleteRemovesReport(): void
{
$created = json_decode(($this->createTool())('Bye', $this->client->getId(), null, null), true);
$id = (int) $created['id'];
$data = json_decode(($this->deleteTool())($id), true);
self::assertTrue($data['success']);
$this->em->clear();
self::assertNull(self::getContainer()->get(CommercialReportRepositoryInterface::class)->findById($id));
}
private function loginAdmin(): void
{
$token = new UsernamePasswordToken($this->admin, 'main', $this->admin->getRoles());
self::getContainer()->get(TokenStorageInterface::class)->setToken($token);
}
private function securityFor(bool $admin = true): Security
{
$security = $this->createMock(Security::class);
$security->method('isGranted')->willReturn($admin);
$security->method('getUser')->willReturn($admin ? $this->admin : null);
return $security;
}
private function createTool(): CreateCommercialReportTool
{
$c = self::getContainer();
return new CreateCommercialReportTool(
$this->em,
$c->get(ClientRepositoryInterface::class),
$c->get(ProspectRepositoryInterface::class),
$c->get(PrestataireRepositoryInterface::class),
$this->securityFor(),
);
}
private function getTool(): GetCommercialReportTool
{
return new GetCommercialReportTool(
self::getContainer()->get(CommercialReportRepositoryInterface::class),
$this->securityFor(),
);
}
private function listTool(): ListCommercialReportsTool
{
return new ListCommercialReportsTool(
self::getContainer()->get(CommercialReportRepositoryInterface::class),
$this->securityFor(),
);
}
private function updateTool(): UpdateCommercialReportTool
{
return new UpdateCommercialReportTool(
self::getContainer()->get(CommercialReportRepositoryInterface::class),
$this->em,
$this->securityFor(),
);
}
private function deleteTool(): DeleteCommercialReportTool
{
return new DeleteCommercialReportTool(
self::getContainer()->get(CommercialReportRepositoryInterface::class),
$this->em,
$this->securityFor(),
);
}
}
@@ -0,0 +1,216 @@
<?php
declare(strict_types=1);
namespace App\Tests\Functional\Mcp\Directory;
use App\Module\Core\Domain\Entity\User;
use App\Module\Directory\Domain\Entity\Client;
use App\Module\Directory\Domain\Entity\Prestataire;
use App\Module\Directory\Domain\Entity\Prospect;
use App\Module\Directory\Domain\Repository\ClientRepositoryInterface;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
use App\Module\Directory\Infrastructure\Mcp\Tool\CreateContactTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\DeleteContactTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\GetContactTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\ListContactsTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\UpdateContactTool;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\SecurityBundle\Security;
/**
* @internal
*/
class ContactLifecycleTest extends KernelTestCase
{
private EntityManagerInterface $em;
private User $admin;
private Client $client;
private Prospect $prospect;
private Prestataire $prestataire;
protected function setUp(): void
{
self::bootKernel();
$this->em = self::getContainer()->get(EntityManagerInterface::class);
$this->admin = new User();
$this->admin->setUsername('mcp-contact-admin-'.uniqid());
$this->admin->setPassword('x');
$this->admin->setRoles(['ROLE_ADMIN']);
$this->em->persist($this->admin);
$this->client = new Client();
$this->client->setName('Test Client '.uniqid());
$this->em->persist($this->client);
$this->prospect = new Prospect();
$this->prospect->setCompany('Test Prospect '.uniqid());
$this->em->persist($this->prospect);
$this->prestataire = new Prestataire();
$this->prestataire->setName('Test Prestataire '.uniqid());
$this->em->persist($this->prestataire);
$this->em->flush();
}
public function testCreateRequiresExactlyOneParent(): void
{
try {
($this->createTool())(null, null, null, 'Anon');
self::fail('Expected error when no parent provided.');
} catch (InvalidArgumentException $e) {
self::assertStringContainsString('Exactly one of clientId, prospectId or prestataireId', $e->getMessage());
}
try {
($this->createTool())($this->client->getId(), $this->prospect->getId(), null, 'Dup');
self::fail('Expected error when two parents provided.');
} catch (InvalidArgumentException $e) {
self::assertStringContainsString('Exactly one of clientId, prospectId or prestataireId', $e->getMessage());
}
}
public function testCreateWithUnknownClientThrows(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Client with ID 999999 not found.');
($this->createTool())(999999, null, null, 'Anon');
}
public function testCreateOnEachParentWorks(): void
{
foreach (
[
['clientId', $this->client->getId()],
['prospectId', $this->prospect->getId()],
['prestataireId', $this->prestataire->getId()],
] as [$field, $id]
) {
$args = [null, null, null, 'John', 'Doe-'.$field, 'CTO', 'john@x.test'];
$idx = ['clientId' => 0, 'prospectId' => 1, 'prestataireId' => 2][$field];
$args[$idx] = $id;
$data = json_decode(($this->createTool())(...$args), true);
self::assertSame('Doe-'.$field, $data['lastName']);
self::assertSame($id, $data[$field]);
}
}
public function testGetReturnsContact(): void
{
$created = json_decode(($this->createTool())($this->client->getId(), null, null, 'Jane', 'Smith'), true);
$data = json_decode(($this->getTool())((int) $created['id']), true);
self::assertSame('Jane', $data['firstName']);
self::assertSame('Smith', $data['lastName']);
self::assertSame($this->client->getId(), $data['clientId']);
}
public function testListFilteredByPrestataire(): void
{
($this->createTool())(null, null, $this->prestataire->getId(), 'A', 'A-Last');
($this->createTool())(null, null, $this->prestataire->getId(), 'B', 'B-Last');
($this->createTool())($this->client->getId(), null, null, 'Z', 'Z-Last');
$data = json_decode(($this->listTool())(null, null, $this->prestataire->getId()), true);
self::assertCount(2, $data);
self::assertSame('A-Last', $data[0]['lastName']);
self::assertSame('B-Last', $data[1]['lastName']);
}
public function testListRejectsMultipleFilters(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('At most one of clientId, prospectId or prestataireId');
($this->listTool())($this->client->getId(), $this->prospect->getId(), null);
}
public function testUpdateOnlyTouchesProvidedFields(): void
{
$created = json_decode(($this->createTool())(null, null, $this->prestataire->getId(), 'Old', 'Last', 'CTO', 'old@x.test'), true);
$data = json_decode(($this->updateTool())((int) $created['id'], 'New', null, null, 'new@x.test'), true);
self::assertSame('New', $data['firstName']); // changed
self::assertSame('Last', $data['lastName']); // unchanged
self::assertSame('CTO', $data['jobTitle']); // unchanged
self::assertSame('new@x.test', $data['email']); // changed
}
public function testDeleteRemovesContact(): void
{
$created = json_decode(($this->createTool())($this->client->getId(), null, null, 'Bye'), true);
$id = (int) $created['id'];
$data = json_decode(($this->deleteTool())($id), true);
self::assertTrue($data['success']);
$this->em->clear();
self::assertNull(self::getContainer()->get(ContactRepositoryInterface::class)->findById($id));
}
private function securityFor(bool $admin = true): Security
{
$security = $this->createMock(Security::class);
$security->method('isGranted')->willReturn($admin);
$security->method('getUser')->willReturn($admin ? $this->admin : null);
return $security;
}
private function createTool(): CreateContactTool
{
$c = self::getContainer();
return new CreateContactTool(
$this->em,
$c->get(ClientRepositoryInterface::class),
$c->get(ProspectRepositoryInterface::class),
$c->get(PrestataireRepositoryInterface::class),
$this->securityFor(),
);
}
private function getTool(): GetContactTool
{
return new GetContactTool(
self::getContainer()->get(ContactRepositoryInterface::class),
$this->securityFor(),
);
}
private function listTool(): ListContactsTool
{
return new ListContactsTool(
self::getContainer()->get(ContactRepositoryInterface::class),
$this->securityFor(),
);
}
private function updateTool(): UpdateContactTool
{
return new UpdateContactTool(
self::getContainer()->get(ContactRepositoryInterface::class),
$this->em,
$this->securityFor(),
);
}
private function deleteTool(): DeleteContactTool
{
return new DeleteContactTool(
self::getContainer()->get(ContactRepositoryInterface::class),
$this->em,
$this->securityFor(),
);
}
}
@@ -0,0 +1,183 @@
<?php
declare(strict_types=1);
namespace App\Tests\Functional\Mcp\Directory;
use App\Module\Core\Domain\Entity\User;
use App\Module\Directory\Domain\Repository\AddressRepositoryInterface;
use App\Module\Directory\Domain\Repository\CommercialReportRepositoryInterface;
use App\Module\Directory\Domain\Repository\ContactRepositoryInterface;
use App\Module\Directory\Domain\Repository\PrestataireRepositoryInterface;
use App\Module\Directory\Infrastructure\Mcp\Tool\CreatePrestataireTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\DeletePrestataireTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\GetPrestataireTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\ListPrestatairesTool;
use App\Module\Directory\Infrastructure\Mcp\Tool\UpdatePrestataireTool;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* @internal
*/
class PrestataireLifecycleTest extends KernelTestCase
{
private EntityManagerInterface $em;
private User $admin;
protected function setUp(): void
{
self::bootKernel();
$this->em = self::getContainer()->get(EntityManagerInterface::class);
$this->admin = new User();
$this->admin->setUsername('mcp-prest-admin-'.uniqid());
$this->admin->setPassword('x');
$this->admin->setRoles(['ROLE_ADMIN']);
$this->em->persist($this->admin);
$this->em->flush();
}
public function testCreatePersistsAllFields(): void
{
$json = ($this->createTool(admin: true))('ACME Cleaning', 'contact@acme.example', '+33100000000', 'https://acme.example');
$data = json_decode($json, true);
self::assertIsInt($data['id']);
self::assertSame('ACME Cleaning', $data['name']);
self::assertSame('contact@acme.example', $data['email']);
self::assertSame('+33100000000', $data['phone']);
self::assertSame('https://acme.example', $data['website']);
}
public function testCreateRequiresAdmin(): void
{
$this->expectException(AccessDeniedException::class);
($this->createTool(admin: false))('Should not pass');
}
public function testGetReturnsEmptyCollectionsWhenNoChildren(): void
{
$created = json_decode(($this->createTool(admin: true))('Lonely Prest'), true);
$json = ($this->getTool(admin: true))((int) $created['id']);
$data = json_decode($json, true);
self::assertSame($created['id'], $data['id']);
self::assertSame([], $data['contacts']);
self::assertSame([], $data['addresses']);
self::assertSame([], $data['reports']);
}
public function testGetUnknownIdThrows(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Prestataire with ID 999999 not found.');
($this->getTool(admin: true))(999999);
}
public function testUpdateOnlyTouchesProvidedFields(): void
{
$created = json_decode(($this->createTool(admin: true))('Before', 'before@x.test', '+33000000000', 'https://before.test'), true);
$json = ($this->updateTool(admin: true))((int) $created['id'], null, 'after@x.test', null, null);
$data = json_decode($json, true);
self::assertSame('Before', $data['name']); // unchanged
self::assertSame('after@x.test', $data['email']); // changed
self::assertSame('+33000000000', $data['phone']); // unchanged
self::assertSame('https://before.test', $data['website']); // unchanged
}
public function testListReturnsAllPrestatairesOrderedByName(): void
{
// Unique prefix isolates this test from data leaked by prior PHPUnit
// runs (DAMA rollback is not active in this project).
$prefix = 'list-test-'.uniqid().'-';
($this->createTool(admin: true))($prefix.'Zeta');
($this->createTool(admin: true))($prefix.'Alpha');
($this->createTool(admin: true))($prefix.'Mu');
$data = json_decode(($this->listTool(admin: true))(), true);
$names = array_values(array_filter(
array_column($data, 'name'),
fn ($n) => str_starts_with((string) $n, $prefix),
));
self::assertSame([$prefix.'Alpha', $prefix.'Mu', $prefix.'Zeta'], $names);
}
public function testDeleteRemovesPrestataire(): void
{
$created = json_decode(($this->createTool(admin: true))('To be removed'), true);
$id = (int) $created['id'];
$json = ($this->deleteTool(admin: true))($id);
$data = json_decode($json, true);
self::assertTrue($data['success']);
self::assertStringContainsString('"To be removed"', $data['message']);
$this->em->clear();
self::assertNull(self::getContainer()->get(PrestataireRepositoryInterface::class)->findById($id));
}
private function securityFor(bool $admin): Security
{
$security = $this->createMock(Security::class);
$security->method('isGranted')->willReturn($admin);
$security->method('getUser')->willReturn($admin ? $this->admin : null);
return $security;
}
private function createTool(bool $admin): CreatePrestataireTool
{
return new CreatePrestataireTool(
$this->em,
$this->securityFor($admin),
);
}
private function getTool(bool $admin): GetPrestataireTool
{
$c = self::getContainer();
return new GetPrestataireTool(
$c->get(PrestataireRepositoryInterface::class),
$c->get(ContactRepositoryInterface::class),
$c->get(AddressRepositoryInterface::class),
$c->get(CommercialReportRepositoryInterface::class),
$this->securityFor($admin),
);
}
private function updateTool(bool $admin): UpdatePrestataireTool
{
return new UpdatePrestataireTool(
self::getContainer()->get(PrestataireRepositoryInterface::class),
$this->em,
$this->securityFor($admin),
);
}
private function listTool(bool $admin): ListPrestatairesTool
{
return new ListPrestatairesTool(
self::getContainer()->get(PrestataireRepositoryInterface::class),
$this->securityFor($admin),
);
}
private function deleteTool(bool $admin): DeletePrestataireTool
{
return new DeletePrestataireTool(
self::getContainer()->get(PrestataireRepositoryInterface::class),
$this->em,
$this->securityFor($admin),
);
}
}
@@ -28,7 +28,6 @@ class ProspectConversionTest extends KernelTestCase
public function testConvertCreatesClientAndFlagsProspectWon(): void
{
$prospect = new Prospect();
$prospect->setName('Lead Test');
$prospect->setCompany('Lead Company '.uniqid());
$prospect->setEmail('lead@example.com');
$prospect->setPhone('06 00 00 00 00');
@@ -47,7 +46,7 @@ class ProspectConversionTest extends KernelTestCase
public function testConvertIsIdempotent(): void
{
$prospect = new Prospect();
$prospect->setName('Idempotent Lead');
$prospect->setCompany('Idempotent Lead');
$prospect->setStatus(ProspectStatus::New);
$this->em->persist($prospect);
$this->em->flush();
@@ -28,7 +28,6 @@ final class ConvertProspectProcessorTest extends KernelTestCase
$em = self::getContainer()->get(EntityManagerInterface::class);
$prospect = new Prospect();
$prospect->setName('Atelier Test');
$prospect->setCompany('Atelier Test SARL');
$em->persist($prospect);