diff --git a/app_http_handlers.go b/app_http_handlers.go
index 58809ec..85a944e 100644
--- a/app_http_handlers.go
+++ b/app_http_handlers.go
@@ -248,13 +248,34 @@ func (app *App) getDocumentHandler() gin.HandlerFunc {
// Section for local-db actions
func (app *App) getModificationHistoryHandler(c *gin.Context) {
- modifications, err := GetAllModifications(app.Database)
+ // Parse pagination parameters
+ page := 1
+ pageSize := 20
+
+ if p, err := strconv.Atoi(c.DefaultQuery("page", "1")); err == nil && p > 0 {
+ page = p
+ }
+ if ps, err := strconv.Atoi(c.DefaultQuery("pageSize", "20")); err == nil && ps > 0 && ps <= 100 {
+ pageSize = ps
+ }
+
+ // Get paginated modifications and total count
+ modifications, total, err := GetPaginatedModifications(app.Database, page, pageSize)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to retrieve modification history"})
log.Errorf("Failed to retrieve modification history: %v", err)
return
}
- c.JSON(http.StatusOK, modifications)
+
+ totalPages := (int(total) + pageSize - 1) / pageSize
+
+ c.JSON(http.StatusOK, gin.H{
+ "items": modifications,
+ "totalItems": total,
+ "totalPages": totalPages,
+ "currentPage": page,
+ "pageSize": pageSize,
+ })
}
func (app *App) undoModificationHandler(c *gin.Context) {
diff --git a/local_db.go b/local_db.go
index 931d7fb..2d696f2 100644
--- a/local_db.go
+++ b/local_db.go
@@ -63,13 +63,35 @@ func GetModification(db *gorm.DB, id uint) (*ModificationHistory, error) {
return &record, result.Error
}
-// GetAllModifications retrieves all modification records from the database
+// GetAllModifications retrieves all modification records from the database (deprecated - use GetPaginatedModifications instead)
func GetAllModifications(db *gorm.DB) ([]ModificationHistory, error) {
var records []ModificationHistory
- result := db.Order("date_changed DESC").Find(&records) // GORM's Find method retrieves all records
+ result := db.Order("date_changed DESC").Find(&records)
return records, result.Error
}
+// GetPaginatedModifications retrieves a page of modification records with total count
+func GetPaginatedModifications(db *gorm.DB, page int, pageSize int) ([]ModificationHistory, int64, error) {
+ var records []ModificationHistory
+ var total int64
+
+ // Get total count
+ if err := db.Model(&ModificationHistory{}).Count(&total).Error; err != nil {
+ return nil, 0, err
+ }
+
+ // Calculate offset
+ offset := (page - 1) * pageSize
+
+ // Get paginated records
+ result := db.Order("date_changed DESC").
+ Offset(offset).
+ Limit(pageSize).
+ Find(&records)
+
+ return records, total, result.Error
+}
+
// UndoModification marks a modification record as undone and sets the undo date
func SetModificationUndone(db *gorm.DB, record *ModificationHistory) error {
record.Undone = true
diff --git a/web-app/src/History.tsx b/web-app/src/History.tsx
index e68fb57..e659ea5 100644
--- a/web-app/src/History.tsx
+++ b/web-app/src/History.tsx
@@ -12,11 +12,23 @@ interface ModificationHistory {
UndoneDate: string | null;
}
+interface PaginatedResponse {
+ items: ModificationHistory[];
+ totalItems: number;
+ totalPages: number;
+ currentPage: number;
+ pageSize: number;
+}
+
const History: React.FC = () => {
const [modifications, setModifications] = useState