ListUserActionLogs
This commit is contained in:
@@ -300,3 +300,70 @@ func NewListPendingCollectionResponse(data []models.PendingCollection, total int
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// --- UserActionLog ---
|
||||
|
||||
// ListUserActionLogRequest 定义了获取用户操作日志列表的请求参数
|
||||
type ListUserActionLogRequest struct {
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"pageSize,default=10"`
|
||||
UserID *uint `form:"user_id"`
|
||||
Username *string `form:"username"`
|
||||
ActionType *string `form:"action_type"`
|
||||
Status *string `form:"status"`
|
||||
StartTime *time.Time `form:"start_time" time_format:"rfc3339"`
|
||||
EndTime *time.Time `form:"end_time" time_format:"rfc3339"`
|
||||
OrderBy string `form:"order_by"`
|
||||
}
|
||||
|
||||
// UserActionLogDTO 是用于API响应的用户操作日志结构
|
||||
type UserActionLogDTO struct {
|
||||
ID uint `json:"id"`
|
||||
Time time.Time `json:"time"`
|
||||
UserID uint `json:"user_id"`
|
||||
Username string `json:"username"`
|
||||
SourceIP string `json:"source_ip"`
|
||||
ActionType string `json:"action_type"`
|
||||
TargetResource json.RawMessage `json:"target_resource"`
|
||||
Description string `json:"description"`
|
||||
Status models.AuditStatus `json:"status"`
|
||||
HTTPPath string `json:"http_path"`
|
||||
HTTPMethod string `json:"http_method"`
|
||||
ResultDetails string `json:"result_details"`
|
||||
}
|
||||
|
||||
// ListUserActionLogResponse 是获取用户操作日志列表的响应结构
|
||||
type ListUserActionLogResponse struct {
|
||||
List []UserActionLogDTO `json:"list"`
|
||||
Pagination PaginationDTO `json:"pagination"`
|
||||
}
|
||||
|
||||
// NewListUserActionLogResponse 从模型数据创建列表响应 DTO
|
||||
func NewListUserActionLogResponse(data []models.UserActionLog, total int64, page, pageSize int) *ListUserActionLogResponse {
|
||||
dtos := make([]UserActionLogDTO, len(data))
|
||||
for i, item := range data {
|
||||
dtos[i] = UserActionLogDTO{
|
||||
ID: item.ID,
|
||||
Time: item.Time,
|
||||
UserID: item.UserID,
|
||||
Username: item.Username,
|
||||
SourceIP: item.SourceIP,
|
||||
ActionType: item.ActionType,
|
||||
TargetResource: json.RawMessage(item.TargetResource),
|
||||
Description: item.Description,
|
||||
Status: item.Status,
|
||||
HTTPPath: item.HTTPPath,
|
||||
HTTPMethod: item.HTTPMethod,
|
||||
ResultDetails: item.ResultDetails,
|
||||
}
|
||||
}
|
||||
|
||||
return &ListUserActionLogResponse{
|
||||
List: dtos,
|
||||
Pagination: PaginationDTO{
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user