Add data migration export/import endpoints
All checks were successful
Backend Build and Test / build (push) Successful in 40s

Add GET /api/export to the Go backend that dumps all users, allowances,
history, and tasks (including completed) as a single JSON snapshot.

Add POST /api/import to the Spring backend that accepts the same JSON,
wipes existing data, inserts all records with original IDs preserved via
native SQL, and resets PostgreSQL sequences to avoid future collisions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-03-01 16:17:37 +01:00
parent 29284f6eac
commit a08a462e22
6 changed files with 248 additions and 1 deletions

View File

@@ -51,6 +51,16 @@ const DefaultDomain = "localhost:8080"
// The domain that the server is reachable at.
var domain = DefaultDomain
func exportData(c *gin.Context) {
data, err := db.ExportAllData()
if err != nil {
log.Printf("Error exporting data: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": ErrInternalServerError})
return
}
c.IndentedJSON(http.StatusOK, data)
}
func getUsers(c *gin.Context) {
users, err := db.GetUsers()
if err != nil {
@@ -713,6 +723,7 @@ func start(ctx context.Context, config *ServerConfig) {
router.DELETE("/api/task/:taskId", deleteTask)
router.POST("/api/task/:taskId/complete", completeTask)
router.POST("/api/transfer", transfer)
router.GET("/api/export", exportData)
srv := &http.Server{
Addr: config.Addr,