refactor: export API returns JSON with download URL, add FileCacheService

This commit is contained in:
agentuser
2026-05-11 16:30:55 +08:00
parent e107e1eb92
commit 318a5bdf7a
7 changed files with 329 additions and 41 deletions
@@ -1,6 +1,5 @@
package com.gmp.mock.handler;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.http.ResponseEntity;
@@ -8,23 +7,24 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import com.gmp.mock.dto.ApiResponse;
import com.gmp.mock.service.TemplateNotFoundException;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<Map<String, Object>> handleValidation(MethodArgumentNotValidException ex) {
public ResponseEntity<ApiResponse<Void>> handleValidation(MethodArgumentNotValidException ex) {
String message = ex.getBindingResult().getFieldErrors().stream()
.map(e -> e.getDefaultMessage())
.collect(Collectors.joining("; "));
return ResponseEntity.badRequest()
.body(Map.of("code", 400, "msg", message));
.body(ApiResponse.error(400, message));
}
@ExceptionHandler(TemplateNotFoundException.class)
public ResponseEntity<Map<String, Object>> handleTemplateNotFound(TemplateNotFoundException ex) {
public ResponseEntity<ApiResponse<Void>> handleTemplateNotFound(TemplateNotFoundException ex) {
return ResponseEntity.status(404)
.body(Map.of("code", 404, "msg", ex.getMessage()));
.body(ApiResponse.error(404, ex.getMessage()));
}
}