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