fix: historial por usuario (user_id en query_history)
This commit is contained in:
@@ -12,6 +12,7 @@ type QueryHistory struct {
|
||||
gorm.Model
|
||||
ConxDbID uint `json:"conx_db_id" gorm:"column:conx_db_id;index"`
|
||||
ConxDb ConxDb `json:"conx_db" gorm:"foreignKey:ConxDbID"`
|
||||
UserID uint `json:"user_id" gorm:"column:user_id;index;default:0"`
|
||||
SQL string `json:"sql" gorm:"column:sql;type:text"`
|
||||
Status string `json:"status" gorm:"column:status"` // ok | error
|
||||
ErrorMsg string `json:"error_msg" gorm:"column:error_msg;type:text"`
|
||||
@@ -29,8 +30,23 @@ func SaveQueryHistory(h QueryHistory) error {
|
||||
return app.Http.Database.DB.Create(&h).Error
|
||||
}
|
||||
|
||||
// GetQueryHistory devuelve el historial de una conexión con paginación.
|
||||
func GetQueryHistory(conxDbID uint, limit, offset int) ([]QueryHistory, int64, error) {
|
||||
// GetQueryHistory devuelve el historial de una conexión con paginación, filtrado por usuario.
|
||||
func GetQueryHistory(conxDbID, userID uint, limit, offset int) ([]QueryHistory, int64, error) {
|
||||
var items []QueryHistory
|
||||
var total int64
|
||||
db := app.Http.Database.DB.Model(&QueryHistory{}).Where("conx_db_id = ? AND user_id = ?", conxDbID, userID)
|
||||
db.Count(&total)
|
||||
err := db.Order("executed_at DESC").Limit(limit).Offset(offset).Find(&items).Error
|
||||
return items, total, err
|
||||
}
|
||||
|
||||
// DeleteQueryHistory elimina el historial de una conexión para un usuario.
|
||||
func DeleteQueryHistory(conxDbID, userID uint) error {
|
||||
return app.Http.Database.DB.Where("conx_db_id = ? AND user_id = ?", conxDbID, userID).Delete(&QueryHistory{}).Error
|
||||
}
|
||||
|
||||
// GetQueryHistoryAdmin devuelve todo el historial de una conexión (solo admin).
|
||||
func GetQueryHistoryAdmin(conxDbID uint, limit, offset int) ([]QueryHistory, int64, error) {
|
||||
var items []QueryHistory
|
||||
var total int64
|
||||
db := app.Http.Database.DB.Model(&QueryHistory{}).Where("conx_db_id = ?", conxDbID)
|
||||
@@ -39,7 +55,7 @@ func GetQueryHistory(conxDbID uint, limit, offset int) ([]QueryHistory, int64, e
|
||||
return items, total, err
|
||||
}
|
||||
|
||||
// DeleteQueryHistory elimina todo el historial de una conexión.
|
||||
func DeleteQueryHistory(conxDbID uint) error {
|
||||
// DeleteQueryHistoryAdmin elimina todo el historial de una conexión (solo admin).
|
||||
func DeleteQueryHistoryAdmin(conxDbID uint) error {
|
||||
return app.Http.Database.DB.Where("conx_db_id = ?", conxDbID).Delete(&QueryHistory{}).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user