试验逻辑删除
This commit is contained in:
@@ -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<User> {
|
||||||
|
@Override
|
||||||
|
public void execute(LifeCycleHookBinding.Operation operation, LifeCycleHookBinding.TransactionPhase phase, User user, RequestScope scope, Optional<ChangeSpec> changes) {
|
||||||
|
log.info("Operation: {}, Phase: {}, User: {}, Scope: {}, Changes: {}", operation, phase, user, scope, changes);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity;
|
package com.lanyuanxiaoyao.server.entity;
|
||||||
|
|
||||||
import com.yahoo.elide.annotation.Include;
|
import com.yahoo.elide.annotation.Include;
|
||||||
|
import com.yahoo.elide.annotation.LifeCycleHookBinding;
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.ConstraintMode;
|
import jakarta.persistence.ConstraintMode;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
@@ -15,6 +16,9 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
import org.hibernate.annotations.SQLRestriction;
|
||||||
|
import org.hibernate.annotations.SoftDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
@@ -26,6 +30,7 @@ import org.hibernate.annotations.DynamicUpdate;
|
|||||||
@Entity
|
@Entity
|
||||||
@DynamicUpdate
|
@DynamicUpdate
|
||||||
@Include
|
@Include
|
||||||
|
@SoftDelete
|
||||||
public class User {
|
public class User {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.UUID)
|
@GeneratedValue(strategy = GenerationType.UUID)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
### Query
|
### Query
|
||||||
GET http://localhost:8080/json/school
|
GET http://localhost:8080/json/school?include=users
|
||||||
Content-Type: application/vnd.api+json
|
Content-Type: application/vnd.api+json
|
||||||
|
|
||||||
### Create
|
### Create
|
||||||
@@ -30,4 +30,4 @@ Content-Type: application/vnd.api+json
|
|||||||
}
|
}
|
||||||
|
|
||||||
### Delete
|
### Delete
|
||||||
DELETE http://localhost:8080/json/school/f424701d-dc94-42be-b2e6-79221b18ee7d
|
DELETE http://localhost:8080/json/school/bd80714e-7345-4d65-97ae-3339c16b0275
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
### Query
|
### 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
|
Content-Type: application/vnd.api+json
|
||||||
|
|
||||||
### Create
|
### Create
|
||||||
@@ -10,8 +10,16 @@ Content-Type: application/vnd.api+json
|
|||||||
"data": {
|
"data": {
|
||||||
"type": "user",
|
"type": "user",
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"username": "tony",
|
"username": "tony3",
|
||||||
"password": "tony"
|
"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
|
||||||
DELETE http://localhost:8080/json/user/f424701d-dc94-42be-b2e6-79221b18ee7d
|
DELETE http://localhost:8080/json/user/6cdd308e-8cab-4376-a0db-5dc6f7c9e0cd
|
||||||
|
|||||||
Reference in New Issue
Block a user