Merge pull request 'Контроллер выдаёт List с File по запросу' (#14) from Feature/FilesRestController into master
Reviewed-on: #14master
commit
bb405f62e4
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue