改进
This commit is contained in:
parent
16957ef1b3
commit
10ebe6807b
@ -52,6 +52,7 @@ message ListDocumentBlockResponse {
|
|||||||
message UpdateDocumentBlockRequest {
|
message UpdateDocumentBlockRequest {
|
||||||
int64 id = 1;
|
int64 id = 1;
|
||||||
string content = 2;
|
string content = 2;
|
||||||
|
int64 order = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateDocumentBlockResponse {
|
message UpdateDocumentBlockResponse {
|
||||||
|
@ -56,9 +56,9 @@ var (
|
|||||||
PrimaryKey: []*schema.Column{DocumentBlocksColumns[0]},
|
PrimaryKey: []*schema.Column{DocumentBlocksColumns[0]},
|
||||||
Indexes: []*schema.Index{
|
Indexes: []*schema.Index{
|
||||||
{
|
{
|
||||||
Name: "documentblock_user_id_order",
|
Name: "documentblock_user_id_order_document_id",
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Columns: []*schema.Column{DocumentBlocksColumns[4], DocumentBlocksColumns[2]},
|
Columns: []*schema.Column{DocumentBlocksColumns[4], DocumentBlocksColumns[2], DocumentBlocksColumns[3]},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,6 @@ func (DocumentBlock) Edges() []ent.Edge {
|
|||||||
|
|
||||||
func (DocumentBlock) Indexes() []ent.Index {
|
func (DocumentBlock) Indexes() []ent.Index {
|
||||||
return []ent.Index{
|
return []ent.Index{
|
||||||
index.Fields("user_id", "order"),
|
index.Fields("user_id", "order", "document_id"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
ent/schema/documentblockchunk.go
Normal file
35
ent/schema/documentblockchunk.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"entgo.io/ent/schema/index"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DocumentBlockChunk holds the schema definition for the DocumentBlockChunk entity.
|
||||||
|
type DocumentBlockChunk struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the DocumentBlockChunk.
|
||||||
|
func (DocumentBlockChunk) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.String("content"),
|
||||||
|
field.Int64("document_block_id"),
|
||||||
|
field.Bool("chunked").Default(false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the DocumentBlockChunk.
|
||||||
|
func (DocumentBlockChunk) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.To("document_block", DocumentBlock.Type),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (DocumentBlockChunk) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
index.Fields("document_block_id", "chunked"),
|
||||||
|
}
|
||||||
|
}
|
@ -94,11 +94,15 @@ func (d DocumentLogic) ListDocumentBlock(ctx context.Context, documentId int) ([
|
|||||||
return nil, consts.ErrDocumentNotFound
|
return nil, consts.ErrDocumentNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks, err := orm.DocumentBlock.Query().Where(
|
blocks := orm.DocumentBlock.Query().Where(
|
||||||
documentblock.DocumentID(int64(documentId)),
|
documentblock.DocumentID(int64(documentId)),
|
||||||
).All(ctx)
|
)
|
||||||
|
|
||||||
return blocks, err
|
blocks = blocks.Order(ent.Asc(documentblock.FieldOrder))
|
||||||
|
|
||||||
|
allBlocks, err := blocks.All(ctx)
|
||||||
|
|
||||||
|
return allBlocks, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- create index "documentblock_user_id_order_document_id" to table: "document_blocks"
|
||||||
|
CREATE INDEX "documentblock_user_id_order_document_id" ON "document_blocks" ("user_id", "order", "document_id");
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- reverse: create index "documentblock_user_id_order_document_id" to table: "document_blocks"
|
||||||
|
DROP INDEX "documentblock_user_id_order_document_id";
|
@ -1,3 +1,4 @@
|
|||||||
h1:i8hOFFa2SFOjNMtOo1eFw1/d9UpiSBEi2XMeAacMcEA=
|
h1:v4UVmVgqfUE/xwMK5hjP6laAx2UGwfm7KdOmQIOyTOI=
|
||||||
20240720155522_init.sql h1:EV/WhsF30qL+Q4kf1mhNxGP0KQpbVxMhjzUmG1pOEdQ=
|
20240720155522_init.sql h1:CKqDLw2sVT+NMqnmrvwtkmbHwNFJTUbdR5q0OtoxF1k=
|
||||||
20240721084724_remove_name_field_from_document_blocks.sql h1:V/+wh2/7HshCdZNTo4xrAVG7WF8HlcRIKa8285zy2K8=
|
20240721084724_remove_name_field_from_document_blocks.sql h1:IEUdjs3V5UcCd6As9A829u8CvW3g4DS5xKHDDPHKzlI=
|
||||||
|
20240722104713_add_document_id_index_to_document_blocks_table.sql h1:Iad/3g4/BLGlbQeB00lUGDVY5KE5BXHeEAFx2gWNjXI=
|
||||||
|
@ -78,11 +78,30 @@ func (Service) CreateDocumentBlock(ctx context.Context, req *ragApi.CreateDocume
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (Service) ListDocumentBlock(ctx context.Context, req *ragApi.ListDocumentBlockRequest) (*ragApi.ListDocumentBlockResponse, error) {
|
func (Service) ListDocumentBlock(ctx context.Context, req *ragApi.ListDocumentBlockRequest) (*ragApi.ListDocumentBlockResponse, error) {
|
||||||
panic("implement me")
|
documentBlocks, err := documentLogic.ListDocumentBlock(ctx, int(req.DocumentId))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var documentBlockApiResponse ragApi.ListDocumentBlockResponse
|
||||||
|
for _, documentBlock := range documentBlocks {
|
||||||
|
var documentBlockApiResponseItem = ragApi.DocumentBlock{
|
||||||
|
Id: int64(documentBlock.ID),
|
||||||
|
Content: documentBlock.Content,
|
||||||
|
DocumentId: documentBlock.DocumentID,
|
||||||
|
CreatedAt: documentBlock.CreatedAt.String(),
|
||||||
|
UpdatedAt: documentBlock.UpdatedAt.String(),
|
||||||
|
}
|
||||||
|
documentBlockApiResponse.DocumentBlocks = append(documentBlockApiResponse.DocumentBlocks, &documentBlockApiResponseItem)
|
||||||
|
}
|
||||||
|
return &documentBlockApiResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Service) UpdateDocumentBlock(ctx context.Context, req *ragApi.UpdateDocumentBlockRequest) (*ragApi.UpdateDocumentBlockResponse, error) {
|
func (Service) UpdateDocumentBlock(ctx context.Context, req *ragApi.UpdateDocumentBlockRequest) (*ragApi.UpdateDocumentBlockResponse, error) {
|
||||||
panic("implement me")
|
var updateDB = &models.UpdateDocumentBlock{
|
||||||
|
Order: req.Order,
|
||||||
|
Content: req.Content,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Service) DeleteDocumentBlock(ctx context.Context, req *ragApi.DeleteDocumentBlockRequest) (*ragApi.DeleteDocumentBlockResponse, error) {
|
func (Service) DeleteDocumentBlock(ctx context.Context, req *ragApi.DeleteDocumentBlockRequest) (*ragApi.DeleteDocumentBlockResponse, error) {
|
||||||
|
@ -4,7 +4,14 @@ package models
|
|||||||
// CreateDocumentBlock CreateDocumentBlock
|
// CreateDocumentBlock CreateDocumentBlock
|
||||||
//}
|
//}
|
||||||
|
|
||||||
type CreateDocumentBlock struct {
|
type (
|
||||||
|
CreateDocumentBlock struct {
|
||||||
Order int64 `json:"order"`
|
Order int64 `json:"order"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateDocumentBlock struct {
|
||||||
|
Order int64 `json:"order"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user