fix: package 接口url增加 workspaceId path 参数

This commit is contained in:
zhangshuai
2024-08-09 10:25:11 +08:00
parent 2945c51b0f
commit 357ee0be62
3 changed files with 27 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
package net.geedge.asw.module.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.geedge.asw.common.util.R;
import net.geedge.asw.common.util.RCode;
@@ -12,53 +13,63 @@ import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/api/v1/package")
@RequestMapping("/api/v1/{workspaceId}/package")
public class PackageController {
@Autowired
private IPackageService packageService;
@GetMapping("/{id}")
public R detail(@PathVariable("id") String id) {
PackageEntity entity = packageService.getById(id);
public R detail(@PathVariable String workspaceId,
@PathVariable("id") String id) {
PackageEntity entity = packageService.getOne(new LambdaQueryWrapper<PackageEntity>()
.eq(PackageEntity::getId, id)
.eq(PackageEntity::getWorkspaceId, workspaceId));
return R.ok().putData("record", entity);
}
@GetMapping
public R list(@RequestParam Map<String, Object> params) {
public R list(@PathVariable String workspaceId,
@RequestParam Map<String, Object> params) {
T.VerifyUtil.is(params).notNull()
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
params.put("workspaceId", workspaceId);
Page page = packageService.queryList(params);
return R.ok(page);
}
@PostMapping
public R add(@RequestBody PackageEntity entity) {
public R add(@PathVariable String workspaceId,
@RequestBody PackageEntity entity) {
T.VerifyUtil.is(entity).notNull()
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
.and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY)
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
entity.setWorkspaceId(workspaceId);
PackageEntity pkgEntity = packageService.savePackage(entity);
return R.ok().putData("id", pkgEntity.getId());
}
@PutMapping
public R update(@RequestBody PackageEntity entity) {
public R update(@PathVariable String workspaceId,
@RequestBody PackageEntity entity) {
T.VerifyUtil.is(entity).notNull()
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
.and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY)
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
entity.setWorkspaceId(workspaceId);
PackageEntity pkgEntity = packageService.updatePackage(entity);
return R.ok().putData("id", pkgEntity.getId());
}
@DeleteMapping
public R delete(String[] ids) {
public R delete(@PathVariable String workspaceId,
String[] ids) {
T.VerifyUtil.is(ids).notEmpty();
packageService.removePackage(T.ListUtil.of(ids));
packageService.removePackage(T.ListUtil.of(ids), workspaceId);
return R.ok();
}

View File

@@ -15,5 +15,5 @@ public interface IPackageService extends IService<PackageEntity>{
PackageEntity updatePackage(PackageEntity entity);
void removePackage(List<String> ids);
void removePackage(List<String> ids, String workspaceId);
}

View File

@@ -80,9 +80,11 @@ public class PackageServiceImpl extends ServiceImpl<PackageDao, PackageEntity> i
@Override
@Transactional(rollbackFor = Exception.class)
public void removePackage(List<String> ids) {
public void removePackage(List<String> ids, String workspaceId) {
// remove
this.removeBatchByIds(ids);
this.remove(new LambdaQueryWrapper<PackageEntity>()
.eq(PackageEntity::getWorkspaceId, workspaceId)
.in(PackageEntity::getId, ids));
// workbook resource
workbookResourceService.removeResource(ids, WorkbookConstant.ResourceType.PACKAGE.getValue());
}