75 行
3.2 KiB
Java
75 行
3.2 KiB
Java
|
|
package com.xuqm.update.controller;
|
||
|
|
|
||
|
|
import com.xuqm.common.model.ApiResponse;
|
||
|
|
import com.xuqm.update.entity.AppPublishConfigEntity;
|
||
|
|
import com.xuqm.update.service.ConnectivityValidationService;
|
||
|
|
import com.xuqm.update.service.PublishConfigService;
|
||
|
|
import org.springframework.http.ResponseEntity;
|
||
|
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/api/v1/updates")
|
||
|
|
public class PublishConfigController {
|
||
|
|
|
||
|
|
private final PublishConfigService publishConfigService;
|
||
|
|
private final ConnectivityValidationService connectivityValidationService;
|
||
|
|
|
||
|
|
public PublishConfigController(PublishConfigService publishConfigService,
|
||
|
|
ConnectivityValidationService connectivityValidationService) {
|
||
|
|
this.publishConfigService = publishConfigService;
|
||
|
|
this.connectivityValidationService = connectivityValidationService;
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/publish/config")
|
||
|
|
public ResponseEntity<ApiResponse<AppPublishConfigEntity>> getConfig(@RequestParam String appId) {
|
||
|
|
return ResponseEntity.ok(ApiResponse.success(publishConfigService.getConfig(appId)));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/publish/config")
|
||
|
|
public ResponseEntity<ApiResponse<AppPublishConfigEntity>> saveConfig(
|
||
|
|
@RequestParam String appId,
|
||
|
|
@RequestBody Map<String, Object> body) {
|
||
|
|
validateCallbacks(body);
|
||
|
|
return ResponseEntity.ok(ApiResponse.success(publishConfigService.saveConfig(appId, body)));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/gray/members")
|
||
|
|
public ResponseEntity<ApiResponse<List<PublishConfigService.GrayMemberGroupView>>> listMembers(
|
||
|
|
@RequestParam String appId,
|
||
|
|
@RequestParam(required = false) String keyword,
|
||
|
|
@RequestParam(required = false) String groupName) {
|
||
|
|
return ResponseEntity.ok(ApiResponse.success(
|
||
|
|
publishConfigService.listGrayMembers(appId, keyword, groupName)));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/gray/members/sync")
|
||
|
|
public ResponseEntity<ApiResponse<List<PublishConfigService.GrayMemberGroupView>>> syncMembers(
|
||
|
|
@RequestParam String appId) {
|
||
|
|
return ResponseEntity.ok(ApiResponse.success(publishConfigService.syncGrayMembers(appId)));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/gray/members/import")
|
||
|
|
public ResponseEntity<ApiResponse<List<PublishConfigService.GrayMemberGroupView>>> importMembers(
|
||
|
|
@RequestParam String appId,
|
||
|
|
@RequestBody String payload) {
|
||
|
|
return ResponseEntity.ok(ApiResponse.success(publishConfigService.replaceGrayMembers(appId, payload)));
|
||
|
|
}
|
||
|
|
|
||
|
|
private void validateCallbacks(Map<String, Object> body) {
|
||
|
|
if (body == null) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
String selectCallback = body.get("graySelectCallbackUrl") == null ? "" : body.get("graySelectCallbackUrl").toString().trim();
|
||
|
|
String syncCallback = body.get("grayDirectorySyncCallbackUrl") == null ? "" : body.get("grayDirectorySyncCallbackUrl").toString().trim();
|
||
|
|
if (!selectCallback.isBlank()) {
|
||
|
|
connectivityValidationService.validateCallbackUrl(selectCallback, "灰度成员选择回调");
|
||
|
|
}
|
||
|
|
if (!syncCallback.isBlank()) {
|
||
|
|
connectivityValidationService.validateCallbackUrl(syncCallback, "灰度成员同步回调");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|