Merged PR 133: Update VideoGroup api call
Update VideoGroup api call
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
package com.olympus.apollo.controllers.FeApi;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.olympus.model.apollo.KSVideo;
|
||||
import com.olympus.apollo.repository.KSVideoRepository;
|
||||
import com.olympus.apollo.services.KSVideoService;
|
||||
import com.olympus.dto.VideoGroupCount;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
@@ -16,8 +22,10 @@ import org.springframework.http.ResponseEntity;
|
||||
@RequestMapping("/fe-api/ksvideos")
|
||||
public class KsVideoController {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(KsVideoController.class);
|
||||
|
||||
@Autowired
|
||||
private KSVideoRepository ksVideoREpository;
|
||||
private KSVideoRepository ksVideoRepository;
|
||||
|
||||
@Autowired
|
||||
private KSVideoService ksVideoService;
|
||||
@@ -32,7 +40,7 @@ public class KsVideoController {
|
||||
@GetMapping("/{id}")
|
||||
public KSVideo getVideo(@PathVariable String id) {
|
||||
|
||||
KSVideo result = ksVideoREpository.findById(id).get();
|
||||
KSVideo result = ksVideoRepository.findById(id).get();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -53,4 +61,36 @@ public class KsVideoController {
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/video-count")
|
||||
public ResponseEntity<?> getVideoCountsByGroup(@RequestParam String groupIds) {
|
||||
logger.info("[API] Received groupIds param: " + groupIds);
|
||||
|
||||
try {
|
||||
if (groupIds == null || groupIds.trim().isEmpty()) {
|
||||
logger.info("[API] groupIds is missing or empty");
|
||||
return ResponseEntity.badRequest().body(Map.of(
|
||||
"status", "ERROR",
|
||||
"message", "Missing or empty groupIds parameter"
|
||||
));
|
||||
}
|
||||
|
||||
List<String> ids = Arrays.asList(groupIds.split(","));
|
||||
logger.info("[API] Parsed groupIds: " + ids);
|
||||
|
||||
List<VideoGroupCount> videoCounts = ksVideoRepository.countVideosByGroupIds(ids);
|
||||
logger.info("[API] Video counts result: " + videoCounts);
|
||||
|
||||
return ResponseEntity.ok(videoCounts);
|
||||
} catch (Exception e) {
|
||||
logger.info("[API] Error while fetching video counts:");
|
||||
e.printStackTrace(); // log completo dello stack trace
|
||||
|
||||
return ResponseEntity.internalServerError().body(Map.of(
|
||||
"status", "ERROR",
|
||||
"message", "Failed to fetch video counts: " + e.getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class VideoGroupController {
|
||||
) {
|
||||
VideoGroup videoGroup = new VideoGroup();
|
||||
videoGroup.setName(videoGroupDTO.getName());
|
||||
videoGroup.setDescription(videoGroupDTO.getDescription());
|
||||
videoGroup.setType(videoGroupDTO.getType());
|
||||
videoGroup.setProjectId(videoGroupDTO.getProjectId());
|
||||
videoGroup.setApplicationId(videoGroupDTO.getApplicationId());
|
||||
@@ -58,4 +59,4 @@ public class VideoGroupController {
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,13 @@ package com.olympus.apollo.repository;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.repository.Aggregation;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
|
||||
import com.olympus.dto.VideoGroupCount;
|
||||
import com.olympus.model.apollo.KSVideo;
|
||||
|
||||
@RepositoryRestResource(collectionResourceRel = "ksvideos", path = "ksvideos")
|
||||
@@ -23,4 +25,13 @@ public interface KSVideoRepository extends MongoRepository<KSVideo, String> {
|
||||
@Query("{ 'ingestionInfo.metadata.KsVideoGroupId': ?0 }")
|
||||
public List<KSVideo> findByGroupId(String groupId, Sort sort);
|
||||
|
||||
@Query(value = "{ 'ingestionInfo.metadata.KsVideoGroupId': ?0 }", count = true)
|
||||
long countByGroupId(String groupId);
|
||||
|
||||
@Aggregation(pipeline = {
|
||||
"{ '$match': { 'ingestionInfo.metadata.KsVideoGroupId': { $in: ?0 } } }",
|
||||
"{ '$group': { _id: '$ingestionInfo.metadata.KsVideoGroupId', count: { $sum: 1 } } }"
|
||||
})
|
||||
List<VideoGroupCount> countVideosByGroupIds(List<String> groupIds);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user