refactoring
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package dev.lions.btpxpress.adapter.http;
|
||||
|
||||
import dev.lions.btpxpress.adapter.http.util.ResponseHelper;
|
||||
import dev.lions.btpxpress.application.service.ClientService;
|
||||
import dev.lions.btpxpress.domain.core.entity.Client;
|
||||
import dev.lions.btpxpress.domain.core.entity.Permission;
|
||||
import dev.lions.btpxpress.domain.shared.dto.ClientCreateDTO;
|
||||
import dev.lions.btpxpress.domain.shared.dto.ClientResponseDTO;
|
||||
import dev.lions.btpxpress.domain.shared.mapper.ClientMapper;
|
||||
import dev.lions.btpxpress.infrastructure.security.RequirePermission;
|
||||
import io.quarkus.security.Authenticated;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -36,6 +38,8 @@ public class ClientResource {
|
||||
|
||||
@Inject ClientService clientService;
|
||||
|
||||
@Inject ClientMapper clientMapper;
|
||||
|
||||
// === ENDPOINTS DE LECTURE - API CONTRACTS PRÉSERVÉS EXACTEMENT ===
|
||||
|
||||
@GET
|
||||
@@ -51,13 +55,29 @@ public class ClientResource {
|
||||
logger.debug("GET /clients - page: {}, size: {}", page, size);
|
||||
|
||||
List<Client> clients;
|
||||
long total;
|
||||
|
||||
if (page == 0 && size == 20) {
|
||||
// Par défaut, retourner tous les clients sans pagination
|
||||
clients = clientService.findAll();
|
||||
total = clients.size();
|
||||
} else {
|
||||
// Avec pagination
|
||||
clients = clientService.findAll(page, size);
|
||||
// Le count() de Panache est déjà optimisé et efficace
|
||||
total = clientService.count();
|
||||
}
|
||||
|
||||
return Response.ok(clients).build();
|
||||
List<ClientResponseDTO> dtos = clients.stream()
|
||||
.map(clientMapper::toResponseDTO)
|
||||
.toList();
|
||||
|
||||
// Utiliser PagedResponse si pagination demandée, sinon ApiResponse simple
|
||||
if (page > 0 || size != 20) {
|
||||
return ResponseHelper.paginated(dtos, page, size, total);
|
||||
} else {
|
||||
return ResponseHelper.ok(dtos);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -71,7 +91,8 @@ public class ClientResource {
|
||||
logger.debug("GET /clients/{}", id);
|
||||
|
||||
Client client = clientService.findByIdRequired(id);
|
||||
return Response.ok(client).build();
|
||||
ClientResponseDTO dto = clientMapper.toResponseDTO(client);
|
||||
return ResponseHelper.ok(dto);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -106,7 +127,10 @@ public class ClientResource {
|
||||
clients = clientService.findAll();
|
||||
}
|
||||
|
||||
return Response.ok(clients).build();
|
||||
List<ClientResponseDTO> dtos = clients.stream()
|
||||
.map(clientMapper::toResponseDTO)
|
||||
.toList();
|
||||
return ResponseHelper.ok(dtos);
|
||||
}
|
||||
|
||||
// === ENDPOINTS D'ÉCRITURE - API CONTRACTS PRÉSERVÉS EXACTEMENT ===
|
||||
@@ -126,7 +150,8 @@ public class ClientResource {
|
||||
|
||||
try {
|
||||
Client createdClient = clientService.createFromDTO(clientDTO);
|
||||
return Response.status(Response.Status.CREATED).entity(createdClient).build();
|
||||
ClientResponseDTO dto = clientMapper.toResponseDTO(createdClient);
|
||||
return ResponseHelper.created(dto, "Client créé avec succès");
|
||||
} catch (Exception e) {
|
||||
logger.error("Erreur lors de la création du client: {}", e.getMessage(), e);
|
||||
throw e;
|
||||
@@ -147,7 +172,8 @@ public class ClientResource {
|
||||
logger.debug("PUT /clients/{}", id);
|
||||
|
||||
Client updatedClient = clientService.update(id, client);
|
||||
return Response.ok(updatedClient).build();
|
||||
ClientResponseDTO dto = clientMapper.toResponseDTO(updatedClient);
|
||||
return ResponseHelper.ok(dto, "Client mis à jour avec succès");
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@@ -161,7 +187,7 @@ public class ClientResource {
|
||||
logger.debug("DELETE /clients/{}", id);
|
||||
|
||||
clientService.delete(id);
|
||||
return Response.noContent().build();
|
||||
return ResponseHelper.noContent("Client supprimé avec succès");
|
||||
}
|
||||
|
||||
// === ENDPOINTS STATISTIQUES - API CONTRACTS PRÉSERVÉS EXACTEMENT ===
|
||||
@@ -174,6 +200,6 @@ public class ClientResource {
|
||||
logger.debug("GET /clients/count");
|
||||
|
||||
long count = clientService.count();
|
||||
return Response.ok(count).build();
|
||||
return ResponseHelper.ok(count);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user