refactor: SubmitResult sealed接口强类型替代ApiResponse<Object>
This commit is contained in:
@@ -3,6 +3,7 @@ package com.par.api.controller;
|
||||
import com.par.core.dto.AccessResultDTO;
|
||||
import com.par.core.dto.ApiResponse;
|
||||
import com.par.core.dto.SiteAccessSummaryDTO;
|
||||
import com.par.core.dto.SubmitResult;
|
||||
import com.par.core.entity.AccessResult;
|
||||
import com.par.core.service.AccessResultService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -30,7 +31,7 @@ public class AccessResultController {
|
||||
* mediabot 提交访问站点的返回数据
|
||||
*/
|
||||
@PostMapping("/api/v1/sites/{siteId}/access-result")
|
||||
public ApiResponse<Object> submitAccessResult(
|
||||
public ApiResponse<SubmitResult> submitAccessResult(
|
||||
@PathVariable("siteId") String siteId,
|
||||
@RequestBody Map<String, Object> payload,
|
||||
HttpServletRequest request) {
|
||||
@@ -58,9 +59,9 @@ public class AccessResultController {
|
||||
AccessResult result = accessResultService.submit(
|
||||
siteId, configVersion, clientId, contentType, content,
|
||||
url, statusCode, responseTimeMs, submitterId);
|
||||
return ApiResponse.success(accessResultService.toDTO(result));
|
||||
return ApiResponse.success(new SubmitResult.Success(accessResultService.toDTO(result)));
|
||||
} catch (com.par.core.exception.DuplicateSubmissionException e) {
|
||||
return ApiResponse.success(Map.of("skipped", true, "reason", "duplicate"));
|
||||
return ApiResponse.success(new SubmitResult.Skipped("duplicate"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
par-core/src/main/java/com/par/core/dto/SubmitResult.java
Normal file
13
par-core/src/main/java/com/par/core/dto/SubmitResult.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.par.core.dto;
|
||||
|
||||
/**
|
||||
* 访问结果提交返回类型,统一处理"正常存储"和"去重跳过"两种场景
|
||||
*/
|
||||
public sealed interface SubmitResult permits SubmitResult.Success, SubmitResult.Skipped {
|
||||
|
||||
/** 正常存储,返回 DTO */
|
||||
record Success(AccessResultDTO dto) implements SubmitResult {}
|
||||
|
||||
/** 内容重复,跳过存储 */
|
||||
record Skipped(String reason) implements SubmitResult {}
|
||||
}
|
||||
Reference in New Issue
Block a user