fix: add storeId variable to retrieveStoreDetails
parent
8256f2c8a6
commit
3569639644
|
|
@ -163,15 +163,25 @@ public class StoreService {
|
|||
@GET
|
||||
@Path("/getStoreDetails")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getStoreDetails() {
|
||||
public Response getStoreDetails(
|
||||
@QueryParam("dbHost") String dbHost,
|
||||
@QueryParam("storeId") Integer storeId) {
|
||||
|
||||
if (dbHost == null) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"dbHost parameter is required\"}").build();
|
||||
}
|
||||
|
||||
if (storeId == null) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"storeId parameter is required\"}").build();
|
||||
}
|
||||
|
||||
try {
|
||||
StoreDetails storeDetails = retrieveStoreDetailsFromDatabase();
|
||||
StoreDetails storeDetails = retrieveStoreDetails(dbHost,storeId);
|
||||
|
||||
if (storeDetails != null) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
String jsonResponse = objectMapper.writeValueAsString(storeDetails);
|
||||
//System.out.println("JSON Response: " + jsonResponse); // Ajoutez ceci pour vérifier la sortie JSON
|
||||
return Response.ok(jsonResponse).build();
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -194,31 +204,37 @@ public class StoreService {
|
|||
*
|
||||
* @return a list of stores retrieved from the database
|
||||
*/
|
||||
private StoreDetails retrieveStoreDetailsFromDatabase() {
|
||||
private StoreDetails retrieveStoreDetails(String dbHost, Integer storeId) {
|
||||
DriverManager.setLoginTimeout(5);
|
||||
|
||||
StoreDetails storeDetails = new StoreDetails(); // Déclarer l'objet en dehors des blocs try
|
||||
|
||||
try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("com02")) {
|
||||
// Partie Store
|
||||
// Store section
|
||||
String storeQuery = "SELECT st.id_structure, TRIM(st.nom) as nom, '10.100.0.18' AS ip, " +
|
||||
"st.tel1 AS telephone, 'https://mp4.ikksgroup.com/photos/1/6/5/7/3/16573-large.JPG' as photoLink " +
|
||||
"FROM COM02.STRUCTURE st " +
|
||||
"WHERE st.id_structure = 4";
|
||||
"WHERE st.id_structure = ?";
|
||||
|
||||
try (PreparedStatement storeStatement = databaseConnection.getConnection().prepareStatement(storeQuery);
|
||||
ResultSet storeResultSet = storeStatement.executeQuery()) {
|
||||
|
||||
if (storeResultSet.next()) {
|
||||
Store store = mapResultSetToStore(storeResultSet);
|
||||
storeDetails.setStore(store); // Définir la partie Store dans l'objet StoreDetails
|
||||
// Faites quelque chose avec la partie Store
|
||||
} else {
|
||||
// Ajustez selon le comportement souhaité si aucun résultat n'est trouvé pour la partie Store
|
||||
try (PreparedStatement storeStatement = databaseConnection.getConnection().prepareStatement(storeQuery)) {
|
||||
storeStatement.setInt(1, storeId); // Set the value of the parameter
|
||||
|
||||
try (ResultSet storeResultSet = storeStatement.executeQuery()) {
|
||||
if (storeResultSet.next()) {
|
||||
Store store = mapResultSetToStore(storeResultSet);
|
||||
storeDetails.setStore(store);
|
||||
} else {
|
||||
// Adjust to the desired behavior if no results are found for the Store part.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Partie Réplication
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
// Handle exceptions correctly in a production environment
|
||||
}
|
||||
|
||||
try (DatabaseConnectXSTORE databaseConnection = new DatabaseConnectXSTORE(dbHost,"dtv")) {
|
||||
// Replication section
|
||||
String replicationQuery = "SELECT 1 AS replicationOk, " +
|
||||
"5 AS pendingReplications, " +
|
||||
"TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS minReplicationDate, " +
|
||||
|
|
@ -232,11 +248,11 @@ public class StoreService {
|
|||
StoreReplication storeReplication = mapResultSetToStoreReplication(storeReplicationResultSet);
|
||||
storeDetails.setReplication(storeReplication);
|
||||
} else {
|
||||
// Ajustez selon le comportement souhaité si aucun résultat n'est trouvé pour la partie Store
|
||||
// Adjust to the desired behavior if no results are found for the Replication section.
|
||||
}
|
||||
}
|
||||
|
||||
// Partie Ticket
|
||||
// Ticket section
|
||||
String ticketQuery = "SELECT 10 AS totalTicketsInCaisse, " +
|
||||
"15 AS totalTicketsInBackOffice " +
|
||||
"FROM DUAL";
|
||||
|
|
@ -248,15 +264,15 @@ public class StoreService {
|
|||
StoreTicket storeTicket = mapResultSetToStoreTicket(ticketResultSet);
|
||||
storeDetails.setTickets(storeTicket);
|
||||
} else {
|
||||
// Ajustez selon le comportement souhaité si aucun résultat n'est trouvé pour la partie Ticket
|
||||
// Adjust to the desired behavior if no results are found for the Ticket section.
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
// Gérer les exceptions correctement dans un environnement de production
|
||||
// Handle exceptions correctly in a production environment
|
||||
}
|
||||
|
||||
// Retournez l'objet StoreDetails complet
|
||||
// Return the complete StoreDetails object
|
||||
return storeDetails;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue