start migration to pocketbase 0.23

This commit is contained in:
Christian Beutel
2025-03-16 21:20:05 +01:00
parent 92433ec618
commit c765e6391d
14 changed files with 390 additions and 376 deletions

View File

@@ -5,10 +5,10 @@ import (
"log"
"github.com/meilisearch/meilisearch-go"
"github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/core"
)
func documentFromTrailRecord(r *models.Record, author *models.Record, includeShares bool) map[string]interface{} {
func documentFromTrailRecord(r *core.Record, author *core.Record, includeShares bool) map[string]interface{} {
photos := r.GetStringSlice("photos")
thumbnail := ""
if len(photos) > 0 {
@@ -52,7 +52,7 @@ func documentFromTrailRecord(r *models.Record, author *models.Record, includeSha
return document
}
func documentFromListRecord(r *models.Record, includeShares bool) map[string]interface{} {
func documentFromListRecord(r *core.Record, includeShares bool) map[string]interface{} {
document := map[string]interface{}{
"id": r.Id,
"author": r.GetString("author"),
@@ -70,7 +70,7 @@ func documentFromListRecord(r *models.Record, includeShares bool) map[string]int
return document
}
func IndexTrail(r *models.Record, author *models.Record, client meilisearch.ServiceManager) error {
func IndexTrail(r *core.Record, author *core.Record, client meilisearch.ServiceManager) error {
documents := []map[string]interface{}{documentFromTrailRecord(r, author, true)}
if _, err := client.Index("trails").AddDocuments(documents); err != nil {
@@ -80,7 +80,7 @@ func IndexTrail(r *models.Record, author *models.Record, client meilisearch.Serv
return nil
}
func UpdateTrail(r *models.Record, author *models.Record, client meilisearch.ServiceManager) error {
func UpdateTrail(r *core.Record, author *core.Record, client meilisearch.ServiceManager) error {
documents := documentFromTrailRecord(r, author, false)
if _, err := client.Index("trails").UpdateDocuments(documents); err != nil {
@@ -103,7 +103,7 @@ func UpdateTrailShares(trailId string, shares []string, client meilisearch.Servi
return nil
}
func IndexList(r *models.Record, client meilisearch.ServiceManager) error {
func IndexList(r *core.Record, client meilisearch.ServiceManager) error {
documents := []map[string]interface{}{documentFromListRecord(r, true)}
if _, err := client.Index("lists").AddDocuments(documents); err != nil {
@@ -113,7 +113,7 @@ func IndexList(r *models.Record, client meilisearch.ServiceManager) error {
return nil
}
func UpdateList(r *models.Record, client meilisearch.ServiceManager) error {
func UpdateList(r *core.Record, client meilisearch.ServiceManager) error {
documents := documentFromListRecord(r, false)
if _, err := client.Index("lists").UpdateDocuments(documents); err != nil {

View File

@@ -6,7 +6,7 @@ import (
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/mailer"
)
@@ -34,7 +34,7 @@ type NotificationSettings struct {
}
func getNotificationPermissions(app *pocketbase.PocketBase, user string, notificationType NotificationType) (*NotificationSettings, error) {
settings, err := app.Dao().FindFirstRecordByFilter("settings", "user={:user}", dbx.Params{"user": user})
settings, err := app.FindFirstRecordByFilter("settings", "user={:user}", dbx.Params{"user": user})
if err != nil {
return nil, err
}
@@ -62,34 +62,34 @@ func SendNotification(app *pocketbase.PocketBase, notification Notification, rec
return err
}
notifications, err := app.Dao().FindCollectionByNameOrId("notifications")
notifications, err := app.FindCollectionByNameOrId("notifications")
if err != nil {
return err
}
if permissions.Web {
n := models.NewRecord(notifications)
n := core.NewRecord(notifications)
n.Set("type", string(notification.Type))
n.Set("metadata", notification.Metadata)
n.Set("seen", notification.Seen)
n.Set("recipient", recipient)
n.Set("author", notification.Author)
if err := app.Dao().SaveRecord(n); err != nil {
if err := app.Save(n); err != nil {
return err
}
}
if permissions.Email {
recipientUser, err := app.Dao().FindRecordById("users", recipient)
recipientUser, err := app.FindAuthRecordByEmail("users", recipient)
if err != nil {
return err
}
authorUser, err := app.Dao().FindRecordById("users", notification.Author)
authorUser, err := app.FindRecordById("users", notification.Author)
if err != nil {
return err
}
html, err := GenerateHTML(app.Settings().Meta.AppUrl, recipientUser.Username(), authorUser.Username(), notification.Type, notification.Metadata)
html, err := GenerateHTML(app.Settings().Meta.AppURL, recipientUser.GetString("username"), authorUser.GetString("username"), notification.Type, notification.Metadata)
if err != nil {
return err
}
@@ -110,7 +110,7 @@ func SendNotification(app *pocketbase.PocketBase, notification Notification, rec
}
func SendNotificationToFollowers(app *pocketbase.PocketBase, notification Notification) error {
followers, err := app.Dao().FindRecordsByFilter("follows", "followee={:user}", "", -1, 0, dbx.Params{"user": notification.Author})
followers, err := app.FindRecordsByFilter("follows", "followee={:user}", "", -1, 0, dbx.Params{"user": notification.Author})
if err != nil {
return err