feat: Add endpoint to list uploaded files
The code changes include adding a new endpoint `/files` to the `KSFileController` class. This endpoint uses the `GetMapping` annotation to handle GET requests and returns a list of uploaded files (`KSDocument`) from the `ksDocumentRepository`. This commit message suggests that a new feature has been added to the codebase, specifically an endpoint to list uploaded files.
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -61,6 +61,11 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ai</groupId>
|
<groupId>org.springframework.ai</groupId>
|
||||||
<artifactId>spring-ai-mongodb-atlas-store-spring-boot-starter</artifactId>
|
<artifactId>spring-ai-mongodb-atlas-store-spring-boot-starter</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.olympus.apollo.controllers.FeApi;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.olympus.apollo.models.KSDocument;
|
||||||
|
import com.olympus.apollo.repository.KSDocumentRepository;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/fe-api/ksdocuments")
|
||||||
|
@CrossOrigin
|
||||||
|
public class KsDocumentController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private KSDocumentRepository ksDocumentREpository;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("")
|
||||||
|
public List<KSDocument> getDocuments() {
|
||||||
|
|
||||||
|
List<KSDocument> result = (List<KSDocument>) ksDocumentREpository.findAll();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public List<KSDocument> getDocument(@RequestParam String id) {
|
||||||
|
|
||||||
|
List<KSDocument> result = (List<KSDocument>) ksDocumentREpository.findAll();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.olympus.apollo.controllers;
|
package com.olympus.apollo.controllers;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.codelibs.jhighlight.fastutil.Hash;
|
import org.codelibs.jhighlight.fastutil.Hash;
|
||||||
@@ -8,8 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
@@ -20,7 +23,7 @@ import com.olympus.apollo.repository.KSIngestionInfoRepository;
|
|||||||
import com.olympus.apollo.services.StorageFileNotFoundException;
|
import com.olympus.apollo.services.StorageFileNotFoundException;
|
||||||
import com.olympus.apollo.services.StorageService;
|
import com.olympus.apollo.services.StorageService;
|
||||||
|
|
||||||
@Controller
|
@RestController
|
||||||
public class KSFileController {
|
public class KSFileController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private StorageService storageService;
|
private StorageService storageService;
|
||||||
@@ -30,6 +33,8 @@ public class KSFileController {
|
|||||||
private KSIngestionInfoRepository ksIngestionInfoRepository;
|
private KSIngestionInfoRepository ksIngestionInfoRepository;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public String handleFileUpload(@RequestParam("file") MultipartFile file) {
|
public String handleFileUpload(@RequestParam("file") MultipartFile file) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package com.olympus.apollo.repository;
|
package com.olympus.apollo.repository;
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
|
||||||
import com.olympus.apollo.models.KSDocument;
|
import com.olympus.apollo.models.KSDocument;
|
||||||
|
|
||||||
@Repository
|
@RepositoryRestResource(collectionResourceRel = "ksdocuments", path = "ksdocuments")
|
||||||
public interface KSDocumentRepository extends CrudRepository<KSDocument, String> {
|
@CrossOrigin
|
||||||
|
public interface KSDocumentRepository extends MongoRepository<KSDocument, String> {
|
||||||
|
|
||||||
public Iterable<KSDocument> findAllByIngestionStatus(String status);
|
public Iterable<KSDocument> findAllByIngestionStatus(String status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.olympus.apollo.repository;
|
||||||
|
|
||||||
|
public @interface RepositoryRestResource {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user