@@ -2,6 +2,7 @@ package main
22
33import (
44 "bytes"
5+ "database/sql"
56 "errors"
67 "fmt"
78 "net/http"
@@ -73,6 +74,42 @@ func handleSearch(c echo.Context) error {
7374 return c .JSON (http .StatusOK , okResp {out })
7475}
7576
77+ // handleGetEntryPublic returns an entry by its guid.
78+ func handleGetEntryPublic (c echo.Context ) error {
79+ var (
80+ app = c .Get ("app" ).(* App )
81+ guid = c .Param ("guid" )
82+ )
83+
84+ e , err := app .data .GetEntry (0 , guid )
85+ if err != nil {
86+ if err == sql .ErrNoRows {
87+ return echo .NewHTTPError (http .StatusBadRequest , "entry not found" )
88+ }
89+
90+ return echo .NewHTTPError (http .StatusInternalServerError , err .Error ())
91+ }
92+
93+ e .Relations = make ([]data.Entry , 0 )
94+
95+ out := []data.Entry {e }
96+ if err := app .data .SearchAndLoadRelations (out , data.Query {}); err != nil {
97+ app .lo .Printf ("error loading relations: %v" , err )
98+ return echo .NewHTTPError (http .StatusInternalServerError , "error loading relations" )
99+ }
100+
101+ for i := range out {
102+ out [i ].ID = 0
103+
104+ for j := range out [i ].Relations {
105+ out [i ].Relations [j ].ID = 0
106+ out [i ].Relations [j ].Relation .ID = 0
107+ }
108+ }
109+
110+ return c .JSON (http .StatusOK , okResp {out [0 ]})
111+ }
112+
76113// handleServeBundle serves concatenated JS or CSS files based on query parameters
77114func handleServeBundle (c echo.Context , bundleType string , staticDir string ) error {
78115 files := c .QueryParams ()["f" ]
0 commit comments