feat(documents): rebuild project document workbench
This commit is contained in:
@@ -62,7 +62,7 @@ type SyncResultDTO struct {
|
||||
}
|
||||
|
||||
type DepositDTO struct {
|
||||
NoteID string `json:"noteId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
ProjectID string `json:"projectId"`
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ func (h *Handler) depositItem(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, DepositDTO{
|
||||
NoteID: result.NoteIdentity, ProjectID: result.ProjectIdentity,
|
||||
DocumentID: result.DocumentIdentity, ProjectID: result.ProjectIdentity,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -90,11 +90,13 @@ func TestDatasetAPIConnectsSourcesItemsAndSyncTasks(t *testing.T) {
|
||||
"projectId": project.Identity,
|
||||
})
|
||||
require.Equal(t, http.StatusCreated, deposited.Code)
|
||||
var depositedNote models.SaNote
|
||||
require.NoError(t, database.Where("project_id = ?", project.ID).First(&depositedNote).Error)
|
||||
require.Equal(t, item.Title, depositedNote.Title)
|
||||
require.Contains(t, depositedNote.Markdown, "")
|
||||
require.Contains(t, depositedNote.Markdown, "原文链接")
|
||||
var depositedDocument models.SaDocument
|
||||
require.NoError(t, database.Where("project_id = ?", project.ID).First(&depositedDocument).Error)
|
||||
require.Equal(t, item.Title+".md", depositedDocument.Name)
|
||||
var depositedContent models.SaDocumentContent
|
||||
require.NoError(t, database.Where("document_id = ?", depositedDocument.ID).First(&depositedContent).Error)
|
||||
require.Contains(t, depositedContent.Markdown, "")
|
||||
require.Contains(t, depositedContent.Markdown, "原文链接")
|
||||
|
||||
firstSync := performDatasetRequest(t, ownerRouter, http.MethodPost, "/api/v1/dataset-sources/sync", map[string]any{})
|
||||
require.Equal(t, http.StatusOK, firstSync.Code)
|
||||
@@ -239,7 +241,8 @@ func newDatasetTestDatabase(t *testing.T) *gorm.DB {
|
||||
&models.SaDatasetSource{},
|
||||
&models.SaDatasetItem{},
|
||||
&models.SaProject{},
|
||||
&models.SaNote{},
|
||||
&models.SaDocument{},
|
||||
&models.SaDocumentContent{},
|
||||
))
|
||||
return database
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ type ItemPatch struct {
|
||||
}
|
||||
|
||||
type DepositResult struct {
|
||||
NoteIdentity string
|
||||
DocumentIdentity string
|
||||
ProjectIdentity string
|
||||
}
|
||||
|
||||
@@ -359,14 +359,27 @@ func (s *Service) DepositItem(userID uint, itemIdentity, projectIdentity string)
|
||||
}
|
||||
body += "[原文链接](" + item.URL + ")"
|
||||
}
|
||||
note := models.SaNote{
|
||||
ProjectID: project.ID, CreatedBy: userID,
|
||||
Title: item.Title, Markdown: body,
|
||||
name := strings.TrimSpace(item.Title)
|
||||
if !strings.HasSuffix(strings.ToLower(name), ".md") {
|
||||
name += ".md"
|
||||
}
|
||||
if err := s.db.Create(¬e).Error; err != nil {
|
||||
var document models.SaDocument
|
||||
err = s.db.Transaction(func(tx *gorm.DB) error {
|
||||
document = models.SaDocument{
|
||||
ProjectID: project.ID, CreatedBy: userID, Kind: models.DocumentKindFile,
|
||||
Name: name, NormalizedName: strings.ToLower(name), Extension: ".md",
|
||||
MimeType: "text/markdown; charset=utf-8", Size: int64(len([]byte(body))),
|
||||
Revision: 1, ScanStatus: "not_scanned",
|
||||
}
|
||||
if err := tx.Create(&document).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Create(&models.SaDocumentContent{DocumentID: document.ID, Markdown: body}).Error
|
||||
})
|
||||
if err != nil {
|
||||
return DepositResult{}, err
|
||||
}
|
||||
return DepositResult{NoteIdentity: note.Identity, ProjectIdentity: project.Identity}, nil
|
||||
return DepositResult{DocumentIdentity: document.Identity, ProjectIdentity: project.Identity}, nil
|
||||
}
|
||||
|
||||
func (s *Service) SyncSources(ctx context.Context, userID uint) ([]SyncResult, error) {
|
||||
|
||||
Reference in New Issue
Block a user