Create api for VideoGroup

This commit is contained in:
2025-05-12 16:20:53 +02:00
parent 651c80d541
commit ff1ab0b236
4 changed files with 81 additions and 0 deletions

View File

@@ -38,6 +38,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>

View File

@@ -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<VideoGroup> getVideoGroupByProjectId(@RequestParam String projectId) {
return videoGroupService.findByProjectId(projectId);
}
@GetMapping("/{id}")
public VideoGroup getVideoGroupById(@PathVariable String id) {
return videoGroupService.getVideoGroupById(id);
}
}

View File

@@ -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<VideoGroup, String> {
@Query("{ 'projectId': ?0 }")
public List<VideoGroup> findByProjectId(String projectId, Sort sort);
public Optional<VideoGroup> findById(String id);
}

View File

@@ -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<VideoGroup> findByProjectId(String projectId) {
return videoGroupRepository.findByProjectId(projectId, Sort.by(Sort.Direction.DESC, "id"));
}
}