moved AuditLogEntry to models

This commit is contained in:
2025-08-05 21:09:48 +02:00
parent 700a174cf1
commit 0d4fe65229
4 changed files with 25 additions and 22 deletions
+7 -21
View File
@@ -2,23 +2,9 @@ package character
import (
"bamort/database"
"time"
"bamort/models"
)
// AuditLogEntry repräsentiert einen Eintrag im Audit-Log
type AuditLogEntry struct {
ID uint `gorm:"primaryKey" json:"id"`
CharacterID uint `json:"character_id" gorm:"not null"`
FieldName string `json:"field_name" gorm:"not null"` // "experience_points", "gold", "silver", "copper"
OldValue int `json:"old_value"`
NewValue int `json:"new_value"`
Difference int `json:"difference"` // NewValue - OldValue
Reason string `json:"reason"` // "manual", "skill_learning", "skill_improvement", "spell_learning", etc.
UserID uint `json:"user_id,omitempty"`
Timestamp time.Time `json:"timestamp" gorm:"autoCreateTime"`
Notes string `json:"notes,omitempty"` // Zusätzliche Informationen
}
// AuditLogReason definiert Standard-Gründe für Änderungen
type AuditLogReason string
@@ -35,7 +21,7 @@ const (
// CreateAuditLogEntry erstellt einen neuen Audit-Log-Eintrag
func CreateAuditLogEntry(characterID uint, fieldName string, oldValue, newValue int, reason AuditLogReason, userID uint, notes string) error {
entry := AuditLogEntry{
entry := models.AuditLogEntry{
CharacterID: characterID,
FieldName: fieldName,
OldValue: oldValue,
@@ -50,8 +36,8 @@ func CreateAuditLogEntry(characterID uint, fieldName string, oldValue, newValue
}
// GetAuditLogForCharacter holt alle Audit-Log-Einträge für einen Charakter
func GetAuditLogForCharacter(characterID uint) ([]AuditLogEntry, error) {
var entries []AuditLogEntry
func GetAuditLogForCharacter(characterID uint) ([]models.AuditLogEntry, error) {
var entries []models.AuditLogEntry
err := database.DB.Where("character_id = ?", characterID).
Order("timestamp DESC").
Find(&entries).Error
@@ -59,8 +45,8 @@ func GetAuditLogForCharacter(characterID uint) ([]AuditLogEntry, error) {
}
// GetAuditLogForField holt Audit-Log-Einträge für ein spezifisches Feld
func GetAuditLogForField(characterID uint, fieldName string) ([]AuditLogEntry, error) {
var entries []AuditLogEntry
func GetAuditLogForField(characterID uint, fieldName string) ([]models.AuditLogEntry, error) {
var entries []models.AuditLogEntry
err := database.DB.Where("character_id = ? AND field_name = ?", characterID, fieldName).
Order("timestamp DESC").
Find(&entries).Error
@@ -69,5 +55,5 @@ func GetAuditLogForField(characterID uint, fieldName string) ([]AuditLogEntry, e
// MigrateAuditLog führt die Migration für die Audit-Log-Tabelle durch
func MigrateAuditLog() error {
return database.DB.AutoMigrate(&AuditLogEntry{})
return database.DB.AutoMigrate(&models.AuditLogEntry{})
}
+2 -1
View File
@@ -1,6 +1,7 @@
package character
import (
"bamort/models"
"net/http"
"strconv"
@@ -21,7 +22,7 @@ func GetCharacterAuditLog(c *gin.Context) {
// Filter für spezifisches Feld (optional)
fieldName := c.Query("field")
var entries []AuditLogEntry
var entries []models.AuditLogEntry
if fieldName != "" {
entries, err = GetAuditLogForField(uint(id), fieldName)
+1
View File
@@ -155,6 +155,7 @@ func learningMigrateStructure(db ...*gorm.DB) error {
&SpellLevelLECost{},
&SkillCategoryDifficulty{},
&SkillImprovementCost{},
&AuditLogEntry{},
)
if err != nil {
return err
+15
View File
@@ -3,6 +3,7 @@ package models
import (
"bamort/database"
"fmt"
"time"
"gorm.io/gorm"
)
@@ -150,6 +151,20 @@ type SpellLearningInfo struct {
LERequired int `json:"le_required"`
}
// AuditLogEntry repräsentiert einen Eintrag im Audit-Log
type AuditLogEntry struct {
ID uint `gorm:"primaryKey" json:"id"`
CharacterID uint `json:"character_id" gorm:"not null"`
FieldName string `json:"field_name" gorm:"not null"` // "experience_points", "gold", "silver", "copper"
OldValue int `json:"old_value"`
NewValue int `json:"new_value"`
Difference int `json:"difference"` // NewValue - OldValue
Reason string `json:"reason"` // "manual", "skill_learning", "skill_improvement", "spell_learning", etc.
UserID uint `json:"user_id,omitempty"`
Timestamp time.Time `json:"timestamp" gorm:"autoCreateTime"`
Notes string `json:"notes,omitempty"` // Zusätzliche Informationen
}
// TableName-Methoden für GORM
func (Source) TableName() string {
return "learning_sources"