From d3784b0337c3e5053eea3e98b5677e9a171b030b Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Thu, 6 Jul 2023 22:16:52 +0200 Subject: [PATCH] editor list --- cmd/owl/editor_test.go | 48 ++++++++++++++++++++++++ main.go => cmd/owl/main.go | 10 +++-- test/fixtures/test.png | Bin 0 -> 3118 bytes web/app.go | 16 ++++---- web/editor_handler.go | 31 +++++++++++++--- web/editor_list_handler.go | 53 +++++++++++++++++++++++++++ web/templates/base.tmpl | 18 +++++++++ web/templates/views/editor_list.tmpl | 12 ++++++ 8 files changed, 173 insertions(+), 15 deletions(-) create mode 100644 cmd/owl/editor_test.go rename main.go => cmd/owl/main.go (79%) create mode 100644 test/fixtures/test.png create mode 100644 web/editor_list_handler.go create mode 100644 web/templates/base.tmpl create mode 100644 web/templates/views/editor_list.tmpl diff --git a/cmd/owl/editor_test.go b/cmd/owl/editor_test.go new file mode 100644 index 0000000..a7735a5 --- /dev/null +++ b/cmd/owl/editor_test.go @@ -0,0 +1,48 @@ +package main + +import ( + "bytes" + "io" + "mime/multipart" + "net/http/httptest" + "os" + "path" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestEditorFormGet(t *testing.T) { + app := App().FiberApp + + req := httptest.NewRequest("GET", "/editor/ImageEntry", nil) + resp, err := app.Test(req) + require.NoError(t, err) + require.Equal(t, 200, resp.StatusCode) +} + +func TestEditorFormPost(t *testing.T) { + app := App().FiberApp + + fileDir, _ := os.Getwd() + fileName := "../../test/fixtures/test.png" + filePath := path.Join(fileDir, fileName) + + file, err := os.Open(filePath) + require.NoError(t, err) + defer file.Close() + + body := &bytes.Buffer{} + writer := multipart.NewWriter(body) + part, _ := writer.CreateFormFile("ImagePath", filepath.Base(file.Name())) + io.Copy(part, file) + part, _ = writer.CreateFormField("Content") + io.WriteString(part, "test content") + writer.Close() + + req := httptest.NewRequest("POST", "/editor/ImageEntry", nil) + resp, err := app.Test(req) + require.NoError(t, err) + require.Equal(t, 200, resp.StatusCode) +} diff --git a/main.go b/cmd/owl/main.go similarity index 79% rename from main.go rename to cmd/owl/main.go index 6cb60bc..22ae34d 100644 --- a/main.go +++ b/cmd/owl/main.go @@ -7,7 +7,7 @@ import ( "owl-blogs/web" ) -func main() { +func App() *web.WebApp { db := infra.NewSqliteDB("owlblogs.db") registry := app.NewEntryTypeRegistry() @@ -15,6 +15,10 @@ func main() { repo := infra.NewEntryRepository(db, registry) entryService := app.NewEntryService(repo) - webApp := web.NewWebApp(entryService) - webApp.Run() + return web.NewWebApp(entryService, registry) + +} + +func main() { + App().Run() } diff --git a/test/fixtures/test.png b/test/fixtures/test.png new file mode 100644 index 0000000000000000000000000000000000000000..fb234fd01e2b8d41d180101c5e61ed3575fa7b02 GIT binary patch literal 3118 zcmV+}4AJw6P)EX>4Tx04R}tkv&MmKpe$iQ?()$hjtKg$j~}j6cusQDionYs1;guFuC*#nlvOW zE{=k0!NHHks)LKOt`4q(Aou~|>f)s6A|?JWDYS_3;J6>}?mh0_0Yan9G^=YI(DbUA zO2oxXc2x|#B7h!*FovkiEMrcRlJFc~_we!cF2=LG&;2?2)ttoupGZ8*46{nSK|H-# zH8}4RhgnfpiO-2gO}ZfQBi9v|-#8Z>7I1)6o+{yw(t<_X|`2CnqBztR9^K1r{) zwa5`Lunk;Xw>4!CxZD8-pA6ZQ9m!8q$mfCgGy0}15V{5W*4*A&`#607($rP*1~@nb zMhcX@?(y#4&ffk#)9UXBlU{PP+6!EJ00009a7bBm001r{001r{0eGc9b^rhX2XskI zMF-~x1`{v}aV@}-0000PbVXQnLvL+uWo~o;Lvm$dbY)~9cWHEJAV*0}P*;Ht7XSbX z7)eAyRCwC$omos%TNlSq2U<~}Km{rm!~zB}h!_;1h(wJHN-%1Gs2GuYc* zO3ls99UL4~eZ=JotGv8?*REX(-VjtOH7_quC={+nSWQh$&d$zCEuesafKQ)3sW|TP z3mtlUd&9!QK7anK)PFTMH`mnEOiWAw-VG%Zi9jIWa=F99!#o~OBoa+dPGT^a>FH@a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ctxES8_29}=W|e0+Xuk>_%`r%s(h zVyv4tZ;C`BWMQ${?9|j$Bxb*J=gx|XiuofB4Go2dha)j!T3XuTn%p1-Z!0E~iNpf5 zw6rWNEc{c~8Jo?%e*HQUC8FHi+(qzG2o^%EloSf3prGLIlkV&5i;s^79-xp&q^hba zWm^Lkf`vqruA7_Nix)2x`FQz!esXd$*v@zef;>Gvl`TFh1Pg5YHx`Qx3JQAr_O0R{ ztW+w^$;km8*B2HKHBC%R?CI%QgnzB8t8;O20jsiRWMqtujV;Ax=<4eF z?AbF_nuz=R`!8I$05Bv*p-|!B;cabgilp3Xa`0Fz_TL5>^JlV8q6Tn-{ z!NH-lv~7Zmetv!cvmyfn0|tZf_YFshpmY(v z@)!)p*Vp&MhYv{9M81Fje&faseSLjUyl^<&l`B{N(ioszx}&(8N1;&m_Vy1SK18&r z$K`S#KYqM*>sGLh6n}a=S-C`-$z(3b3ynroD3rLkIQ8_ph{fVpuU_rjw-2DpKYsl9 zyLa#AZ$wHgvi*LIe9?v$FQ(%NI{iPoYo<>VgCUAt52* z+_`f`Mn({{oX^ktPfJNj0s8@v$>gl8EP2Sf(qO?b?CtFhT$29y@#6}FC6mdTnwnf) zUBQ+-&YU?T6be@$ESXGJQBeW*!I*XH*5&2ptxQ-lnXIO!#@pK)pvvm$>A7NI$*V+{ zE?oi@$KY_dl?+R+8Wt55sdT{DuO?ds*4^EG~z`ii%QIHI%Iy8yp;D zFc>Noie#(FMn*>N-@i{J61A`tm2|SRvrSD+wXhVmf`S5LV`HVIL1 + + + + {{template "title" .}} - Owl Blog + + +
+ Owl Blog +
+
+ {{template "main" .}} +
+
Powered by Go
+ + +{{end}} \ No newline at end of file diff --git a/web/templates/views/editor_list.tmpl b/web/templates/views/editor_list.tmpl new file mode 100644 index 0000000..4af68b6 --- /dev/null +++ b/web/templates/views/editor_list.tmpl @@ -0,0 +1,12 @@ +{{define "title"}}Editor List{{end}} + +{{define "main"}} + +

Editor List

+ +
    +{{range .Types}} +
  • {{.}}
  • +{{end}} + +{{end}} \ No newline at end of file