-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] 新增 StorageBucketController 及对应的单元测试
Signed-off-by: Alan Yeh <[email protected]>
- Loading branch information
Showing
6 changed files
with
768 additions
and
1 deletion.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
...rc/main/java/central/studio/dashboard/controller/storage/controller/BucketController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022-present Alan Yeh <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package central.studio.dashboard.controller.storage.controller; | ||
|
||
import central.bean.Page; | ||
import central.data.storage.StorageBucket; | ||
import central.starter.web.param.IdsParams; | ||
import central.starter.web.query.IdQuery; | ||
import central.studio.dashboard.controller.storage.param.BucketParams; | ||
import central.studio.dashboard.controller.storage.query.BucketPageQuery; | ||
import central.studio.dashboard.logic.storage.StorageLogic; | ||
import central.validation.group.Insert; | ||
import central.validation.group.Update; | ||
import central.web.XForwardedHeaders; | ||
import jakarta.validation.groups.Default; | ||
import lombok.Setter; | ||
import org.apache.shiro.authz.annotation.RequiresAuthentication; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* Storage Bucket Controller | ||
* <p> | ||
* 存储桶管理 | ||
* | ||
* @author Alan Yeh | ||
* @since 2024/10/29 | ||
*/ | ||
@RestController | ||
@RequiresAuthentication | ||
@RequestMapping("/dashboard/api/storage/buckets") | ||
public class BucketController { | ||
|
||
public interface Permissions { | ||
String VIEW = "storage:bucket:view"; | ||
String ADD = "storage:bucket:add"; | ||
String EDIT = "storage:bucket:edit"; | ||
String DELETE = "storage:bucket:delete"; | ||
String ENABLE = "storage:bucket:enable"; | ||
String DISABLE = "storage:bucket:disable"; | ||
} | ||
|
||
@Setter(onMethod_ = @Autowired) | ||
private StorageLogic logic; | ||
|
||
/** | ||
* 按条件分页查询列表 | ||
* | ||
* @param query 查询 | ||
* @param tenant 租户标识 | ||
* @return 列表结果 | ||
*/ | ||
@GetMapping("/page") | ||
public Page<StorageBucket> page(@Validated BucketPageQuery query, @RequestHeader(XForwardedHeaders.TENANT) String tenant) { | ||
return this.logic.pageBy(query.getPageIndex(), query.getPageSize(), query.build(), null, tenant); | ||
} | ||
|
||
/** | ||
* 根据主键查询详情 | ||
* | ||
* @param query 查询 | ||
* @param tenant 租户标识 | ||
* @return 详情 | ||
*/ | ||
@GetMapping("/details") | ||
public StorageBucket details(@Validated IdQuery<StorageBucket> query, @RequestHeader(XForwardedHeaders.TENANT) String tenant) { | ||
return this.logic.findById(query.getId(), tenant); | ||
} | ||
|
||
/** | ||
* 更新行政数据 | ||
* | ||
* @param params 数据入参 | ||
* @param accountId 当前登录帐号 | ||
* @param tenant 租户标识 | ||
* @return 新增后的数据 | ||
*/ | ||
@PostMapping | ||
public StorageBucket add(@RequestBody @Validated({Insert.class, Default.class}) BucketParams params, @RequestAttribute String accountId, @RequestHeader(XForwardedHeaders.TENANT) String tenant) { | ||
return this.logic.insert(params.toInput(), accountId, tenant); | ||
} | ||
|
||
/** | ||
* 更新数据 | ||
* | ||
* @param params 数据入参 | ||
* @param accountId 当前登录帐号 | ||
* @param tenant 租户标识 | ||
* @return 更新后的数据 | ||
*/ | ||
@PutMapping | ||
public StorageBucket update(@RequestBody @Validated({Update.class, Default.class}) BucketParams params, @RequestAttribute String accountId, @RequestHeader(XForwardedHeaders.TENANT) String tenant) { | ||
return this.logic.update(params.toInput(), accountId, tenant); | ||
} | ||
|
||
/** | ||
* 根据主键删除数据 | ||
* | ||
* @param params 待删除主键列表 | ||
* @param accountId 当前登录帐号 | ||
* @param tenant 租户标识 | ||
* @return 受影响数据行数 | ||
*/ | ||
@DeleteMapping | ||
public long delete(@Validated IdsParams params, @RequestAttribute String accountId, @RequestHeader(XForwardedHeaders.TENANT) String tenant) { | ||
return this.logic.deleteByIds(params.getIds(), accountId, tenant); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...shboard/src/main/java/central/studio/dashboard/controller/storage/param/BucketParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022-present Alan Yeh <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package central.studio.dashboard.controller.storage.param; | ||
|
||
import central.data.storage.StorageBucketInput; | ||
import central.validation.Label; | ||
import central.validation.group.Insert; | ||
import central.validation.group.Update; | ||
import jakarta.validation.constraints.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Storage Bucket Params | ||
* <p> | ||
* 存储桶入参 | ||
* | ||
* @author Alan Yeh | ||
* @since 2024/10/29 | ||
*/ | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class BucketParams { | ||
|
||
@Label("主键") | ||
@Null(groups = Insert.class) | ||
@NotBlank(groups = Update.class) | ||
@Size(min = 1, max = 32, groups = Insert.class) | ||
private String id; | ||
|
||
@Label("应用主键") | ||
@NotNull | ||
@Size(min = 1, max = 32) | ||
private String applicationId; | ||
|
||
@Label("标识") | ||
@NotBlank | ||
@Size(min = 1, max = 32) | ||
@Pattern(regexp = "^[0-9a-zA-Z_-]+$", message = "${label}[${property}]只能由数字、英文字母、中划线、下划线组成") | ||
@Pattern(regexp = "^(?!-)(?!_).*$", message = "${label}[${property}]不能由中划线或下划线开头") | ||
@Pattern(regexp = "^(?!.*?[-_]$).*$", message = "${label}[${property}]不能由中划线或下划线结尾") | ||
@Pattern(regexp = "^(?!.*(--).*$).*$", message = "${label}[${property}]不能出现连续中划线") | ||
@Pattern(regexp = "^(?!.*(__).*$).*$", message = "${label}[${property}]不能出现连续下划线") | ||
@Pattern(regexp = "^(?!.*(-_|_-).*$).*$", message = "${label}[${property}]不能出现连续中划线、下划线") | ||
private String code; | ||
|
||
@Label("名称") | ||
@NotBlank | ||
@Size(min = 1, max = 50) | ||
private String name; | ||
|
||
@Label("类型") | ||
@NotBlank | ||
@Size(min = 1, max = 32) | ||
private String type; | ||
|
||
@Label("是否启用") | ||
@NotNull | ||
private Boolean enabled; | ||
|
||
@Label("备注") | ||
@Size(max = 1024) | ||
private String remark; | ||
|
||
@Label("初始化参数") | ||
@NotNull | ||
@Size(min = 1, max = 5 * 1024 * 1024) | ||
private String params; | ||
|
||
public StorageBucketInput toInput() { | ||
return StorageBucketInput.builder() | ||
.id(this.getId()) | ||
.applicationId(this.getApplicationId()) | ||
.code(this.getCode()) | ||
.name(this.getName()) | ||
.type(this.getType()) | ||
.enabled(this.getEnabled()) | ||
.remark(this.getRemark()) | ||
.params(this.getParams()) | ||
.build(); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...oard/src/main/java/central/studio/dashboard/controller/storage/query/BucketPageQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022-present Alan Yeh <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package central.studio.dashboard.controller.storage.query; | ||
|
||
import central.data.organization.option.AreaType; | ||
import central.data.storage.StorageBucket; | ||
import central.lang.Stringx; | ||
import central.sql.query.Conditions; | ||
import central.starter.web.query.PageQuery; | ||
import central.validation.Enums; | ||
import central.validation.Label; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
import java.io.Serial; | ||
|
||
/** | ||
* @author Alan Yeh | ||
* @since 2024/10/29 | ||
*/ | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class BucketPageQuery extends PageQuery<StorageBucket> { | ||
Check warning on line 45 in central-dashboard/src/main/java/central/studio/dashboard/controller/storage/query/BucketPageQuery.java
|
||
@Serial | ||
private static final long serialVersionUID = -5018132706306974456L; | ||
|
||
@Label("主键") | ||
private String id; | ||
|
||
@Label("应用主键") | ||
private String applicationId; | ||
|
||
@Label("名称") | ||
private String name; | ||
|
||
@Label("区划代码") | ||
private String code; | ||
|
||
@Label("类型") | ||
@Enums(value = AreaType.class) | ||
private String type; | ||
|
||
@Override | ||
public Conditions<StorageBucket> build() { | ||
var conditions = Conditions.of(StorageBucket.class); | ||
|
||
// 精确字段搜索 | ||
if (Stringx.isNotEmpty(this.getId())) { | ||
conditions.eq(StorageBucket::getId, this.getId()); | ||
} | ||
if (Stringx.isNotEmpty(this.getApplicationId())) { | ||
conditions.eq(StorageBucket::getApplicationId, this.getApplicationId()); | ||
} | ||
if (Stringx.isNotEmpty(this.getName())) { | ||
conditions.like(StorageBucket::getName, this.getName()); | ||
} | ||
if (Stringx.isNotEmpty(this.getCode())) { | ||
conditions.like(StorageBucket::getCode, this.getCode()); | ||
} | ||
|
||
// 模糊搜索 | ||
for (String keyword : this.getKeywords()) { | ||
conditions.and(filter -> filter.like(StorageBucket::getCode, keyword).or().like(StorageBucket::getName, keyword)); | ||
} | ||
return conditions; | ||
} | ||
} |
Oops, something went wrong.