mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-19 18:15:38 +08:00
资源分类整改
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.constant.BackendConstant;
|
||||
import xyz.playedu.api.domain.Resource;
|
||||
import xyz.playedu.api.domain.ResourceCategory;
|
||||
import xyz.playedu.api.domain.ResourceVideo;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.request.backend.ResourceRequest;
|
||||
import xyz.playedu.api.service.MinioService;
|
||||
import xyz.playedu.api.service.ResourceCategoryService;
|
||||
import xyz.playedu.api.service.ResourceService;
|
||||
import xyz.playedu.api.service.ResourceVideoService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
@@ -28,7 +23,6 @@ import java.util.stream.Collectors;
|
||||
* @create 2023/2/23 10:50
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/backend/v1/resource")
|
||||
public class ResourceController {
|
||||
|
||||
@@ -38,9 +32,6 @@ public class ResourceController {
|
||||
@Autowired
|
||||
private ResourceVideoService resourceVideoService;
|
||||
|
||||
@Autowired
|
||||
private ResourceCategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private MinioService minioService;
|
||||
|
||||
@@ -61,7 +52,6 @@ public class ResourceController {
|
||||
ResourcePaginateFilter filter = new ResourcePaginateFilter();
|
||||
filter.setSortAlgo(sortAlgo);
|
||||
filter.setSortField(sortField);
|
||||
filter.setType(type);
|
||||
if (name != null && name.length() > 0) {
|
||||
filter.setName(name);
|
||||
}
|
||||
@@ -84,60 +74,6 @@ public class ResourceController {
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@GetMapping("/create")
|
||||
public JsonResponse create(@RequestParam(name = "type") String type) {
|
||||
List<ResourceCategory> categories = categoryService.getByType(type);
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("categories", categories);
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@Transactional
|
||||
public JsonResponse store(@RequestBody @Validated ResourceRequest req) {
|
||||
String disk = req.getDisk();
|
||||
if (!Arrays.asList(BackendConstant.RESOURCE_DISK_WHITELIST).contains(disk)) {
|
||||
return JsonResponse.error("存储磁盘参数错误");
|
||||
}
|
||||
String extension = req.getExtension().toLowerCase();
|
||||
String type = BackendConstant.RESOURCE_EXT_2_TYPE.get(extension);
|
||||
if (type == null) {
|
||||
return JsonResponse.error("格式不支持");
|
||||
}
|
||||
|
||||
// 如果是视频则必须传递duration参数
|
||||
Integer duration = req.getDuration();
|
||||
String poster = req.getPoster();
|
||||
boolean isVideoType = BackendConstant.RESOURCE_TYPE_VIDEO.equals(type);
|
||||
if (isVideoType) {
|
||||
if (duration == null || duration == 0) {
|
||||
return JsonResponse.error("duration参数必须存在且大于0");
|
||||
}
|
||||
if (poster == null || poster.trim().length() == 0) {
|
||||
return JsonResponse.error("poster参数值不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
Resource res = resourceService.create(
|
||||
req.getCategoryId(),
|
||||
type, req.getName(),
|
||||
extension,
|
||||
req.getSize(),
|
||||
disk,
|
||||
req.getFileId(),
|
||||
req.getPath(),
|
||||
req.getUrl()
|
||||
);
|
||||
|
||||
if (isVideoType) {
|
||||
resourceVideoService.create(res.getId(), duration, poster);
|
||||
}
|
||||
|
||||
return JsonResponse.data(res);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public JsonResponse destroy(@PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||
|
||||
Reference in New Issue
Block a user