This commit is contained in:
2026-04-14 16:27:47 +08:00
commit 4b38a4c952
134 changed files with 7478 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.k12study</groupId>
<artifactId>k12study-backend</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>common-api</artifactId>
<dependencies>
<dependency>
<groupId>com.k12study</groupId>
<artifactId>common-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,31 @@
package com.k12study.common.api.response;
import com.k12study.common.core.utils.TraceIdHolder;
import lombok.Getter;
@Getter
public class ApiResponse<T> {
private final int code;
private final String message;
private final T data;
private final String traceId;
private ApiResponse(int code, String message, T data, String traceId) {
this.code = code;
this.message = message;
this.data = data;
this.traceId = traceId;
}
public static <T> ApiResponse<T> success(T data) {
return new ApiResponse<>(0, "OK", data, TraceIdHolder.getOrCreate());
}
public static <T> ApiResponse<T> success(String message, T data) {
return new ApiResponse<>(0, message, data, TraceIdHolder.getOrCreate());
}
public static <T> ApiResponse<T> failure(int code, String message) {
return new ApiResponse<>(code, message, null, TraceIdHolder.getOrCreate());
}
}