From ff1ab0b2360a1ce7ef4c09a254ad2ac6961a55bc Mon Sep 17 00:00:00 2001 From: Emanuele Ferrelli Date: Mon, 12 May 2025 16:20:53 +0200 Subject: [PATCH] Create api for VideoGroup --- pom.xml | 4 +++ .../controllers/VideoGroupController.java | 29 +++++++++++++++++++ .../repository/VideoGroupRepository.java | 23 +++++++++++++++ .../hermione/services/VideoGroupService.java | 25 ++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 src/main/java/com/olympus/hermione/controllers/VideoGroupController.java create mode 100644 src/main/java/com/olympus/hermione/repository/VideoGroupRepository.java create mode 100644 src/main/java/com/olympus/hermione/services/VideoGroupService.java diff --git a/pom.xml b/pom.xml index 1b7edcc..970ccb1 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,10 @@ org.springframework.boot spring-boot-starter-data-mongodb + + org.springframework.boot + spring-boot-starter-data-rest + org.springframework.boot spring-boot-starter-web diff --git a/src/main/java/com/olympus/hermione/controllers/VideoGroupController.java b/src/main/java/com/olympus/hermione/controllers/VideoGroupController.java new file mode 100644 index 0000000..3378eb7 --- /dev/null +++ b/src/main/java/com/olympus/hermione/controllers/VideoGroupController.java @@ -0,0 +1,29 @@ +package com.olympus.hermione.controllers; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import com.olympus.model.apollo.VideoGroup; +import com.olympus.hermione.services.VideoGroupService; + +@RestController +public class VideoGroupController { + + @Autowired + private VideoGroupService videoGroupService; + + + @GetMapping("/project") + public List getVideoGroupByProjectId(@RequestParam String projectId) { + return videoGroupService.findByProjectId(projectId); + } + + @GetMapping("/{id}") + public VideoGroup getVideoGroupById(@PathVariable String id) { + return videoGroupService.getVideoGroupById(id); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/olympus/hermione/repository/VideoGroupRepository.java b/src/main/java/com/olympus/hermione/repository/VideoGroupRepository.java new file mode 100644 index 0000000..1c24157 --- /dev/null +++ b/src/main/java/com/olympus/hermione/repository/VideoGroupRepository.java @@ -0,0 +1,23 @@ +package com.olympus.hermione.repository; + +import java.util.List; +import java.util.Optional; + +import org.springframework.data.domain.Sort; +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.model.apollo.VideoGroup; + + +@RepositoryRestResource(collectionResourceRel = "video_groups", path = "video_groups") +@CrossOrigin +public interface VideoGroupRepository extends MongoRepository { + + @Query("{ 'projectId': ?0 }") + public List findByProjectId(String projectId, Sort sort); + + public Optional findById(String id); +} \ No newline at end of file diff --git a/src/main/java/com/olympus/hermione/services/VideoGroupService.java b/src/main/java/com/olympus/hermione/services/VideoGroupService.java new file mode 100644 index 0000000..16e8590 --- /dev/null +++ b/src/main/java/com/olympus/hermione/services/VideoGroupService.java @@ -0,0 +1,25 @@ +package com.olympus.hermione.services; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +import com.olympus.hermione.repository.VideoGroupRepository; +import com.olympus.model.apollo.VideoGroup; + +@Service +public class VideoGroupService { + + @Autowired + private VideoGroupRepository videoGroupRepository; + + public VideoGroup getVideoGroupById(String id) { + return videoGroupRepository.findById(id).get(); + } + + public List findByProjectId(String projectId) { + return videoGroupRepository.findByProjectId(projectId, Sort.by(Sort.Direction.DESC, "id")); + } +} \ No newline at end of file