~netlandish/links

6a3be70c25dc527ced1185038d041cd4c0a5f7fa — Yader Velasquez 9 months ago a748803
Dynamic exclude functionality

References: https://todo.code.netlandish.com/~netlandish/links/47
3 files changed, 21 insertions(+), 5 deletions(-)

M api/graph/schema.resolvers.go
M core/routes.go
M helpers.go
M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +11 -3
@@ 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
		}

M core/routes.go => core/routes.go +9 -1
@@ 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")

M helpers.go => helpers.go +1 -1
@@ 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