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:
andrea.terzani
2024-07-30 15:16:20 +02:00
parent 59ee7672c9
commit 1f8c5a062b
5 changed files with 63 additions and 5 deletions

View File

@@ -61,6 +61,11 @@
</dependency>
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mongodb-atlas-store-spring-boot-starter</artifactId>

View File

@@ -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;
}
}

View File

@@ -1,6 +1,7 @@
package com.olympus.apollo.controllers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.stereotype.Controller;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
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.StorageService;
@Controller
@RestController
public class KSFileController {
@Autowired
private StorageService storageService;
@@ -30,6 +33,8 @@ public class KSFileController {
private KSIngestionInfoRepository ksIngestionInfoRepository;
@PostMapping("/upload")
public String handleFileUpload(@RequestParam("file") MultipartFile file) {

View File

@@ -1,12 +1,16 @@
package com.olympus.apollo.repository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.mongodb.repository.MongoRepository;
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;
@Repository
public interface KSDocumentRepository extends CrudRepository<KSDocument, String> {
@RepositoryRestResource(collectionResourceRel = "ksdocuments", path = "ksdocuments")
@CrossOrigin
public interface KSDocumentRepository extends MongoRepository<KSDocument, String> {
public Iterable<KSDocument> findAllByIngestionStatus(String status);
}

View File

@@ -0,0 +1,5 @@
package com.olympus.apollo.repository;
public @interface RepositoryRestResource {
}