mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 09:15:33 +00:00
Refactored single almanach view
This commit is contained in:
@@ -2,6 +2,14 @@ package dbmodels
|
||||
|
||||
import "github.com/pocketbase/pocketbase/core"
|
||||
|
||||
func Ids[T core.RecordProxy](records []T) []any {
|
||||
ids := []any{}
|
||||
for _, r := range records {
|
||||
ids = append(ids, r.ProxyRecord().Id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func SetBasicPublicRules(collection *core.Collection) {
|
||||
collection.ViewRule = PUBLIC_VIEW_RULE
|
||||
collection.ListRule = PUBLIC_LIST_RULE
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// For scanning, with an Iter_ prefix, yields single row results
|
||||
|
||||
func REntriesAgents_Agent(app core.App, id string) ([]*REntriesAgents, error) {
|
||||
return TableByField[[]*REntriesAgents](
|
||||
return TableByFields[[]*REntriesAgents](
|
||||
app,
|
||||
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
|
||||
AGENTS_TABLE,
|
||||
@@ -23,7 +23,7 @@ func REntriesAgents_Agent(app core.App, id string) ([]*REntriesAgents, error) {
|
||||
}
|
||||
|
||||
func REntriesAgents_Entry(app core.App, id string) ([]*REntriesAgents, error) {
|
||||
return TableByField[[]*REntriesAgents](
|
||||
return TableByFields[[]*REntriesAgents](
|
||||
app,
|
||||
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
|
||||
ENTRIES_TABLE,
|
||||
@@ -32,7 +32,7 @@ func REntriesAgents_Entry(app core.App, id string) ([]*REntriesAgents, error) {
|
||||
}
|
||||
|
||||
func RContentsAgents_Agent(app core.App, id string) ([]*RContentsAgents, error) {
|
||||
return TableByField[[]*RContentsAgents](
|
||||
return TableByFields[[]*RContentsAgents](
|
||||
app,
|
||||
RelationTableName(CONTENTS_TABLE, AGENTS_TABLE),
|
||||
AGENTS_TABLE,
|
||||
@@ -40,8 +40,17 @@ func RContentsAgents_Agent(app core.App, id string) ([]*RContentsAgents, error)
|
||||
)
|
||||
}
|
||||
|
||||
func REntriesSeries_Entries(app core.App, ids any) ([]*REntriesSeries, error) {
|
||||
return TableByField[[]*REntriesSeries](
|
||||
func RContentsAgents_Contents(app core.App, id []any) ([]*RContentsAgents, error) {
|
||||
return TableByFields[[]*RContentsAgents](
|
||||
app,
|
||||
RelationTableName(CONTENTS_TABLE, AGENTS_TABLE),
|
||||
CONTENTS_TABLE,
|
||||
id,
|
||||
)
|
||||
}
|
||||
|
||||
func REntriesSeries_Entries(app core.App, ids []any) ([]*REntriesSeries, error) {
|
||||
return TableByFields[[]*REntriesSeries](
|
||||
app,
|
||||
RelationTableName(ENTRIES_TABLE, SERIES_TABLE),
|
||||
ENTRIES_TABLE,
|
||||
@@ -49,18 +58,55 @@ func REntriesSeries_Entries(app core.App, ids any) ([]*REntriesSeries, error) {
|
||||
)
|
||||
}
|
||||
|
||||
func REntriesSeries_Entry(app core.App, id string) ([]*REntriesSeries, error) {
|
||||
return TableByFields[[]*REntriesSeries](
|
||||
app,
|
||||
RelationTableName(ENTRIES_TABLE, SERIES_TABLE),
|
||||
ENTRIES_TABLE,
|
||||
id,
|
||||
)
|
||||
}
|
||||
|
||||
func Agents_ID(app core.App, id string) (*Agent, error) {
|
||||
return TableByID[*Agent](app, AGENTS_TABLE, id)
|
||||
r, err := TableByID[Agent](app, AGENTS_TABLE, id)
|
||||
return &r, err
|
||||
}
|
||||
|
||||
func Agents_IDs(app core.App, ids []any) ([]*Agent, error) {
|
||||
return TableByIDs[[]*Agent](app, AGENTS_TABLE, ids)
|
||||
}
|
||||
|
||||
func Entries_ID(app core.App, id string) (*Entry, error) {
|
||||
e, err := TableByID[Entry](app, ENTRIES_TABLE, id)
|
||||
return &e, err
|
||||
}
|
||||
|
||||
func Entries_MusenalmID(app core.App, id string) (*Entry, error) {
|
||||
ret, err := TableByField[Entry](app, ENTRIES_TABLE, MUSENALMID_FIELD, id)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
func Entries_IDs(app core.App, ids []any) ([]*Entry, error) {
|
||||
return TableByID[[]*Entry](app, ENTRIES_TABLE, ids)
|
||||
return TableByIDs[[]*Entry](app, ENTRIES_TABLE, ids)
|
||||
}
|
||||
|
||||
func Series_IDs(app core.App, ids []any) ([]*Series, error) {
|
||||
return TableByID[[]*Series](app, SERIES_TABLE, ids)
|
||||
return TableByIDs[[]*Series](app, SERIES_TABLE, ids)
|
||||
}
|
||||
|
||||
func Places_IDs(app core.App, ids []any) ([]*Place, error) {
|
||||
return TableByIDs[[]*Place](app, PLACES_TABLE, ids)
|
||||
}
|
||||
|
||||
func Contents_IDs(app core.App, ids []any) ([]*Content, error) {
|
||||
return TableByID[[]*Content](app, CONTENTS_TABLE, ids)
|
||||
return TableByIDs[[]*Content](app, CONTENTS_TABLE, ids)
|
||||
}
|
||||
|
||||
func Contents_Entry(app core.App, id string) ([]*Content, error) {
|
||||
return TableByFields[[]*Content](
|
||||
app,
|
||||
CONTENTS_TABLE,
|
||||
ENTRIES_TABLE,
|
||||
id,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,31 +11,56 @@ import (
|
||||
|
||||
// BUG: this is not working:
|
||||
// github.com/pocketbase/pocketbase/apis.NewRouter.panicRecover.func3.1()
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/apis/middlewares.go:269 +0x13c
|
||||
//
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/apis/middlewares.go:269 +0x13c
|
||||
//
|
||||
// panic({0x15b34c0?, 0x2831680?})
|
||||
// /usr/local/go/src/runtime/panic.go:787 +0x132
|
||||
//
|
||||
// /usr/local/go/src/runtime/panic.go:787 +0x132
|
||||
//
|
||||
// github.com/pocketbase/pocketbase/core.(*Record).FieldsData(0xc000632820)
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/core/record_model.go:774 +0x1a
|
||||
//
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/core/record_model.go:774 +0x1a
|
||||
//
|
||||
// github.com/pocketbase/pocketbase/core.(*Record).PostScan(0xc000632820)
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/core/record_model.go:591 +0x4e
|
||||
//
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/core/record_model.go:591 +0x4e
|
||||
//
|
||||
// github.com/pocketbase/dbx.(*Rows).ScanStruct(0xc00052e6d0, {0x175f840?, 0xc000586060?})
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/dbx@v1.11.0/rows.go:97 +0x32e
|
||||
//
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/dbx@v1.11.0/rows.go:97 +0x32e
|
||||
//
|
||||
// github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels.Iter_TableByField[...].func1()
|
||||
// /home/simon/source/musenalm/dbmodels/queryhelpers.go:23 +0x65
|
||||
//
|
||||
// /home/simon/source/musenalm/dbmodels/queryhelpers.go:23 +0x65
|
||||
//
|
||||
// github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels.Iter_REntriesAgents_Agent.func1(0xc000624840)
|
||||
// /home/simon/source/musenalm/dbmodels/queries_iter.go:30 +0xae
|
||||
//
|
||||
// /home/simon/source/musenalm/dbmodels/queries_iter.go:30 +0xae
|
||||
//
|
||||
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.(*PersonResult).FilterEntriesByPerson(0x1762c40?, {0x1dfba88, 0xc000438870}, {0xc00004627c, 0xf}, 0xc000064720)
|
||||
// /home/simon/source/musenalm/pages/person.go:111 +0x248
|
||||
//
|
||||
// /home/simon/source/musenalm/pages/person.go:111 +0x248
|
||||
//
|
||||
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.NewPersonResult({0x1dfba88, 0xc000438870}, {0xc00004627c, 0xf})
|
||||
// /home/simon/source/musenalm/pages/person.go:92 +0x4f
|
||||
//
|
||||
// /home/simon/source/musenalm/pages/person.go:92 +0x4f
|
||||
//
|
||||
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.(*PersonPage).Setup.func1(0xc0002da000)
|
||||
// /home/simon/source/musenalm/pages/person.go:46 +0x1ee
|
||||
//
|
||||
// /home/simon/source/musenalm/pages/person.go:46 +0x1ee
|
||||
//
|
||||
// github.com/pocketbase/pocketbase/tools/hook.(*Hook[...]).Trigger.func1()
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/tools/hook/hook.go:169 +0x5d
|
||||
//
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/tools/hook/hook.go:169 +0x5d
|
||||
//
|
||||
// github.com/pocketbase/pocketbase/tools/hook.(*Event).Next(0xc0002da000?)
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/tools/hook/event.go:32 +0x17
|
||||
//
|
||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/tools/hook/event.go:32 +0x17
|
||||
//
|
||||
// github.com/pocketbase/pocketbase/apis.NewRouter.BodyLimit.func7(0xc0002da000)
|
||||
// /home
|
||||
//
|
||||
// /home
|
||||
func Iter_TableByField[T interface{}](app core.App, table, field string, value interface{}) (iter.Seq2[*T, error], error) {
|
||||
rows, err := app.RecordQuery(table).
|
||||
Where(dbx.HashExp{field: value}).
|
||||
@@ -74,10 +99,22 @@ func Iter_TableByID[T interface{}](app core.App, table, id interface{}) (iter.Se
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TableByField[T interface{}](app core.App, table, field string, value interface{}) (T, error) {
|
||||
func TableByField[T interface{}](app core.App, table, field string, value string) (T, error) {
|
||||
var ret T
|
||||
err := app.RecordQuery(table).
|
||||
Where(dbx.HashExp{field: value}).
|
||||
One(&ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func TableByFields[T interface{}](app core.App, table, field string, values any) (T, error) {
|
||||
var ret T
|
||||
err := app.RecordQuery(table).
|
||||
Where(dbx.HashExp{field: values}).
|
||||
All(&ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
@@ -86,10 +123,22 @@ func TableByField[T interface{}](app core.App, table, field string, value interf
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func TableByID[T interface{}](app core.App, table, id interface{}) (T, error) {
|
||||
func TableByID[T interface{}](app core.App, table, id string) (T, error) {
|
||||
var ret T
|
||||
err := app.RecordQuery(table).
|
||||
Where(dbx.HashExp{ID_FIELD: id}).
|
||||
One(&ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func TableByIDs[T interface{}](app core.App, table string, ids []any) (T, error) {
|
||||
var ret T
|
||||
err := app.RecordQuery(table).
|
||||
Where(dbx.HashExp{ID_FIELD: ids}).
|
||||
All(&ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
|
||||
Reference in New Issue
Block a user