Create api for VideoGroup
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -38,6 +38,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user