Merge pull request 'Контроллер выдаёт List с File по запросу' (#14) from Feature/FilesRestController into master

Reviewed-on: #14
master
L_DelOff 2023-06-05 16:52:25 +03:00
commit bb405f62e4
3 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package ru.ldeloff.hedgehogcloud.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.ldeloff.hedgehogcloud.service.FileService;
import java.io.File;
import java.util.List;
@RestController
@RequestMapping("/apps/files")
public class FilesRestController {
FileService fileService;
public FilesRestController(FileService fileService) {
this.fileService = fileService;
}
@GetMapping
public List<File> listFiles(String path) {
return fileService.list(path);
}
}

View File

@ -0,0 +1,9 @@
package ru.ldeloff.hedgehogcloud.service;
import java.io.File;
import java.util.List;
public interface FileService {
public List<File> list(String path);
}

View File

@ -0,0 +1,16 @@
package ru.ldeloff.hedgehogcloud.service;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
public class FileServiceImpl implements FileService {
@Override
public List<File> list(String path) {
return Stream.of(new File(path).listFiles()).collect(Collectors.toList());
}
}