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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user