diff --git a/src/hmndata/education_helper.go b/src/hmndata/education_helper.go deleted file mode 100644 index 55afccd..0000000 --- a/src/hmndata/education_helper.go +++ /dev/null @@ -1,57 +0,0 @@ -package hmndata - -import ( - "context" - - "git.handmade.network/hmn/hmn/src/db" - "git.handmade.network/hmn/hmn/src/models" - "git.handmade.network/hmn/hmn/src/oops" - "git.handmade.network/hmn/hmn/src/perf" -) - -type EduArticleQuery struct { - Slugs []string - Types []models.EduArticleType -} - -type EduArticleAndStuff struct { - Article models.EduArticle `db:"a"` - CurrentVersion models.EduArticleVersion `db:"v"` -} - -func FetchEduArticles( - ctx context.Context, - dbConn db.ConnOrTx, - currentUser *models.User, - q EduArticleQuery, -) ([]*EduArticleAndStuff, error) { - perf := perf.ExtractPerf(ctx) - perf.StartBlock("SQL", "Fetch education articles") - defer perf.EndBlock() - - var qb db.QueryBuilder - qb.Add(` - SELECT $columns - FROM - education_article AS a - JOIN education_article_version AS v ON a.current_version = v.id - WHERE - TRUE - `) - if len(q.Slugs) > 0 { - qb.Add(`AND a.slug = ANY ($?)`, q.Slugs) - } - if len(q.Types) > 0 { - qb.Add(`AND a.type = ANY ($?)`, q.Types) - } - if currentUser == nil || !currentUser.CanSeeUnpublishedEducationContent() { - qb.Add(`AND a.published`) - } - - articles, err := db.Query[EduArticleAndStuff](ctx, dbConn, qb.String(), qb.Args()...) - if err != nil { - return nil, oops.New(err, "failed to fetch education articles") - } - - return articles, nil -} diff --git a/src/hmnurl/hmnurl_test.go b/src/hmnurl/hmnurl_test.go index f273ef7..4cbe665 100644 --- a/src/hmnurl/hmnurl_test.go +++ b/src/hmnurl/hmnurl_test.go @@ -199,6 +199,18 @@ func TestEducationArticle(t *testing.T) { AssertRegexMatch(t, BuildEducationArticle("foo"), RegexEducationArticle, map[string]string{"slug": "foo"}) } +func TestEducationArticleNew(t *testing.T) { + AssertRegexMatch(t, BuildEducationArticleNew(), RegexEducationArticleNew, nil) +} + +func TestEducationArticleEdit(t *testing.T) { + AssertRegexMatch(t, BuildEducationArticleEdit("foo"), RegexEducationArticleEdit, map[string]string{"slug": "foo"}) +} + +func TestEducationArticleDelete(t *testing.T) { + AssertRegexMatch(t, BuildEducationArticleDelete("foo"), RegexEducationArticleDelete, map[string]string{"slug": "foo"}) +} + func TestForum(t *testing.T) { AssertRegexMatch(t, hmn.BuildForum(nil, 1), RegexForum, nil) AssertRegexMatch(t, hmn.BuildForum([]string{"wip"}, 2), RegexForum, map[string]string{"subforums": "wip", "page": "2"}) @@ -296,22 +308,6 @@ func TestBlogPostReply(t *testing.T) { AssertSubdomain(t, hero.BuildBlogPostReply(1, 2), "hero") } -func TestLibrary(t *testing.T) { - AssertRegexMatch(t, BuildLibrary(), RegexLibrary, nil) -} - -func TestLibraryAll(t *testing.T) { - AssertRegexMatch(t, BuildLibraryAll(), RegexLibraryAll, nil) -} - -func TestLibraryTopic(t *testing.T) { - AssertRegexMatch(t, BuildLibraryTopic(1), RegexLibraryTopic, map[string]string{"topicid": "1"}) -} - -func TestLibraryResource(t *testing.T) { - AssertRegexMatch(t, BuildLibraryResource(1), RegexLibraryResource, map[string]string{"resourceid": "1"}) -} - func TestEpisodeGuide(t *testing.T) { AssertRegexMatch(t, hero.BuildEpisodeList(""), RegexEpisodeList, map[string]string{"topic": ""}) AssertRegexMatch(t, hero.BuildEpisodeList("code"), RegexEpisodeList, map[string]string{"topic": "code"}) diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index 89bb7d8..a7c3d21 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -481,13 +481,6 @@ func BuildEducationArticleDelete(slug string) string { return Url(fmt.Sprintf("/education/%s/delete", slug), nil) } -var RegexEducationAdmin = regexp.MustCompile(`^/education/admin$`) - -func BuildEducationAdmin() string { - defer CatchPanic() - return Url("/education/admin", nil) -} - /* * Forums */ diff --git a/src/templates/src/education_admin.html b/src/templates/src/education_admin.html deleted file mode 100644 index 427a473..0000000 --- a/src/templates/src/education_admin.html +++ /dev/null @@ -1,21 +0,0 @@ -{{ template "base.html" . }} - -{{ define "content" }} -

Articles

- - -

Glossary Terms

- -{{ end }} diff --git a/src/website/education.go b/src/website/education.go index f6f91e0..1a072b4 100644 --- a/src/website/education.go +++ b/src/website/education.go @@ -9,7 +9,6 @@ import ( "time" "git.handmade.network/hmn/hmn/src/db" - "git.handmade.network/hmn/hmn/src/hmndata" "git.handmade.network/hmn/hmn/src/hmnurl" "git.handmade.network/hmn/hmn/src/models" "git.handmade.network/hmn/hmn/src/parsing" @@ -93,41 +92,6 @@ func EducationArticle(c *RequestContext) ResponseData { return res } -func EducationAdmin(c *RequestContext) ResponseData { - articles, err := hmndata.FetchEduArticles(c, c.Conn, c.CurrentUser, hmndata.EduArticleQuery{}) - if err != nil { - return c.ErrorResponse(http.StatusInternalServerError, err) - } - - var tmplArticles []templates.EduArticle - var tmplGlossaryTerms []templates.EduArticle - for _, a := range articles { - tmpl := templates.EducationArticleToTemplate(&a.Article) - switch a.Article.Type { - case models.EduArticleTypeArticle: - tmplArticles = append(tmplArticles, tmpl) - case models.EduArticleTypeGlossary: - tmplGlossaryTerms = append(tmplGlossaryTerms, tmpl) - } - } - - type adminData struct { - templates.BaseData - Articles []templates.EduArticle - GlossaryTerms []templates.EduArticle - } - - tmpl := adminData{ - BaseData: getBaseData(c, "Education Admin", nil), - Articles: tmplArticles, - GlossaryTerms: tmplGlossaryTerms, - } - - var res ResponseData - res.MustWriteTemplate("education_admin.html", tmpl, c.Perf) - return res -} - func EducationArticleNew(c *RequestContext) ResponseData { type adminData struct { editorData diff --git a/src/website/routes.go b/src/website/routes.go index c89e4ca..a9c165b 100644 --- a/src/website/routes.go +++ b/src/website/routes.go @@ -119,7 +119,6 @@ func NewWebsiteRoutes(conn *pgxpool.Pool) http.Handler { hmnOnly.GET(hmnurl.RegexEducationIndex, EducationIndex) hmnOnly.GET(hmnurl.RegexEducationGlossary, EducationGlossary) - hmnOnly.GET(hmnurl.RegexEducationAdmin, educationAuthorsOnly(EducationAdmin)) hmnOnly.GET(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNew)) hmnOnly.POST(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNewSubmit)) hmnOnly.GET(hmnurl.RegexEducationArticle, EducationArticle) // Article stuff must be last so `/glossary` and others do not match as an article slug