feat(v1): unify API response, validation, exception handling and tests

This commit is contained in:
likingcode
2026-03-08 14:40:30 +00:00
parent 539dc41868
commit 6a4c6a369a
10 changed files with 216 additions and 73 deletions

View File

@@ -0,0 +1,22 @@
package com.example.demo.common;
import java.time.Instant;
public record ApiResponse<T>(
int code,
String message,
T data,
Instant timestamp
) {
public static <T> ApiResponse<T> ok(T data) {
return new ApiResponse<>(0, "success", data, Instant.now());
}
public static <T> ApiResponse<T> ok(String message, T data) {
return new ApiResponse<>(0, message, data, Instant.now());
}
public static ApiResponse<Void> fail(int code, String message) {
return new ApiResponse<>(code, message, null, Instant.now());
}
}