diff --git a/src/main/java/com/lanyuanxiaoyao/server/entity/LogicDeletedHook.java b/src/main/java/com/lanyuanxiaoyao/server/entity/LogicDeletedHook.java new file mode 100644 index 0000000..35e8cd3 --- /dev/null +++ b/src/main/java/com/lanyuanxiaoyao/server/entity/LogicDeletedHook.java @@ -0,0 +1,21 @@ +package com.lanyuanxiaoyao.server.entity; + +import com.yahoo.elide.annotation.LifeCycleHookBinding; +import com.yahoo.elide.core.lifecycle.CRUDEvent; +import com.yahoo.elide.core.lifecycle.LifeCycleHook; +import com.yahoo.elide.core.security.ChangeSpec; +import com.yahoo.elide.core.security.RequestScope; +import java.util.Optional; +import lombok.extern.slf4j.Slf4j; + +/** + * @author lanyuanxiaoyao + * @version 20250304 + */ +@Slf4j +public class LogicDeletedHook implements LifeCycleHook { + @Override + public void execute(LifeCycleHookBinding.Operation operation, LifeCycleHookBinding.TransactionPhase phase, User user, RequestScope scope, Optional changes) { + log.info("Operation: {}, Phase: {}, User: {}, Scope: {}, Changes: {}", operation, phase, user, scope, changes); + } +} diff --git a/src/main/java/com/lanyuanxiaoyao/server/entity/User.java b/src/main/java/com/lanyuanxiaoyao/server/entity/User.java index da17426..94613a7 100644 --- a/src/main/java/com/lanyuanxiaoyao/server/entity/User.java +++ b/src/main/java/com/lanyuanxiaoyao/server/entity/User.java @@ -1,6 +1,7 @@ package com.lanyuanxiaoyao.server.entity; import com.yahoo.elide.annotation.Include; +import com.yahoo.elide.annotation.LifeCycleHookBinding; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; @@ -15,6 +16,9 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.annotations.SQLRestriction; +import org.hibernate.annotations.SoftDelete; +import org.hibernate.annotations.Where; /** * @author lanyuanxiaoyao @@ -26,6 +30,7 @@ import org.hibernate.annotations.DynamicUpdate; @Entity @DynamicUpdate @Include +@SoftDelete public class User { @Id @GeneratedValue(strategy = GenerationType.UUID) diff --git a/src/test/resources/school.http b/src/test/resources/school.http index 0ca6725..ff98872 100644 --- a/src/test/resources/school.http +++ b/src/test/resources/school.http @@ -1,5 +1,5 @@ ### Query -GET http://localhost:8080/json/school +GET http://localhost:8080/json/school?include=users Content-Type: application/vnd.api+json ### Create @@ -30,4 +30,4 @@ Content-Type: application/vnd.api+json } ### Delete -DELETE http://localhost:8080/json/school/f424701d-dc94-42be-b2e6-79221b18ee7d +DELETE http://localhost:8080/json/school/bd80714e-7345-4d65-97ae-3339c16b0275 diff --git a/src/test/resources/user.http b/src/test/resources/user.http index 1f47abe..b1b2645 100644 --- a/src/test/resources/user.http +++ b/src/test/resources/user.http @@ -1,5 +1,5 @@ ### Query -GET http://localhost:8080/json/user?sort=-username&page[number]=1&page[size]=10&filter[user]=username==lanyuan* +GET http://localhost:8080/json/user?include=school&fields[user]=username,school&fields[school]=name Content-Type: application/vnd.api+json ### Create @@ -10,8 +10,16 @@ Content-Type: application/vnd.api+json "data": { "type": "user", "attributes": { - "username": "tony", + "username": "tony3", "password": "tony" + }, + "relationships": { + "school": { + "data": { + "type": "school", + "id": "bd80714e-7345-4d65-97ae-3339c16b0275" + } + } } } } @@ -42,4 +50,4 @@ Content-Type: application/vnd.api+json } ### Delete -DELETE http://localhost:8080/json/user/f424701d-dc94-42be-b2e6-79221b18ee7d +DELETE http://localhost:8080/json/user/6cdd308e-8cab-4376-a0db-5dc6f7c9e0cd