Skip to content
Extraits de code Groupes Projets
Valider 60242f4c rédigé par oussama aftys's avatar oussama aftys
Parcourir les fichiers

enhanced live product presentation process

parent 2968e295
1 requête de fusion!28enhanced live product presentation process
Pipeline #19044 en échec avec les étapes
in 22 secondes
## [0.0.10-RELEASE]
### Added
- added live pagination in client side .
- enhanced live product presentation process.
## [0.0.9-RELEASE]
### Added
......
\ No newline at end of file
......@@ -17,4 +17,7 @@ public interface LiveProductRepository extends JpaRepository<LiveProduct, Long>
@Query("SELECT new com.marketingconfort.mydressin.mydressinstreamservices.models.dtos.LiveProductResponse(l) FROM LiveProduct l WHERE l.liveStream.id = :id AND (l.status = com.marketingconfort.mydressin.mydressinstreamservices.models.enums.ProductStatus.IN_PRESENTATION OR l.status = com.marketingconfort.mydressin.mydressinstreamservices.models.enums.ProductStatus.PRESENTED)")
List<LiveProductResponse> findEnabledLiveProducts(@Param("id") Long id);
@Query("SELECT l FROM LiveProduct l WHERE l.liveStream.id = :id")
List<LiveProduct> findByLiveStreamId(@Param("id") Long id);
}
......@@ -65,11 +65,36 @@ public class LiveProductService implements ILiveProductService {
.price(liveProduct.getPrice())
.status(liveProduct.getStatus())
.image(liveProduct.getImage())
.productId(liveProduct.getProductId())
.build();
}
@Override
public void removeLiveProduct(Long id) {
logger.info("Removing live product with id: {}", id);
// First, get the product details before deletion
LiveProduct liveProduct = liveProductRepository.findById(id).orElse(null);
if (liveProduct != null) {
try {
long liveId = liveProduct.getLiveStream().getId();
String productId = String.valueOf(liveProduct.getProductId());
// Call stock management service to hide the product from this specific live
String url = nameUrl.getStockManagementService() + NameUri.STOCK + "/products/hide-product-from-live" +
"?productId=" + productId + "&liveId=" + String.valueOf(liveId);
logger.info("Calling stock management service to hide product from live: {}", url);
mcRestTemplateService.postForObject(url, null, Void.class);
logger.info("Successfully notified stock management service to hide product {} from live {}", productId, liveId);
} catch (Exception e) {
logger.error("Failed to call stock management service when removing product. ProductId: {}, Error: {}",
liveProduct.getProductId(), e.getMessage(), e);
// Continue with removal even if stock service call fails
}
}
// Remove from stream service database
liveProductRepository.deleteById(id);
logger.info("Live product removed successfully. Id: {}", id);
}
......@@ -112,12 +137,16 @@ public class LiveProductService implements ILiveProductService {
TimeStampProduct timeStampProduct = timeStampProductRepository.save(new TimeStampProduct(startTime, liveProduct));
logger.debug("TimeStampProduct created with id: {}", timeStampProduct.getId());
// Call stock management service with single live presentation endpoint
// This integrates with our new multiple live presentations feature but uses the single endpoint
// since we're presenting to one live at a time
String url = nameUrl.getStockManagementService() + NameUri.STOCK + StockManagerServicePath.PRESENT_PRODUCT +
"?liveId=" + liveId + "&id=" + liveProduct.getProductId() + "&presentedAt=" + startTime;
"?id=" + liveProduct.getProductId() + "&liveId=" + liveId + "&presentedAt=" + startTime;
try {
logger.info("Calling stock management service: {}", url);
logger.info("Calling stock management service to present product: {}", url);
mcRestTemplateService.postForObject(url, null, Void.class);
logger.info("Successfully notified stock management service of product presentation");
LiveProductDto result = LiveProductDto.builder()
.id(liveProductId)
......@@ -141,7 +170,7 @@ public class LiveProductService implements ILiveProductService {
return result;
} catch (Exception e) {
logger.error("Failed to present product with id: {}. Error: {}", liveProductId, e.getMessage(), e);
throw new TechnicalException("Failed to present product: " + e.getMessage());
throw new TechnicalException("Failed to present product in stock management service: " + e.getMessage());
}
}
......@@ -166,15 +195,17 @@ public class LiveProductService implements ILiveProductService {
.build());
logger.debug("TimeStampProduct created with id: {}", timeStampProduct.getId());
// Call stock management service to register the presentation
String url = nameUrl.getStockManagementService() + NameUri.STOCK + StockManagerServicePath.PRESENT_PRODUCT +
"?liveId=" + liveProduct.getLiveStream().getId() + "&id=" + liveProduct.getProductId() + "&presentedAt=" + startTime;
"?id=" + liveProduct.getProductId() + "&liveId=" + liveProduct.getLiveStream().getId() + "&presentedAt=" + startTime;
try {
logger.info("Calling stock management service: {}", url);
logger.info("Calling stock management service to register timestamp product: {}", url);
mcRestTemplateService.postForObject(url, null, Void.class);
logger.info("Successfully notified stock management service of timestamp product");
} catch (Exception e) {
logger.error("Failed to call stock management service. LiveProductId: {}, Error: {}", liveProductId, e.getMessage(), e);
// Note: This exception is caught and logged but not rethrown
// Log the error but don't fail the operation - the local timestamp is still created
}
TimeStampProductDto result = TimeStampProductDto.builder()
......@@ -236,15 +267,20 @@ public class LiveProductService implements ILiveProductService {
logger.debug("LiveProduct status updated to IN_PRESENTATION. Id: {}", liveProductId);
long liveId = liveProduct.getLiveStream().getId();
// Call stock management service to present the product
String url = nameUrl.getStockManagementService() + NameUri.STOCK + StockManagerServicePath.PRESENT_PRODUCT +
"?liveId=" + liveId + "&id=" + liveProduct.getProductId() + "&presentedAt=" + startTime;
"?id=" + liveProduct.getProductId() + "&liveId=" + liveId + "&presentedAt=" + startTime;
try {
logger.info("Calling stock management service: {}", url);
logger.info("Calling stock management service to push product: {}", url);
mcRestTemplateService.postForObject(url, null, Void.class);
logger.info("Successfully notified stock management service of product push");
} catch (Exception e) {
logger.error("Failed to call stock management service. LiveProductId: {}, Error: {}", liveProductId, e.getMessage(), e);
// Continue with local operation even if remote call fails
}
TimeStampProduct timeStampProduct = timeStampProductRepository.save(TimeStampProduct.builder()
.liveProduct(liveProduct)
.startTime(startTime)
......@@ -283,6 +319,7 @@ public class LiveProductService implements ILiveProductService {
lastTimeStamp.setEndTime(endTime);
lastTimeStamp = timeStampProductRepository.save(lastTimeStamp);
TimeStampProductDto result = TimeStampProductDto.builder()
.type(MessageType.HIDEPRODUCT)
.id(lastTimeStamp.getId())
......
......@@ -208,14 +208,39 @@ public class LiveStreamService implements ILiveStreamService {
@Override
public void deleteLive(Long liveId) {
liveStreamRepository.deleteById(liveId);
String url = nameUrl.getStockManagementService() + NameUri.STOCK + StockManagerServicePath.HIDE_LIVE_PRODUCT+"?liveId="+liveId;
try{
log.info("Deleting live stream with id: {}", liveId);
// First, get all products associated with this live stream
List<LiveProduct> liveProducts = liveProductRepository.findByLiveStreamId(liveId);
// Hide each product from the specific live in the stock management service
for (LiveProduct liveProduct : liveProducts) {
try {
String hideUrl = nameUrl.getStockManagementService() + NameUri.STOCK + "/products/hide-product-from-live" +
"?productId=" + String.valueOf(liveProduct.getProductId()) + "&liveId=" + liveId;
log.info("Calling stock management service to hide product {} from live {}", liveProduct.getProductId(), liveId);
mcRestTemplateService.postForObject(hideUrl, null, Void.class);
log.info("Successfully hid product {} from live {}", liveProduct.getProductId(), liveId);
} catch (Exception e) {
log.error("Failed to hide product {} from live {}. Error: {}", liveProduct.getProductId(), liveId, e.getMessage(), e);
// Continue with other products even if one fails
}
}
// Also call the general hide endpoint as a fallback (this will hide all products from this live)
String url = nameUrl.getStockManagementService() + NameUri.STOCK + StockManagerServicePath.HIDE_LIVE_PRODUCT + "?liveId=" + liveId;
try {
log.info("Calling stock management service to hide all products from live: {}", liveId);
mcRestTemplateService.postForObject(url, null, Void.class);
log.info("Successfully hid all products from live: {}", liveId);
} catch (Exception e) {
log.error("Exception: " + e.getMessage());
log.error("Failed to hide products from live {}. Error: {}", liveId, e.getMessage(), e);
}
// Finally, delete the live stream from the stream service database
liveStreamRepository.deleteById(liveId);
log.info("Live stream deleted successfully. Id: {}", liveId);
}
......
live-server:
hls: https://hls.mydressin-server.com/hls
rtmp: rtmp://rtmp.mydressin-server.com:1935/live
stat: https://rtmp.mydressin-server.com/stat
status: http://rtmp.mydressin-server.com:3003
cdn: https://bucket-rtmp.s3.eu-north-1.amazonaws.com/
hls: https://ant-media-ovh.mydressin-server.com
rtmp: rtmp://ant-media-ovh.mydressin-server.com/live
stat: https://ant-media-ovh.mydressin-server.com/stat
status: https://live-rec.mydressin-server.com
cdn: https://test.mydressin-cdn.com/
spring:
datasource:
......
......@@ -8,7 +8,7 @@ spring:
application:
name: mydressin-stream-service
profiles:
active: ${PROFILE:rec}
active: ${PROFILE:local}
servlet:
multipart:
max-file-size: 90000MB
......
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter