Skip to content

Commit

Permalink
remove items entirely in preparation for a simpler one-type datagraph…
Browse files Browse the repository at this point in the history
… node tree
  • Loading branch information
Southclaws committed May 13, 2024
1 parent 5abcf1f commit 39ce546
Show file tree
Hide file tree
Showing 147 changed files with 1,025 additions and 16,091 deletions.
369 changes: 20 additions & 349 deletions api/openapi.yaml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion app/resources/datagraph/cluster.go
Expand Up @@ -34,7 +34,6 @@ type Cluster struct {
Visibility post.Visibility
Properties any

Items []*Item
Clusters []*Cluster
}

Expand Down
12 changes: 0 additions & 12 deletions app/resources/datagraph/cluster/cluster.go
Expand Up @@ -117,15 +117,3 @@ func WithChildClusterRemove(id xid.ID) Option {
c.RemoveClusterIDs(id)
}
}

func WithItemAdd(id xid.ID) Option {
return func(c *ent.ClusterMutation) {
c.AddItemIDs(id)
}
}

func WithItemRemove(id xid.ID) Option {
return func(c *ent.ClusterMutation) {
c.RemoveItemIDs(id)
}
}
13 changes: 0 additions & 13 deletions app/resources/datagraph/cluster/db.go
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/Southclaws/storyden/app/resources/datagraph"
"github.com/Southclaws/storyden/internal/ent"
"github.com/Southclaws/storyden/internal/ent/cluster"
"github.com/Southclaws/storyden/internal/ent/item"
"github.com/Southclaws/storyden/internal/ent/link"
)

Expand Down Expand Up @@ -98,12 +97,6 @@ func (d *database) Get(ctx context.Context, slug datagraph.ClusterSlug) (*datagr
WithLinks(func(lq *ent.LinkQuery) {
lq.WithAssets().Order(link.ByCreatedAt(sql.OrderDesc()))
}).
WithItems(func(iq *ent.ItemQuery) {
iq.
WithAssets().
WithOwner().
Order(item.ByUpdatedAt(sql.OrderDesc()), item.ByCreatedAt(sql.OrderDesc()))
}).
WithClusters(func(cq *ent.ClusterQuery) {
cq.
WithAssets().
Expand Down Expand Up @@ -132,12 +125,6 @@ func (d *database) GetByID(ctx context.Context, id datagraph.ClusterID) (*datagr
WithLinks(func(lq *ent.LinkQuery) {
lq.WithAssets().Order(link.ByCreatedAt(sql.OrderDesc()))
}).
WithItems(func(iq *ent.ItemQuery) {
iq.
WithAssets().
WithOwner().
Order(item.ByUpdatedAt(sql.OrderDesc()), item.ByCreatedAt(sql.OrderDesc()))
}).
WithClusters(func(cq *ent.ClusterQuery) {
cq.
WithAssets().
Expand Down
19 changes: 0 additions & 19 deletions app/resources/datagraph/cluster_children/db.go
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/Southclaws/storyden/app/resources/datagraph/cluster"
"github.com/Southclaws/storyden/internal/ent"
cluster_model "github.com/Southclaws/storyden/internal/ent/cluster"
"github.com/Southclaws/storyden/internal/ent/item"
)

type database struct {
Expand Down Expand Up @@ -67,24 +66,6 @@ func (d *database) Move(ctx context.Context, fromSlug datagraph.ClusterSlug, toS
return fault.Wrap(err)
}
}

if o.moveItems {
items, err := d.db.Item.Query().Where(item.HasClustersWith(cluster_model.ID(xid.ID(fromCluster.ID)))).All(ctx)
if err != nil {
return fault.Wrap(err)
}
childItemIDs := dt.Map(items, func(i *ent.Item) xid.ID { return i.ID })

err = d.db.Item.Update().
RemoveClusterIDs(xid.ID(fromCluster.ID)).
AddClusterIDs(xid.ID(toCluster.ID)).
Where(item.IDIn(childItemIDs...)).
Exec(ctx)
if err != nil {
return fault.Wrap(err)
}
}

return
}()
if err != nil {
Expand Down
@@ -1,4 +1,4 @@
package item_search
package cluster_search

import (
"context"
Expand All @@ -12,11 +12,11 @@ import (
"github.com/Southclaws/storyden/app/resources/datagraph"
"github.com/Southclaws/storyden/app/resources/post"
"github.com/Southclaws/storyden/internal/ent"
"github.com/Southclaws/storyden/internal/ent/item"
"github.com/Southclaws/storyden/internal/ent/cluster"
)

type Search interface {
Search(ctx context.Context, opts ...Option) ([]*datagraph.Item, error)
Search(ctx context.Context, opts ...Option) ([]*datagraph.Cluster, error)
}

type query struct {
Expand Down Expand Up @@ -50,34 +50,34 @@ func New(db *ent.Client, raw *sqlx.DB) Search {
}
}

func (s *service) Search(ctx context.Context, opts ...Option) ([]*datagraph.Item, error) {
func (s *service) Search(ctx context.Context, opts ...Option) ([]*datagraph.Cluster, error) {
q := &query{}

for _, fn := range opts {
fn(q)
}

query := s.db.Item.Query().
query := s.db.Cluster.Query().
Where(
item.NameContainsFold(q.qs),
cluster.NameContainsFold(q.qs),
// TODO: more query/filter params
).
WithOwner().
WithClusters(func(cq *ent.ClusterQuery) {
cq.WithOwner()
}).
WithAssets().
Order(item.ByUpdatedAt(sql.OrderDesc()), item.ByCreatedAt(sql.OrderDesc()))
Order(cluster.ByUpdatedAt(sql.OrderDesc()), cluster.ByCreatedAt(sql.OrderDesc()))

r, err := query.All(ctx)
if err != nil {
return nil, fault.Wrap(err, fctx.With(ctx))
}

items, err := dt.MapErr(r, datagraph.ItemFromModel)
clusters, err := dt.MapErr(r, datagraph.ClusterFromModel)
if err != nil {
return nil, fault.Wrap(err, fctx.With(ctx))
}

return items, nil
return clusters, nil
}
9 changes: 6 additions & 3 deletions app/resources/datagraph/datagraph_enum_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 0 additions & 44 deletions app/resources/datagraph/item.go

This file was deleted.

0 comments on commit 39ce546

Please sign in to comment.