2026-04-27 10:27:57 +08:00
|
|
|
package com.labelsys.backend.controller;
|
|
|
|
|
|
|
|
|
|
import com.labelsys.backend.common.Result;
|
|
|
|
|
import com.labelsys.backend.context.UserContext;
|
|
|
|
|
import com.labelsys.backend.dto.common.PageResult;
|
|
|
|
|
import com.labelsys.backend.dto.request.SourceResourcePageQuery;
|
|
|
|
|
import com.labelsys.backend.dto.request.SourceUploadRequest;
|
|
|
|
|
import com.labelsys.backend.dto.response.SourceResourceResponse;
|
|
|
|
|
import com.labelsys.backend.dto.response.SourceUploadResponse;
|
|
|
|
|
import com.labelsys.backend.service.SourceResourceService;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
2026-04-27 16:25:39 +08:00
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
2026-04-27 10:27:57 +08:00
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
2026-04-27 16:25:39 +08:00
|
|
|
import org.springdoc.core.annotations.ParameterObject;
|
2026-04-27 10:27:57 +08:00
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
@Tag(name = "资源管理")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/source-resources")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class SourceResourceController {
|
|
|
|
|
|
|
|
|
|
private final SourceResourceService sourceResourceService;
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "上传资源")
|
|
|
|
|
@PostMapping("/upload")
|
2026-04-27 16:25:39 +08:00
|
|
|
public Result<SourceUploadResponse> upload(@ParameterObject @ModelAttribute SourceUploadRequest request) {
|
2026-04-27 10:27:57 +08:00
|
|
|
return Result.success(sourceResourceService.upload(UserContext.requireUser(), request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "分页查询资源")
|
|
|
|
|
@GetMapping
|
2026-04-27 16:25:39 +08:00
|
|
|
public Result<PageResult<SourceResourceResponse>> page(@ParameterObject SourceResourcePageQuery query) {
|
2026-04-27 10:27:57 +08:00
|
|
|
return Result.success(sourceResourceService.pageResources(UserContext.requireUser(), query));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "查询资源详情")
|
|
|
|
|
@GetMapping("/{id}")
|
2026-04-27 16:25:39 +08:00
|
|
|
public Result<SourceResourceResponse> detail(
|
|
|
|
|
@Parameter(description = "资源ID", example = "191000000000000101")
|
|
|
|
|
@PathVariable Long id
|
|
|
|
|
) {
|
2026-04-27 10:27:57 +08:00
|
|
|
return Result.success(sourceResourceService.getResource(UserContext.requireUser(), id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除资源")
|
|
|
|
|
@DeleteMapping("/{id}")
|
2026-04-27 16:25:39 +08:00
|
|
|
public Result<Void> delete(
|
|
|
|
|
@Parameter(description = "资源ID", example = "191000000000000101")
|
|
|
|
|
@PathVariable Long id
|
|
|
|
|
) {
|
2026-04-27 10:27:57 +08:00
|
|
|
sourceResourceService.deleteResource(UserContext.requireUser(), id);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
}
|