From 1f8c5a062b43516d52fa659ec8c55f3a73e79086 Mon Sep 17 00:00:00 2001 From: "andrea.terzani" Date: Tue, 30 Jul 2024 15:16:20 +0200 Subject: [PATCH] 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. --- pom.xml | 5 +++ .../FeApi/KsDocumentController.java | 39 +++++++++++++++++++ .../apollo/controllers/KSFileController.java | 7 +++- .../repository/KSDocumentRepository.java | 12 ++++-- .../repository/RepositoryRestResource.java | 5 +++ 5 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/olympus/apollo/controllers/FeApi/KsDocumentController.java create mode 100644 src/main/java/com/olympus/apollo/repository/RepositoryRestResource.java diff --git a/pom.xml b/pom.xml index c85f318..6717668 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,11 @@ --> + + org.springframework.boot + spring-boot-starter-data-rest + + org.springframework.ai spring-ai-mongodb-atlas-store-spring-boot-starter diff --git a/src/main/java/com/olympus/apollo/controllers/FeApi/KsDocumentController.java b/src/main/java/com/olympus/apollo/controllers/FeApi/KsDocumentController.java new file mode 100644 index 0000000..3a46eba --- /dev/null +++ b/src/main/java/com/olympus/apollo/controllers/FeApi/KsDocumentController.java @@ -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 getDocuments() { + + List result = (List) ksDocumentREpository.findAll(); + + return result; + } + @GetMapping("/{id}") + public List getDocument(@RequestParam String id) { + + List result = (List) ksDocumentREpository.findAll(); + + return result; + } +} diff --git a/src/main/java/com/olympus/apollo/controllers/KSFileController.java b/src/main/java/com/olympus/apollo/controllers/KSFileController.java index d7ca220..25efcfb 100644 --- a/src/main/java/com/olympus/apollo/controllers/KSFileController.java +++ b/src/main/java/com/olympus/apollo/controllers/KSFileController.java @@ -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) { diff --git a/src/main/java/com/olympus/apollo/repository/KSDocumentRepository.java b/src/main/java/com/olympus/apollo/repository/KSDocumentRepository.java index 4a14147..898e187 100644 --- a/src/main/java/com/olympus/apollo/repository/KSDocumentRepository.java +++ b/src/main/java/com/olympus/apollo/repository/KSDocumentRepository.java @@ -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 { +@RepositoryRestResource(collectionResourceRel = "ksdocuments", path = "ksdocuments") +@CrossOrigin +public interface KSDocumentRepository extends MongoRepository { public Iterable findAllByIngestionStatus(String status); } diff --git a/src/main/java/com/olympus/apollo/repository/RepositoryRestResource.java b/src/main/java/com/olympus/apollo/repository/RepositoryRestResource.java new file mode 100644 index 0000000..267cb80 --- /dev/null +++ b/src/main/java/com/olympus/apollo/repository/RepositoryRestResource.java @@ -0,0 +1,5 @@ +package com.olympus.apollo.repository; + +public @interface RepositoryRestResource { + +}