Skip to content

Commit

Permalink
fix(netzach): tested with client
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Dec 21, 2023
1 parent 91ac63d commit 0303138
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/porter/internal/biz/bizfeed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type RSSRepo interface {
func NewFeed(rss RSSRepo) *FeedUseCase {
return &FeedUseCase{
rss,
favicon.New(),
favicon.New(favicon.IgnoreManifest),
}
}

Expand Down
6 changes: 6 additions & 0 deletions app/sephirah/internal/biz/bizangela/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func NewNotifyRouterTopic( //nolint:gocognit // TODO
if err != nil {
return err
}
if flow.Status != modelnetzach.NotifyFlowStatusActive {
continue
}
var messages []*modelfeed.Item
for _, source := range flow.Sources {
if source.SourceID == r.FeedID {
Expand Down Expand Up @@ -78,6 +81,9 @@ func NewNotifyPushTopic(
if err != nil {
return err
}
if target.Status != modelnetzach.NotifyTargetStatusActive {
return nil
}
_, err = a.porter.PushFeedItems(ctx, &porter.PushFeedItemsRequest{
Destination: converter.ToPBFeedDestination(target.Type),
ChannelId: p.Target.ChannelID,
Expand Down
20 changes: 20 additions & 0 deletions app/sephirah/internal/biz/biznetzach/netzach.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ func (n *Netzach) CreateNotifyFlow(ctx context.Context, flow *modelnetzach.Notif
return 0, pb.ErrorErrorReasonUnspecified("%s", err.Error())
}
flow.ID = id
for _, source := range flow.Sources {
if source.Filter == nil {
source.Filter = &modelnetzach.NotifyFilter{}

Check failure on line 130 in app/sephirah/internal/biz/biznetzach/netzach.go

View workflow job for this annotation

GitHub Actions / lint

modelnetzach.NotifyFilter is missing fields ExcludeKeywords, IncludeKeywords (exhaustruct)
}
}
for _, target := range flow.Targets {
if target.Filter == nil {
target.Filter = &modelnetzach.NotifyFilter{}

Check failure on line 135 in app/sephirah/internal/biz/biznetzach/netzach.go

View workflow job for this annotation

GitHub Actions / lint

modelnetzach.NotifyFilter is missing fields ExcludeKeywords, IncludeKeywords (exhaustruct)
}
}
err = n.repo.CreateNotifyFlow(ctx, claims.InternalID, flow)
if err != nil {
return 0, pb.ErrorErrorReasonUnspecified("%s", err.Error())
Expand All @@ -137,6 +147,16 @@ func (n *Netzach) UpdateNotifyFlow(ctx context.Context, flow *modelnetzach.Notif
if claims == nil {
return bizutils.NoPermissionError()
}
for _, source := range flow.Sources {
if source.Filter == nil {
source.Filter = &modelnetzach.NotifyFilter{}

Check failure on line 152 in app/sephirah/internal/biz/biznetzach/netzach.go

View workflow job for this annotation

GitHub Actions / lint

modelnetzach.NotifyFilter is missing fields ExcludeKeywords, IncludeKeywords (exhaustruct)
}
}
for _, target := range flow.Targets {
if target.Filter == nil {
target.Filter = &modelnetzach.NotifyFilter{}

Check failure on line 157 in app/sephirah/internal/biz/biznetzach/netzach.go

View workflow job for this annotation

GitHub Actions / lint

modelnetzach.NotifyFilter is missing fields ExcludeKeywords, IncludeKeywords (exhaustruct)
}
}
err := n.repo.UpdateNotifyFlow(ctx, claims.InternalID, flow)
if err != nil {
return pb.ErrorErrorReasonUnspecified("%s", err.Error())
Expand Down
32 changes: 16 additions & 16 deletions app/sephirah/internal/data/netzach.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func (n *netzachRepo) GetNotifyTarget(ctx context.Context, id model.InternalID)

func (n *netzachRepo) CreateNotifyFlow(ctx context.Context, userID model.InternalID, f *modelnetzach.NotifyFlow) error {
err := n.data.WithTx(ctx, func(tx *ent.Tx) error {
err := tx.NotifyFlow.Create().
SetID(f.ID).
SetOwnerID(userID).
SetName(f.Name).
SetDescription(f.Description).
SetStatus(converter.ToEntNotifySourceSource(f.Status)).
Exec(ctx)
if err != nil {
return err
}
flowSources := make([]*ent.NotifyFlowSourceCreate, len(f.Sources))
for i, source := range f.Sources {
flowSources[i] = tx.NotifyFlowSource.Create().
Expand All @@ -117,7 +127,7 @@ func (n *netzachRepo) CreateNotifyFlow(ctx context.Context, userID model.Interna
SetFilterExcludeKeywords(source.Filter.ExcludeKeywords).
SetFilterIncludeKeywords(source.Filter.IncludeKeywords)
}
source, err := tx.NotifyFlowSource.CreateBulk(flowSources...).Save(ctx)
err = tx.NotifyFlowSource.CreateBulk(flowSources...).Exec(ctx)
if err != nil {
return err
}
Expand All @@ -130,19 +140,11 @@ func (n *netzachRepo) CreateNotifyFlow(ctx context.Context, userID model.Interna
SetFilterExcludeKeywords(target.Filter.ExcludeKeywords).
SetFilterIncludeKeywords(target.Filter.IncludeKeywords)
}
target, err := tx.NotifyFlowTarget.CreateBulk(flowTargets...).Save(ctx)
err = tx.NotifyFlowTarget.CreateBulk(flowTargets...).Exec(ctx)
if err != nil {
return err
}
q := n.data.db.NotifyFlow.Create().
SetID(f.ID).
SetOwnerID(userID).
SetName(f.Name).
SetDescription(f.Description).
SetStatus(converter.ToEntNotifySourceSource(f.Status)).
AddNotifyFlowSource(source...).
AddNotifyFlowTarget(target...)
return q.Exec(ctx)
return nil
})
if err != nil {
return err
Expand Down Expand Up @@ -183,11 +185,10 @@ func (n *netzachRepo) UpdateNotifyFlow( //nolint:gocognit // TODO
SetFilterExcludeKeywords(source.Filter.ExcludeKeywords).
SetFilterIncludeKeywords(source.Filter.IncludeKeywords)
}
source, err := tx.NotifyFlowSource.CreateBulk(flowSources...).Save(ctx)
err = tx.NotifyFlowSource.CreateBulk(flowSources...).Exec(ctx)
if err != nil {
return err
}
q.ClearFeedConfig().AddNotifyFlowSource(source...)
}
if f.Targets != nil {
_, err := tx.NotifyFlowTarget.Delete().Where(
Expand All @@ -207,11 +208,10 @@ func (n *netzachRepo) UpdateNotifyFlow( //nolint:gocognit // TODO
SetFilterExcludeKeywords(target.Filter.ExcludeKeywords).
SetFilterIncludeKeywords(target.Filter.IncludeKeywords)
}
targets, err := tx.NotifyFlowTarget.CreateBulk(flowTargets...).Save(ctx)
err = tx.NotifyFlowTarget.CreateBulk(flowTargets...).Exec(ctx)
if err != nil {
return err
}
q.ClearNotifyTarget().AddNotifyFlowTarget(targets...)
}
if f.Status != modelnetzach.NotifyFlowStatusUnspecified {
q.SetStatus(converter.ToEntNotifySourceSource(f.Status))
Expand Down Expand Up @@ -259,7 +259,7 @@ func (n *netzachRepo) ListNotifyFlows(
func (n *netzachRepo) GetNotifyFlow(ctx context.Context, id model.InternalID) (*modelnetzach.NotifyFlow, error) {
res, err := n.data.db.NotifyFlow.Query().
Where(notifyflow.IDEQ(id)).
WithFeedConfig().
WithNotifyFlowSource().
WithNotifyFlowTarget().
Only(ctx)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions app/sephirah/internal/data/yesod.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (y *yesodRepo) UpdateFeedConfig(ctx context.Context, userID model.InternalI
q.SetStatus(converter.ToEntFeedConfigStatus(c.Status))
}
if c.PullInterval > 0 {
q.SetPullInterval(c.PullInterval)
q.SetPullInterval(c.PullInterval).SetNextPullBeginAt(time.Now())
}
q.SetHideItems(c.HideItems)
return q.Exec(ctx)
Expand Down Expand Up @@ -214,7 +214,7 @@ func (y *yesodRepo) ListFeedItems(
return err
}
fq := tx.User.QueryFeedConfig(u).Where(
feedconfig.HideItemsEQ(true),
feedconfig.HideItemsEQ(false),
).QueryFeed()
if len(feedIDs) > 0 {
fq.Where(feed.IDIn(feedIDs...))
Expand Down Expand Up @@ -278,7 +278,7 @@ func (y *yesodRepo) GroupFeedItems( //nolint:gocognit //TODO
}
for _, timeRange := range groups {
fq := tx.User.QueryFeedConfig(u).Where(
feedconfig.HideItemsEQ(true),
feedconfig.HideItemsEQ(false),
).QueryFeed()
if len(feedIDs) > 0 {
fq.Where(feed.IDIn(feedIDs...))
Expand Down

0 comments on commit 0303138

Please sign in to comment.