From c5b71472ac10e01b75d7bc8266303cb1463a6618 Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Mon, 26 Oct 2026 22:47:20 +0100 Subject: [PATCH] refactor: declare the content descriptors in MenuItemTypes The three descriptors are now literal pact.ContentDescriptor values next to the types they describe; no behaviour change. --- classes/content_descriptors.go | 34 ---------------------------------- classes/menu_item_types.go | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/classes/content_descriptors.go b/classes/content_descriptors.go index 03917df..c83bea2 100644 --- a/classes/content_descriptors.go +++ b/classes/content_descriptors.go @@ -39,18 +39,6 @@ func (m menuTypes) contentDB(ctx context.Context) (*gorm.DB, error) { return m.db(ctx) } -// postContent is the D-93 descriptor of journal-post: posts are edited by -// the posts controller and carry the Post morph name. -func (m menuTypes) postContent() *pact.ContentDescriptor { - return &pact.ContentDescriptor{ - Controller: postsControllerID, - Model: models.Post{}.MorphName(), - Records: m.listPosts, - Describe: m.describePost, - Match: m.matchPost, - } -} - // describePost describes one post, drafts included: Published tells // whether visitors see it. func (m menuTypes) describePost(ctx context.Context, in pact.ContentDescribe) (*pact.ContentRecord, error) { @@ -314,17 +302,6 @@ func (m menuTypes) matchPost(ctx context.Context, in pact.ContentMatch) (*pact.C return matchContent(ctx, db, in, find, urls) } -// categoryContent is the D-93 descriptor of journal-category. -func (m menuTypes) categoryContent() *pact.ContentDescriptor { - return &pact.ContentDescriptor{ - Controller: categoriesControllerID, - Model: models.Category{}.MorphName(), - Records: m.listCategories, - Describe: m.describeCategory, - Match: m.matchCategory, - } -} - func (m menuTypes) describeCategory(ctx context.Context, in pact.ContentDescribe) (*pact.ContentRecord, error) { id, ok := menuReferenceID(in.ID) if !ok { @@ -439,17 +416,6 @@ func (m menuTypes) matchCategory(ctx context.Context, in pact.ContentMatch) (*pa return matchContent(ctx, db, in, find, urls) } -// tagContent is the D-93 descriptor of journal-tag. -func (m menuTypes) tagContent() *pact.ContentDescriptor { - return &pact.ContentDescriptor{ - Controller: tagsControllerID, - Model: models.Tag{}.MorphName(), - Records: m.listTags, - Describe: m.describeTag, - Match: m.matchTag, - } -} - // tagReferences lists every tag by name, ties by id. func (m menuTypes) tagReferences(ctx context.Context) ([]pact.MenuItemReference, error) { db, err := m.db(ctx) diff --git a/classes/menu_item_types.go b/classes/menu_item_types.go index 0b26484..214a7d8 100644 --- a/classes/menu_item_types.go +++ b/classes/menu_item_types.go @@ -121,7 +121,13 @@ func MenuItemTypes(app func() *backpack.App) []pact.MenuItemType { DynamicItems: true, References: m.categoryReferences, Resolve: m.resolveCategory, - Content: m.categoryContent(), + Content: &pact.ContentDescriptor{ + Controller: categoriesControllerID, + Model: models.Category{}.MorphName(), + Records: m.listCategories, + Describe: m.describeCategory, + Match: m.matchCategory, + }, }, { Key: MenuTypeAllCategories, @@ -139,7 +145,13 @@ func MenuItemTypes(app func() *backpack.App) []pact.MenuItemType { Placeholders: append([]string(nil), postPlaceholders...), References: m.postReferences, Resolve: m.resolvePost, - Content: m.postContent(), + Content: &pact.ContentDescriptor{ + Controller: postsControllerID, + Model: models.Post{}.MorphName(), + Records: m.listPosts, + Describe: m.describePost, + Match: m.matchPost, + }, }, { Key: MenuTypeAllPosts, @@ -167,7 +179,13 @@ func MenuItemTypes(app func() *backpack.App) []pact.MenuItemType { Placeholders: append([]string(nil), tagPlaceholders...), References: m.tagReferences, Resolve: m.resolveTag, - Content: m.tagContent(), + Content: &pact.ContentDescriptor{ + Controller: tagsControllerID, + Model: models.Tag{}.MorphName(), + Records: m.listTags, + Describe: m.describeTag, + Match: m.matchTag, + }, }, } }