|
|
@@ -1,8 +1,11 @@
|
|
|
package org.linlinjava.litemall.admin.web;
|
|
|
|
|
|
+import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
|
|
import org.linlinjava.litemall.core.storage.StorageService;
|
|
|
import org.linlinjava.litemall.core.util.CharUtil;
|
|
|
import org.linlinjava.litemall.core.util.ResponseUtil;
|
|
|
+import org.linlinjava.litemall.core.validator.Order;
|
|
|
+import org.linlinjava.litemall.core.validator.Sort;
|
|
|
import org.linlinjava.litemall.db.domain.LitemallStorage;
|
|
|
import org.linlinjava.litemall.db.service.LitemallStorageService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -10,9 +13,11 @@ import org.springframework.core.io.Resource;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -22,6 +27,7 @@ import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/admin/storage")
|
|
|
+@Validated
|
|
|
public class AdminStorageController {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -46,10 +52,12 @@ public class AdminStorageController {
|
|
|
}
|
|
|
|
|
|
@GetMapping("/list")
|
|
|
- public Object list(String key, String name,
|
|
|
- @RequestParam(value = "page", defaultValue = "1") Integer page,
|
|
|
- @RequestParam(value = "limit", defaultValue = "10") Integer limit,
|
|
|
- String sort, String order){
|
|
|
+ public Object list(@LoginAdmin Integer adminId,
|
|
|
+ String key, String name,
|
|
|
+ @RequestParam(defaultValue = "1") Integer page,
|
|
|
+ @RequestParam(defaultValue = "10") Integer limit,
|
|
|
+ @Sort @RequestParam(defaultValue = "add_time") String sort,
|
|
|
+ @Order @RequestParam(defaultValue = "desc") String order){
|
|
|
List<LitemallStorage> storageList = litemallStorageService.querySelective(key, name, page, limit, sort, order);
|
|
|
int total = litemallStorageService.countSelective(key, name, page, limit, sort, order);
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
@@ -60,7 +68,10 @@ public class AdminStorageController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
- public Object create(@RequestParam("file") MultipartFile file) {
|
|
|
+ public Object create(@LoginAdmin Integer adminId, @RequestParam("file") MultipartFile file) {
|
|
|
+ if(adminId == null){
|
|
|
+ return ResponseUtil.unlogin();
|
|
|
+ }
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
InputStream inputStream = null;
|
|
|
try {
|
|
|
@@ -86,9 +97,9 @@ public class AdminStorageController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/read")
|
|
|
- public Object read(Integer id) {
|
|
|
- if(id == null){
|
|
|
- return ResponseUtil.badArgument();
|
|
|
+ public Object read(@LoginAdmin Integer adminId, @NotNull Integer id) {
|
|
|
+ if(adminId == null){
|
|
|
+ return ResponseUtil.unlogin();
|
|
|
}
|
|
|
LitemallStorage storageInfo = litemallStorageService.findById(id);
|
|
|
if(storageInfo == null){
|
|
|
@@ -98,14 +109,19 @@ public class AdminStorageController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/update")
|
|
|
- public Object update(@RequestBody LitemallStorage litemallStorage) {
|
|
|
-
|
|
|
+ public Object update(@LoginAdmin Integer adminId, @RequestBody LitemallStorage litemallStorage) {
|
|
|
+ if(adminId == null){
|
|
|
+ return ResponseUtil.unlogin();
|
|
|
+ }
|
|
|
litemallStorageService.update(litemallStorage);
|
|
|
return ResponseUtil.ok(litemallStorage);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/delete")
|
|
|
- public Object delete(@RequestBody LitemallStorage litemallStorage) {
|
|
|
+ public Object delete(@LoginAdmin Integer adminId, @RequestBody LitemallStorage litemallStorage) {
|
|
|
+ if(adminId == null){
|
|
|
+ return ResponseUtil.unlogin();
|
|
|
+ }
|
|
|
litemallStorageService.deleteByKey(litemallStorage.getKey());
|
|
|
storageService.delete(litemallStorage.getKey());
|
|
|
return ResponseUtil.ok();
|