diff --git a/api/feed.go b/api/feed.go
index be3c8a2..b4c58fb 100644
--- a/api/feed.go
+++ b/api/feed.go
@@ -52,11 +52,12 @@ func (f feedAPI) Create(c echo.Context) error {
return err
}
- if err := f.srv.Create(c.Request().Context(), &req); err != nil {
+ resp, err := f.srv.Create(c.Request().Context(), &req)
+ if err != nil {
return err
}
- return c.NoContent(http.StatusCreated)
+ return c.JSON(http.StatusCreated, resp)
}
func (f feedAPI) CheckValidity(c echo.Context) error {
diff --git a/frontend/src/lib/api/feed.ts b/frontend/src/lib/api/feed.ts
index a4d4ffd..ad4d9d1 100644
--- a/frontend/src/lib/api/feed.ts
+++ b/frontend/src/lib/api/feed.ts
@@ -47,10 +47,12 @@ export type FeedCreateForm = {
};
export async function createFeed(data: FeedCreateForm) {
- return await api.post('feeds', {
- timeout: 20000,
- json: data
- });
+ return await api
+ .post('feeds', {
+ timeout: 20000,
+ json: data
+ })
+ .json<{ ids: number[] }>();
}
export type FeedUpdateForm = {
diff --git a/frontend/src/lib/components/FeedActionImportManually.svelte b/frontend/src/lib/components/FeedActionImportManually.svelte
index b16b8b0..4b4c155 100644
--- a/frontend/src/lib/components/FeedActionImportManually.svelte
+++ b/frontend/src/lib/components/FeedActionImportManually.svelte
@@ -1,5 +1,5 @@
@@ -158,6 +159,11 @@
{/each}
-
+
{/if}
diff --git a/server/feed.go b/server/feed.go
index ac9ea4e..5f4f4f3 100644
--- a/server/feed.go
+++ b/server/feed.go
@@ -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)
}
func (f Feed) CheckValidity(ctx context.Context, req *ReqFeedCheckValidity) (*RespFeedCheckValidity, error) {
diff --git a/server/feed_form.go b/server/feed_form.go
index 61cd6c7..10effc8 100644
--- a/server/feed_form.go
+++ b/server/feed_form.go
@@ -56,6 +56,10 @@ type ReqFeedCreate struct {
GroupID uint `json:"group_id" validate:"required"`
}
+type RespFeedCreate struct {
+ IDs []uint `json:"ids"`
+}
+
type ReqFeedUpdate struct {
ID uint `param:"id" validate:"required"`
Name *string `json:"name"`