042a1d4773
* introduced central package registry by package init function * dynamic registration of routes, model, migrations and initializers. * setting a docker compose project name to prevent shutdown of other containers with the same (composer)name * ai documentation * app template * Create tests for ALL API entpoints in ALL packages Based on current data. Ensure that all API endpoints used in frontend are tested. These tests are crucial for the next refactoring tasks. * adopting agent instructions for a more consistent coding style * added desired module layout and debugging information * Fix All Failing tests All failing tests are fixed now that makes the refactoring more easy since all tests must pass * restored routes for maintenance * added common translations * added new tests for API Endpoint * Merge branch 'separate_business_logic' * added lern and skill improvement cost editing * Set Docker image tag when building to prevent rebuild when nothing has changed * add and remove PP for Weaponskill fixed * add and remove PP for same named skills fixed * add new task
60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package character
|
|
|
|
import (
|
|
"bamort/database"
|
|
"bamort/bmrt/models"
|
|
)
|
|
|
|
// AuditLogReason definiert Standard-Gründe für Änderungen
|
|
type AuditLogReason string
|
|
|
|
const (
|
|
ReasonManual AuditLogReason = "manual"
|
|
ReasonSkillLearning AuditLogReason = "skill_learning"
|
|
ReasonSkillImprovement AuditLogReason = "skill_improvement"
|
|
ReasonSpellLearning AuditLogReason = "spell_learning"
|
|
ReasonEquipment AuditLogReason = "equipment"
|
|
ReasonReward AuditLogReason = "reward"
|
|
ReasonCorrection AuditLogReason = "correction"
|
|
ReasonImport AuditLogReason = "import"
|
|
)
|
|
|
|
// CreateAuditLogEntry erstellt einen neuen Audit-Log-Eintrag
|
|
func CreateAuditLogEntry(characterID uint, fieldName string, oldValue, newValue int, reason AuditLogReason, userID uint, notes string) error {
|
|
entry := models.AuditLogEntry{
|
|
CharacterID: characterID,
|
|
FieldName: fieldName,
|
|
OldValue: oldValue,
|
|
NewValue: newValue,
|
|
Difference: newValue - oldValue,
|
|
Reason: string(reason),
|
|
UserID: userID,
|
|
Notes: notes,
|
|
}
|
|
|
|
return database.DB.Create(&entry).Error
|
|
}
|
|
|
|
// GetAuditLogForCharacter holt alle Audit-Log-Einträge für einen Charakter
|
|
func GetAuditLogForCharacter(characterID uint) ([]models.AuditLogEntry, error) {
|
|
var entries []models.AuditLogEntry
|
|
err := database.DB.Where("character_id = ?", characterID).
|
|
Order("timestamp DESC").
|
|
Find(&entries).Error
|
|
return entries, err
|
|
}
|
|
|
|
// GetAuditLogForField holt Audit-Log-Einträge für ein spezifisches Feld
|
|
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
|
|
return entries, err
|
|
}
|
|
|
|
// MigrateAuditLog führt die Migration für die Audit-Log-Tabelle durch
|
|
func MigrateAuditLog() error {
|
|
return database.DB.AutoMigrate(&models.AuditLogEntry{})
|
|
}
|