refactor: remove dataset item creator fields
This commit is contained in:
@@ -155,7 +155,7 @@ func TestDatasetSourceAuthorizationUsesOwner(t *testing.T) {
|
||||
require.Empty(t, creatorSources)
|
||||
|
||||
item := models.SaDatasetItem{
|
||||
SourceID: source.ID, CreatedBy: creator.ID, Title: "Creator-authored item", Status: "unread",
|
||||
SourceID: source.ID, Title: "Collected item", Status: "unread",
|
||||
}
|
||||
require.NoError(t, database.Create(&item).Error)
|
||||
page, err := NewService(database).ListItemsPage(owner.ID, source.Identity, 50, 0)
|
||||
@@ -184,8 +184,8 @@ func TestDatasetItemsArePaginatedByOwnedSource(t *testing.T) {
|
||||
require.NoError(t, database.Create(&source).Error)
|
||||
for index := 0; index < 3; index++ {
|
||||
require.NoError(t, database.Create(&models.SaDatasetItem{
|
||||
SourceID: source.ID, CreatedBy: owner.ID,
|
||||
Title: fmt.Sprintf("Item %d", index), Status: "unread",
|
||||
SourceID: source.ID,
|
||||
Title: fmt.Sprintf("Item %d", index), Status: "unread",
|
||||
}).Error)
|
||||
}
|
||||
router := datasetTestRouter(database, owner.ID)
|
||||
|
||||
@@ -297,7 +297,7 @@ func (s *Service) CreateItem(userID uint, input ItemInput) (*models.SaDatasetIte
|
||||
return nil, ErrURLInvalid
|
||||
}
|
||||
item := &models.SaDatasetItem{
|
||||
SourceID: source.ID, CreatedBy: userID, Title: title,
|
||||
SourceID: source.ID, Title: title,
|
||||
Summary: strings.TrimSpace(input.Summary), Content: strings.TrimSpace(input.Content),
|
||||
URL: itemURL, Status: "unread", PublishedAt: utcOptionalTime(input.PublishedAt),
|
||||
}
|
||||
@@ -539,7 +539,7 @@ func (s *Service) executeDatasetRun(ctx context.Context, entry queuedSource) (mo
|
||||
completedAt := time.Now().UTC()
|
||||
err := s.db.Transaction(func(tx *gorm.DB) error {
|
||||
var storeErr error
|
||||
inserted, storeErr = storeFeedItems(tx, cron.CreatedBy, source, feed.Items)
|
||||
inserted, storeErr = storeFeedItems(tx, source, feed.Items)
|
||||
if storeErr != nil {
|
||||
return storeErr
|
||||
}
|
||||
@@ -569,22 +569,12 @@ func (s *Service) executeDatasetRun(ctx context.Context, entry queuedSource) (mo
|
||||
return cron, nil
|
||||
}
|
||||
|
||||
func (s *Service) storeFeedItems(userID uint, source models.SaDatasetSource, items []FeedItem) (int, error) {
|
||||
inserted := 0
|
||||
err := s.db.Transaction(func(tx *gorm.DB) error {
|
||||
var err error
|
||||
inserted, err = storeFeedItems(tx, userID, source, items)
|
||||
return err
|
||||
})
|
||||
return inserted, err
|
||||
}
|
||||
|
||||
func storeFeedItems(tx *gorm.DB, userID uint, source models.SaDatasetSource, items []FeedItem) (int, error) {
|
||||
func storeFeedItems(tx *gorm.DB, source models.SaDatasetSource, items []FeedItem) (int, error) {
|
||||
inserted := 0
|
||||
for _, input := range items {
|
||||
externalID := input.ExternalID
|
||||
item := models.SaDatasetItem{
|
||||
SourceID: source.ID, CreatedBy: userID, ExternalID: &externalID,
|
||||
SourceID: source.ID, ExternalID: &externalID,
|
||||
Title: input.Title, Summary: input.Summary, Content: input.Content,
|
||||
URL: input.URL, Status: "unread", PublishedAt: input.PublishedAt,
|
||||
}
|
||||
|
||||
@@ -3,22 +3,20 @@ package models
|
||||
import "time"
|
||||
|
||||
type SaDatasetItem struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Identity string `gorm:"type:char(36);uniqueIndex"`
|
||||
SourceID uint `gorm:"index;not null"`
|
||||
SourceIdentity string `gorm:"type:char(36);index"`
|
||||
CreatedBy uint `gorm:"index;not null"`
|
||||
CreatedByIdentity string `gorm:"type:char(36);index"`
|
||||
ExternalID *string `gorm:"size:64;index"`
|
||||
Title string `gorm:"size:500;not null"`
|
||||
Summary string `gorm:"type:text"`
|
||||
Content string `gorm:"type:text"`
|
||||
URL string `gorm:"size:2048"`
|
||||
Status string `gorm:"size:32;not null;default:unread;index"`
|
||||
Starred bool `gorm:"not null;default:false;index"`
|
||||
PublishedAt *time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Identity string `gorm:"type:char(36);uniqueIndex"`
|
||||
SourceID uint `gorm:"index;not null"`
|
||||
SourceIdentity string `gorm:"type:char(36);index"`
|
||||
ExternalID *string `gorm:"size:64;index"`
|
||||
Title string `gorm:"size:500;not null"`
|
||||
Summary string `gorm:"type:text"`
|
||||
Content string `gorm:"type:text"`
|
||||
URL string `gorm:"size:2048"`
|
||||
Status string `gorm:"size:32;not null;default:unread;index"`
|
||||
Starred bool `gorm:"not null;default:false;index"`
|
||||
PublishedAt *time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (SaDatasetItem) TableName() string {
|
||||
|
||||
@@ -33,10 +33,7 @@ func (m *SaDatasetItem) BeforeCreate(tx *gorm.DB) error {
|
||||
if err := ensureIdentity(&m.Identity); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := resolveIdentity(tx, &SaDatasetSource{}, m.SourceID, &m.SourceIdentity); err != nil {
|
||||
return err
|
||||
}
|
||||
return resolveIdentity(tx, &SaUser{}, m.CreatedBy, &m.CreatedByIdentity)
|
||||
return resolveIdentity(tx, &SaDatasetSource{}, m.SourceID, &m.SourceIdentity)
|
||||
}
|
||||
|
||||
func (m *SaDatasetCron) BeforeCreate(tx *gorm.DB) error {
|
||||
|
||||
Reference in New Issue
Block a user