-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathAppController.java
More file actions
213 lines (199 loc) · 8.37 KB
/
AppController.java
File metadata and controls
213 lines (199 loc) · 8.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
package com.tinyengine.it.controller;
import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.common.log.SystemControllerLog;
import com.tinyengine.it.model.entity.App;
import com.tinyengine.it.service.app.AppService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 应用api
*
* @since 2024-10-20
*/
@Validated
@RestController
@RequestMapping("/app-center/api")
@Tag(name = "应用")
public class AppController {
/**
* The App service.
*/
@Autowired
private AppService appService;
/**
* 查询表App信息
*
* @return App信息 all app
*/
@Operation(summary = "查询表App信息",
description = "查询表App信息",
responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = App.class))),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "查询表App信息")
@GetMapping("/apps/list")
public Result<List<App>> getAllApp() {
List<App> appList = appService.queryAllApp();
return Result.success(appList);
}
/**
* 根据id查询表App信息
*
* @param id the id
* @return App信息 app by id
*/
@Operation(summary = "根据id查询表App信息",
description = "根据id查询表App信息",
parameters = {
@Parameter(name = "id", description = "App主键id")
},
responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = App.class))),
@ApiResponse(responseCode = "400", description = "请求失败")}
)
@SystemControllerLog(description = "根据id查询表App信息")
@GetMapping("/apps/{id}")
public Result<App> getAppById(@PathVariable Integer id) {
return appService.queryAppById(id);
}
/**
* 创建App
*
* @param app the app
* @return App信息 result
*/
@Operation(summary = "创建app",
description = "创建app",
parameters = {
@Parameter(name = "app", description = "App入参对象")
},
responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = App.class))),
@ApiResponse(responseCode = "400", description = "请求失败")}
)
@SystemControllerLog(description = "创建app")
@PostMapping("/apps/create")
public Result<App> createApp(@Valid @RequestBody App app) {
return appService.createApp(app);
}
/**
* 修改App信息
*
* @param id the id
* @param app the app
* @return App信息 result
*/
@Operation(summary = "修改单个App信息", description = "修改单个App信息", parameters = {
@Parameter(name = "id", description = "appId"),
@Parameter(name = "App", description = "入参对象")}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = App.class))),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "修改单个App信息")
@PostMapping("/apps/update/{id}")
public Result<App> updateApp(@PathVariable Integer id, @RequestBody App app) {
app.setId(id);
return appService.updateAppById(app);
}
/**
* 删除App信息
*
* @param id the id
* @return app信息 result
*/
@Operation(summary = "删除app信息",
description = "删除app信息",
parameters = {
@Parameter(name = "id", description = "App主键id")
},
responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = App.class))),
@ApiResponse(responseCode = "400", description = "请求失败")}
)
@SystemControllerLog(description = "删除app信息")
@GetMapping("/apps/delete/{id}")
public Result<App> deleteApp(@PathVariable Integer id) {
return appService.deleteAppById(id);
}
/**
* 获取应用信息详情
*
* @param id the id
* @return the result
*/
@Operation(summary = "获取应用信息详情", description = "获取应用信息详情", parameters = {
@Parameter(name = "id", description = "appId")}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = App.class))),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "获取应用信息详情")
@GetMapping("/apps/detail/{id}")
public Result<App> detail(@PathVariable Integer id) {
return appService.queryAppById(id);
}
/**
* 修改应用对应的国际化语种关联
*
* @param id the id
* @param param the param
* @return the result
*/
@Operation(summary = "修改应用对应的国际化语种关联", description = "修改应用对应的国际化语种关联", parameters = {
@Parameter(name = "id", description = "appId"),
@Parameter(name = "param", description = "入参对象")}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = App.class))),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "修改应用对应的国际化语种关联")
@PostMapping("/apps/i18n/{id}")
public Result<App> updateI18n(@PathVariable Integer id, @RequestBody Map<String, Object> param) {
if (param.get("i18n_langs") == null) {
return Result.failed("i18n_langs 是必须的");
}
// 判断参数i18n_langs是不是数组且是数字
boolean isAreNumbers = Arrays.stream((int[]) param.get("i18n_langs")).allMatch(Integer.class::isInstance);
if (!isAreNumbers) {
return Result.failed("i18n_langs[0] should be a number");
}
// needTODO 对于传参进行修改逻辑存疑
return Result.failed("修改应用对应的国际化语种关联接口逻辑存疑");
}
}