diff --git a/cmd/kuriweb/http.go b/cmd/kuriweb/http.go index edb22c7..64efce2 100644 --- a/cmd/kuriweb/http.go +++ b/cmd/kuriweb/http.go @@ -41,7 +41,7 @@ func setupHTTPWithTempl(srv xhttp.Server, router *mux.Router, log *slog.Logger) } func setupHTTPWithGoTemplates(srv xhttp.Server, router *mux.Router, log *slog.Logger) { - coursesAPI := srv.Courses() + coursesAPI := srv.Courses(true) coursesRouter := router.PathPrefix("/courses").Subrouter().StrictSlash(true) coursesRouter.HandleFunc("/", coursesAPI.List).Methods(http.MethodGet) diff --git a/internal/kurious/ports/http/course.go b/internal/kurious/ports/http/course.go index 0481ff4..d48c185 100644 --- a/internal/kurious/ports/http/course.go +++ b/internal/kurious/ports/http/course.go @@ -2,6 +2,7 @@ package http import ( "encoding/json" + "html/template" "log/slog" "net/http" "sort" @@ -21,6 +22,8 @@ import ( type courseServer struct { app service.Application log *slog.Logger + + useTailwind bool } type pagination struct { @@ -218,7 +221,13 @@ func (c courseServer) List(w http.ResponseWriter, r *http.Request) { }) } - err = getCoreTemplate(ctx, c.log).ExecuteTemplate(w, "courses", templateCourses) + var tmpl *template.Template + if c.useTailwind { + tmpl = getTemplateHTMLBySpecificFiles(ctx, c.log, "list.html") + } else { + tmpl = getCoreTemplate(ctx, c.log) + } + err = tmpl.ExecuteTemplate(w, "courses", templateCourses) if handleError(ctx, err, w, c.log, "unable to execute template") { return } diff --git a/internal/kurious/ports/http/course_test.go b/internal/kurious/ports/http/course_test.go deleted file mode 100644 index 7f62c6a..0000000 --- a/internal/kurious/ports/http/course_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package http - -import ( - "strconv" - "strings" - "testing" - "time" - - "git.loyso.art/frx/kurious/internal/kurious/domain" -) - -var courses = func() []domain.Course { - out := make([]domain.Course, 0) - out = append(out, makeBatchCourses("prog", []string{"go", "rust"}, 4)...) - out = append(out, makeBatchCourses("front", []string{"js", "html"}, 4)...) - - return out -}() - -func makeBatchCourses(lt string, cts []string, num int) []domain.Course { - out := make([]domain.Course, 0, len(cts)*num) - for _, ct := range cts { - for i := 0; i < num; i++ { - name := strings.Join([]string{ - lt, ct, - strconv.Itoa(i), - }, ".") - out = append(out, makeCourse(lt, ct, name)) - } - } - - return out -} - -func makeCourse(lt, ct, name string) domain.Course { - return domain.Course{ - LearningType: lt, - Thematic: ct, - Name: name, - ID: lt + ct + name, - FullPrice: 123, - Duration: time.Second * 100, - StartsAt: time.Now(), - } -} - -func TestRenderTemplate(t *testing.T) { - t.SkipNow() - result := mapDomainCourseToTemplate(courses...) - t.Logf("%#v", result) - - var out strings.Builder - err := listTemplateParsed.ExecuteTemplate(&out, "courses", result) - if err != nil { - t.Fatalf("executing: %v", err) - } - - t.Log(out.String()) - t.Fail() -} diff --git a/internal/kurious/ports/http/html/index.html b/internal/kurious/ports/http/html/index.html new file mode 100644 index 0000000..6e4b0c9 --- /dev/null +++ b/internal/kurious/ports/http/html/index.html @@ -0,0 +1,20 @@ +{{ define "base" }} + + +
+ {{ template "htmlhead" . }} + + + {{ template "htmlbody" . }} + + +{{ end }} + +{{ define "htmlhead" }} + + + +Course Description: {{$category.Description}}
- {{range $subcategory := $category.Subcategories}} -Subcategory Description: {{$subcategory.Description}}
- {{range $course := $subcategory.Courses}} -Description:
Full price: {{$course.FullPrice}}
-Discount: {{$course.Discount}}
-Thematic: {{$course.Thematic}}
-Learning type: {{$course.LearningType}}
-Duration: {{$course.Duration}}
-Starts at: {{$course.StartsAt}}
-