This commit is contained in:
Francesco
2023-10-01 09:02:54 +02:00
parent c7258e9968
commit 5b027be0d1
10 changed files with 90 additions and 15 deletions

View File

@@ -23,6 +23,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* Configuration class for the "internal" data source. Place in the root "internal"
* package so as to allow component scanning and detection of models and repositories.
*/
@ConditionalOnProperty(name = "dbadmin.enabled", matchIfMissing = true)
@ComponentScan
@Configuration

View File

@@ -31,8 +31,9 @@ import jakarta.persistence.Id;
import jakarta.persistence.Lob;
/**
* An action executed by any user from the web UI.
*
* An write operation executed by a user from the web UI. This class
* only holds metadata about the operation and not anything
* concrete yet (e.g. a diff or SQL query) about what change was performed.
*/
@Entity
public class UserAction {
@@ -40,22 +41,39 @@ public class UserAction {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/**
* The time at which the operation was perfomed
*/
@Column(nullable = false)
private LocalDateTime createdAt;
/**
* The SQL query generated by the operation.
* This field is here but it's NOT currently supported
*/
@Lob
@Column(nullable = false)
private String sql;
/**
* The full qualified name of the Entity class this operation
* occurred on.
*/
@Column(nullable = false)
private String javaClass;
/**
* The table name of the Entity class this operation occurred on.
*/
@Column(nullable = false)
private String onTable;
@Column(nullable = false)
private String primaryKey;
/**
* The action type (EDIT, CREATE or DELETE)
*/
@Column(nullable = false)
private String actionType;

View File

@@ -23,7 +23,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
/**
* A single variable in the settings.
* A single variable in the user settings.
*/
@Entity
public class UserSetting {

View File

@@ -0,0 +1,10 @@
/**
* This is the root package for the "internal" data source, i.e. not the data source
* that interacts with the user entities, but rather the one used internally by Spring
* Boot Database Admin in order to save information.
*
* Due to the way Spring Boot component scanning works, it is needed to create this package and the
* respective {@link tech.ailef.dbadmin.internal.InternalDbAdminConfiguration} in order to
* have the component scanning only pick the correct entities/repositories.
*/
package tech.ailef.dbadmin.internal;

View File

@@ -92,7 +92,7 @@ public class CustomActionRepositoryImpl implements CustomActionRepository {
/**
* Returns the count that match the filtering parameters, used for pagination.
* @return
* @return the number of user actions matching the filtering parameters
*/
@Override
public long countActions(String table, String actionType, String itemId) {

View File

@@ -33,6 +33,10 @@ import tech.ailef.dbadmin.internal.model.UserAction;
import tech.ailef.dbadmin.internal.repository.CustomActionRepositoryImpl;
import tech.ailef.dbadmin.internal.repository.UserActionRepository;
/**
* Service class to retrieve user actions through the {@link CustomActionRepositoryImpl}.
*
*/
@Service
public class UserActionService {
@Autowired
@@ -46,6 +50,11 @@ public class UserActionService {
return repo.save(a);
}
/**
* Retruns a page of results of user actions that match the given input request.
* @param request a request containing filtering parameters for user actions
* @return a page of results matching the input request
*/
public PaginatedResult<UserAction> findActions(LogsSearchRequest request) {
String table = request.getTable();
String actionType = request.getActionType();