From 6a3be70c25dc527ced1185038d041cd4c0a5f7fa Mon Sep 17 00:00:00 2001 From: Yader Velasquez Date: Mon, 12 Feb 2024 14:12:31 -0600 Subject: [PATCH] Dynamic exclude functionality References: https://todo.code.netlandish.com/~netlandish/links/47 --- api/graph/schema.resolvers.go | 14 +++++++++++--- core/routes.go | 10 +++++++++- helpers.go | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go index b8edb08..d4025f3 100644 --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -4743,10 +4743,18 @@ func (r *queryResolver) GetOrgLinks(ctx context.Context, input *model.GetLinkInp } } - if input.Tag != nil && *input.Tag != "" { + if (input.Tag != nil && *input.Tag != "") || (input.ExcludeTag != nil && *input.ExcludeTag != "") { + var tagList = make([]string, 0) + if input.Tag != nil && *input.Tag != "" { + tagList = strings.Split(*input.Tag, ",") + } + + var excludeTagList = make([]string, 0) + if input.ExcludeTag != nil && *input.ExcludeTag != "" { + excludeTagList = strings.Split(*input.ExcludeTag, ",") + } // Filter based on tags - tagList := strings.Split(*input.Tag, ",") - subQText, subQVal, err := links.GetTagSubQuery(tagList, []string{}) + subQText, subQVal, err := links.GetTagSubQuery(tagList, excludeTagList) if err != nil { return nil, err } diff --git a/core/routes.go b/core/routes.go index 88237ea..559bd71 100644 --- a/core/routes.go +++ b/core/routes.go @@ -1195,12 +1195,13 @@ func (s *Service) OrgLinksList(c echo.Context) error { var result GraphQLResponse op := gqlclient.NewOperation( `query GetOrgLinks($slug: String, $after: Cursor, $before: Cursor, - $tag: String, $search: String, $filter: String) { + $tag: String, $excludeTag: String, $search: String, $filter: String) { getOrgLinks(input: { orgSlug: $slug, after: $after, before: $before, tag: $tag, + excludeTag: $excludeTag, search: $search, filter: $filter }) { @@ -1299,6 +1300,13 @@ func (s *Service) OrgLinksList(c echo.Context) error { tag = c.QueryParam("tag") op.Var("tag", tag) } + + var excludeTag string + if c.QueryParam("exclude") != "" { + excludeTag = c.QueryParam("exclude") + op.Var("excludeTag", excludeTag) + + } var search string if c.QueryParam("q") != "" { search = c.QueryParam("q") diff --git a/helpers.go b/helpers.go index 6f80b08..1b78917 100644 --- a/helpers.go +++ b/helpers.go @@ -731,7 +731,7 @@ func GetTagSubQuery(tags, excludeTags []string) (string, []interface{}, error) { excludeSubQ := sq.Select("tl.org_link_id"). From("tag_links tl"). LeftJoin("tags t ON t.id = tl.tag_id"). - Where(sq.Eq{"t.slug": "alpine"}) + Where(sq.Eq{"t.slug": excludeTags}) excludeSubQText, excludeSubQVal, err := excludeSubQ.ToSql() if err != nil { return "", nil, err -- 2.45.2