Skip to content

Commit

Permalink
[ADD] 新增应用管理及其单元测试
Browse files Browse the repository at this point in the history
1. 新增 ApplicationController
2. 新增 TestApplicationController 单元测试
3. 应用模块改为应用路由,独立表存储改为JSON存储

Signed-off-by: Alan Yeh <[email protected]>
  • Loading branch information
alan-yeh committed Nov 23, 2024
1 parent a8eb277 commit 6f03cb6
Show file tree
Hide file tree
Showing 46 changed files with 1,119 additions and 2,317 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* 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.saas.controller;

import central.bean.Page;
import central.data.saas.Application;
import central.starter.web.param.IdsParams;
import central.starter.web.query.IdQuery;
import central.studio.dashboard.controller.saas.param.ApplicationParams;
import central.studio.dashboard.controller.saas.query.ApplicationPageQuery;
import central.studio.dashboard.logic.saas.ApplicationLogic;
import central.validation.group.Insert;
import central.validation.group.Update;
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.*;

/**
* Application Controller
* <p>
* 应用管理
*
* @author Alan Yeh
* @since 2024/11/19
*/
@RestController
@RequiresAuthentication
@RequestMapping("/dashboard/api/saas/applications")
public class ApplicationController {

public interface Permissions {
String VIEW = "saas:application:view";
String ADD = "saas:application:add";
String EDIT = "saas:application:edit";
String DELETE = "saas:application:delete";
String ENABLE = "saas:application:enable";
String DISABLE = "saas:application:disable";
}

@Setter(onMethod_ = @Autowired)
private ApplicationLogic logic;

/**
* 按条件分页查询列表
*
* @param query 查询
* @return 分页结果
*/
@GetMapping("/page")
public Page<Application> page(@Validated ApplicationPageQuery query) {
return this.logic.pageBy(query.getPageIndex(), query.getPageSize(), query.build(), null);
}

/**
* 根据主键查询详情
*
* @param query 查询
* @return 详情
*/
@GetMapping("/details")
public Application details(@Validated IdQuery<Application> query) {
return this.logic.findById(query.getId());
}

/**
* 更新行政数据
*
* @param params 数据入参
* @param accountId 当前登录帐号
* @return 新增后的数据
*/
@PostMapping
public Application add(@RequestBody @Validated({Insert.class, Default.class}) ApplicationParams params, @RequestAttribute String accountId) {
return this.logic.insert(params.toInput(), accountId);
}

/**
* 更新数据
*
* @param params 数据入参
* @param accountId 当前登录帐号
* @return 更新后的数据
*/
@PutMapping
public Application update(@RequestBody @Validated({Update.class, Default.class}) ApplicationParams params, @RequestAttribute String accountId) {
return this.logic.update(params.toInput(), accountId);
}

/**
* 根据主键删除数据
*
* @param params 待删除主键列表
* @param accountId 当前登录帐号
* @return 受影响数据行数
*/
@DeleteMapping
public long delete(@Validated IdsParams params, @RequestAttribute String accountId) {
return this.logic.deleteByIds(params.getIds(), accountId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.saas.param;

import central.data.saas.ApplicationInput;
import central.util.Listx;
import central.validation.Label;
import central.validation.group.Insert;
import central.validation.group.Update;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* Application Params
* <p>
* 应用数据入参
*
* @author Alan Yeh
* @since 2024/11/19
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ApplicationParams {

@Label("主键")
@Null(groups = Insert.class)
@NotBlank(groups = Update.class)
@Size(min = 1, max = 32, groups = Insert.class)
private String id;

@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(max = 2 * 1024 * 1024)
private String logo;

@Label("上下文路径")
@NotBlank
@Size(min = 1, max = 64)
private String contextPath;

@Label("服务地址")
@NotBlank
@Size(min = 1, max = 1024)
private String url;

@Label("密钥")
@NotBlank
@Size(min = 1, max = 32)
private String secret;

@Label("是否启用")
@NotNull
private Boolean enabled;

@Label("备注")
@Size(max = 1024)
private String remark;

@Valid
@Label("路由")
private List<ApplicationRouteParams> routes;

public ApplicationInput toInput() {
return ApplicationInput.builder()
.id(this.getId())
.code(this.getCode())
.name(this.getName())
.logo(this.getLogo())
.url(this.getUrl())
.contextPath(this.getContextPath())
.secret(this.getSecret())
.enabled(this.getEnabled())
.remark(this.getRemark())
.routes(Listx.asStream(this.getRoutes()).map(ApplicationRouteParams::toInput).toList())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,42 @@
* SOFTWARE.
*/

package central.studio.provider.graphql.saas.entity;
package central.studio.dashboard.controller.saas.param;

import central.data.saas.ApplicationModuleInput;
import central.sql.data.ModifiableEntity;
import central.sql.meta.annotation.Relation;
import central.data.saas.ApplicationRouteInput;
import central.validation.Label;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;

/**
* 应用模块信息
* Application Module Params
* <p>
* 应用路由参数
*
* @author Alan Yeh
* @since 2022/09/25
* @since 2024/11/19
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "X_SAAS_APPLICATION_MODULE")
@EqualsAndHashCode(callSuper = true)
@Relation(alias = "application", target = ApplicationEntity.class, property = "applicationId")
public class ApplicationModuleEntity extends ModifiableEntity {
@Serial
private static final long serialVersionUID = 7015722509704015462L;

@Id
@Label("主键")
@Size(max = 32)
private String id;
public class ApplicationRouteParams {

@Label("所属应用主键")
@Label("上下文路径")
@NotBlank
@Size(min = 1, max = 32)
private String applicationId;
@Size(min = 1, max = 64)
private String contextPath;

@Label("服务地址")
@NotBlank
@Size(min = 1, max = 1024)
private String url;

@Label("上下文路径")
@NotBlank
@Size(min = 1, max = 64)
private String contextPath;

@Label("是否启用")
@NotNull
private Boolean enabled;
Expand All @@ -84,12 +66,12 @@ public class ApplicationModuleEntity extends ModifiableEntity {
@Size(max = 1024)
private String remark;

public void fromInput(ApplicationModuleInput input) {
this.setId(input.getId());
this.setApplicationId(input.getApplicationId());
this.setUrl(input.getUrl());
this.setContextPath(input.getContextPath());
this.setEnabled(input.getEnabled());
this.setRemark(input.getRemark());
public ApplicationRouteInput toInput() {
return ApplicationRouteInput.builder()
.contextPath(this.getContextPath())
.url(this.getUrl())
.enabled(this.getEnabled())
.remark(this.getRemark())
.build();
}
}
Loading

0 comments on commit 6f03cb6

Please sign in to comment.