diff --git a/gists/controller.go b/gists/controller.go index 5017f0b..5873ecb 100644 --- a/gists/controller.go +++ b/gists/controller.go @@ -110,6 +110,7 @@ func (g *GistControllerImpl) FindAll() fiber.Handler { owner_id := c.Locals("pub").(string) limit_param := c.Query("limit") offset_param := c.Query("offset") + short_param := c.Query("short") if limit_param == "" { limit_param = "50" @@ -119,6 +120,8 @@ func (g *GistControllerImpl) FindAll() fiber.Handler { offset_param = "0" } + short := short_param == "true" + limit, err := strconv.Atoi(limit_param) if err != nil { return c.Status(400).SendString("limit must be a number") @@ -128,7 +131,7 @@ func (g *GistControllerImpl) FindAll() fiber.Handler { return c.Status(400).SendString("offset must be a number") } - gists, err := GistService.FindAll(owner_id, limit, offset) + gists, err := GistService.FindAll(owner_id, limit, offset, short) if err != nil { return c.Status(500).SendString(err.Error()) } diff --git a/gists/service.go b/gists/service.go index e852b5c..9ea1d1a 100644 --- a/gists/service.go +++ b/gists/service.go @@ -3,6 +3,7 @@ package gists import ( "database/sql" "errors" + "strings" "github.com/gistapp/api/utils" "github.com/gofiber/fiber/v2/log" @@ -110,12 +111,20 @@ func (g *GistServiceImpl) Delete(id string, owner_id string) error { return nil } -func (g *GistServiceImpl) FindAll(owner_id string, limit int, offset int) ([]Gist, error) { +func (g *GistServiceImpl) FindAll(owner_id string, limit int, offset int, short bool) ([]Gist, error) { m := NewGistSQL("", "", "", owner_id, sql.NullString{}, "", "", "") gists, err := m.FindAll(limit, offset) if err != nil { return nil, errors.New("couldn't get gists") } + THRESHOLD := 700 + if short { + for gist := range gists { + if len(gists[gist].Content) > THRESHOLD { + gists[gist].Content = strings.Join(strings.Split(gists[gist].Content, "")[:THRESHOLD], "") + } + } + } return gists, nil }