fix(freedoc): widen freeform project_id to BIGINT for snowflake IDs

UI-11 POST /freeform-documents 500 when project_id exceeds int4.
Align Go types + goose 00063 with projects.id BIGINT.
This commit is contained in:
WeiCHEN
2026-09-23 00:45:31 +08:00
parent 1ff3d81e1b
commit 3bdd53ae35
5 changed files with 38 additions and 7 deletions
+19
View File
@@ -59,6 +59,25 @@ func TestCreateDocument_ClientKeyIdempotentAndBootstrapsLedger(t *testing.T) {
assert.NotEqual(t, detail.Document.DocID, otherUser.Document.DocID)
}
func TestCreateDocument_AcceptsSnowflakeProjectID(t *testing.T) {
// projects.id is BIGINT; freeform must accept IDs above int4 max (regression: int4 encode 500).
const snowflakeProjectID int64 = 1789095399489
svc := freedoc.NewService(nil, nil)
detail, err := svc.CreateDocument(context.Background(), 42, freedoc.CreateFreeformDocRequest{
ProjectID: snowflakeProjectID,
Title: "snowflake.pdf",
ContentMarkdown: "# snowflake\n",
Space: "my_private",
})
require.NoError(t, err)
assert.Equal(t, snowflakeProjectID, detail.Document.ProjectID)
list, err := svc.ListDocuments(context.Background(), 42, snowflakeProjectID, "my_private")
require.NoError(t, err)
require.Len(t, list, 1)
assert.Equal(t, snowflakeProjectID, list[0].ProjectID)
}
func TestCreateDocument_RejectsEmptyContent(t *testing.T) {
svc := freedoc.NewService(nil, nil)
_, err := svc.CreateDocument(context.Background(), 1, freedoc.CreateFreeformDocRequest{
+1 -1
View File
@@ -525,7 +525,7 @@ func (s *Service) GetDocument(ctx context.Context, userID int, docID string) (*F
}
// ListDocuments 按空间与权限列出自由文档概要
func (s *Service) ListDocuments(ctx context.Context, userID int, projectID int, space string) ([]FreeformDocSummary, error) {
func (s *Service) ListDocuments(ctx context.Context, userID int, projectID int64, space string) ([]FreeformDocSummary, error) {
if space != "my_private" && space != "project_shared" && space != "trash" {
space = "my_private"
}
+4 -4
View File
@@ -16,7 +16,7 @@ var (
// FreeformDocument 自由私密/共享文档元数据
type FreeformDocument struct {
DocID string `json:"doc_id"`
ProjectID int `json:"project_id"`
ProjectID int64 `json:"project_id"`
OwnerUserID int `json:"owner_user_id"`
SourceMessageID *int64 `json:"source_message_id,omitempty"`
SourceContentSHA256 string `json:"source_content_sha256"`
@@ -53,7 +53,7 @@ type FreeformDocDetail struct {
// FreeformDocSummary 列表项概要
type FreeformDocSummary struct {
DocID string `json:"doc_id"`
ProjectID int `json:"project_id"`
ProjectID int64 `json:"project_id"`
OwnerUserID int `json:"owner_user_id"`
Title string `json:"title"`
Space string `json:"space"`
@@ -66,14 +66,14 @@ type FreeformDocSummary struct {
// CreateFromMessageRequest 从单条消息保存到私密文档请求
type CreateFromMessageRequest struct {
MessageID int64 `json:"message_id"`
ProjectID int `json:"project_id"`
ProjectID int64 `json:"project_id"`
Title string `json:"title,omitempty"`
ExpectedSHA256 string `json:"expected_sha256,omitempty"`
}
// CreateFreeformDocRequest 直接创建空白/自定义自由文档请求(上传附件即时注册事实源)
type CreateFreeformDocRequest struct {
ProjectID int `json:"project_id"`
ProjectID int64 `json:"project_id"`
Title string `json:"title"`
ContentMarkdown string `json:"content_markdown"`
Space string `json:"space,omitempty"` // 默认 'my_private'