mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-02 17:59:14 +02:00
feat:#16 added migration for feeds with uuid
This commit is contained in:
@@ -243,4 +243,22 @@ func AddRoutes(app *pocketbase.PocketBase) {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||
_, err := e.Router.AddRoute(echo.Route{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/feed/migrate",
|
||||
Handler: func(c echo.Context) error {
|
||||
ical.MigrateFeedJson(app)
|
||||
return c.JSON(200, "Migrated")
|
||||
},
|
||||
Middlewares: []echo.MiddlewareFunc{
|
||||
apis.ActivityLogger(app),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
54
backend/service/ical/icalJsonMigrate.go
Normal file
54
backend/service/ical/icalJsonMigrate.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package ical
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"htwkalender/model"
|
||||
)
|
||||
|
||||
//update ical feed json
|
||||
//add uuid field
|
||||
//remove module name field
|
||||
|
||||
func MigrateFeedJson(app *pocketbase.PocketBase) {
|
||||
|
||||
var feeds []model.Feed
|
||||
|
||||
err := app.Dao().DB().Select("*").From("feed").All(&feeds)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, feed := range feeds {
|
||||
|
||||
var modules []model.FeedCollection
|
||||
|
||||
err := json.Unmarshal([]byte(feed.Modules), &modules)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var uuidFeedCollection model.UUIDFeedCollection
|
||||
|
||||
for _, module := range modules {
|
||||
uuid := searchUUIDForModule(app, module.Name)
|
||||
|
||||
if uuid != "" {
|
||||
uuidFeedCollection = model.UUIDFeedCollection{UUID: uuid, Name: module.Name, Course: module.Course, UserDefinedName: module.UserDefinedName}
|
||||
app.Dao().DB().Update("feed", dbx.Params{"modules": uuidFeedCollection}, dbx.NewExp("id = {:id}", dbx.Params{"id": feed.Id}))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func searchUUIDForModule(app *pocketbase.PocketBase, module string) string {
|
||||
var uuid string
|
||||
err := app.Dao().DB().Select("uuid").From("module").Where(dbx.NewExp("name = {:name}", dbx.Params{"name": module})).One(&uuid)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return uuid
|
||||
}
|
Reference in New Issue
Block a user