-
Notifications
You must be signed in to change notification settings - Fork 56
feat: redirect to the feed page after creation #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -79,7 +79,7 @@ func (f Feed) Get(ctx context.Context, req *ReqFeedGet) (*RespFeedGet, error) { | |||||||||||||||
}, nil | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func (f Feed) Create(ctx context.Context, req *ReqFeedCreate) error { | ||||||||||||||||
func (f Feed) Create(ctx context.Context, req *ReqFeedCreate) (*RespFeedCreate, error) { | ||||||||||||||||
feeds := make([]*model.Feed, 0, len(req.Feeds)) | ||||||||||||||||
for _, r := range req.Feeds { | ||||||||||||||||
feeds = append(feeds, &model.Feed{ | ||||||||||||||||
|
@@ -91,16 +91,23 @@ func (f Feed) Create(ctx context.Context, req *ReqFeedCreate) error { | |||||||||||||||
GroupID: req.GroupID, | ||||||||||||||||
}) | ||||||||||||||||
} | ||||||||||||||||
if len(feeds) == 0 { | ||||||||||||||||
return nil | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if err := f.repo.Create(feeds); err != nil { | ||||||||||||||||
return err | ||||||||||||||||
return nil, err | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// GORM assigns the ID to the model after Create | ||||||||||||||||
ids := make([]uint, 0, len(feeds)) | ||||||||||||||||
for _, v := range feeds { | ||||||||||||||||
ids = append(ids, v.ID) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
resp := &RespFeedCreate{ | ||||||||||||||||
IDs: ids, | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
puller := pull.NewPuller(repo.NewFeed(repo.DB), repo.NewItem(repo.DB)) | ||||||||||||||||
if len(feeds) >= 1 { | ||||||||||||||||
if len(feeds) > 1 { | ||||||||||||||||
go func() { | ||||||||||||||||
routinePool := make(chan struct{}, 10) | ||||||||||||||||
defer close(routinePool) | ||||||||||||||||
|
@@ -118,9 +125,9 @@ func (f Feed) Create(ctx context.Context, req *ReqFeedCreate) error { | |||||||||||||||
} | ||||||||||||||||
wg.Wait() | ||||||||||||||||
}() | ||||||||||||||||
return nil | ||||||||||||||||
return resp, nil | ||||||||||||||||
} | ||||||||||||||||
return puller.PullOne(ctx, feeds[0].ID) | ||||||||||||||||
return resp, puller.PullOne(ctx, feeds[0].ID) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning the result of puller.PullOne along with the response may lead to unintended error propagation. Consider handling the error from puller.PullOne separately to ensure a clear separation between a successful creation response and asynchronous processing errors.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func (f Feed) CheckValidity(ctx context.Context, req *ReqFeedCheckValidity) (*RespFeedCheckValidity, error) { | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the condition for triggering asynchronous processing is intentional. If a single feed creation should be processed synchronously with a pull, confirm that using 'if len(feeds) > 1' is the correct logic for differentiating the two cases.
Copilot uses AI. Check for mistakes.