Refactor document ID handling in API responses
- Updated API response structures across multiple endpoints to replace `document_id` with `doc_id` for consistency. - Enhanced error handling in segment retrieval to ensure proper validation of document ownership. - Improved response clarity by ensuring all relevant endpoints reflect the updated field naming convention.
This commit is contained in:
parent
faafa4f90e
commit
5ea5c7835d
6 changed files with 105 additions and 63 deletions
|
|
@ -74,7 +74,7 @@ func GetSegmentGraph(c *gin.Context) {
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"entities": []interface{}{},
|
"entities": []interface{}{},
|
||||||
"relationships": []interface{}{},
|
"relationships": []interface{}{},
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"options": options,
|
"options": options,
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +130,7 @@ func ExtractSegmentGraph(c *gin.Context) {
|
||||||
// Return mock response for now
|
// Return mock response for now
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"message": "Entities and relationships extracted successfully",
|
"message": "Entities and relationships extracted successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"entities_count": 0,
|
"entities_count": 0,
|
||||||
"relationships_count": 0,
|
"relationships_count": 0,
|
||||||
|
|
@ -196,10 +196,10 @@ func ExtractSegmentGraphAsync(c *gin.Context) {
|
||||||
|
|
||||||
// Return job ID for status tracking
|
// Return job ID for status tracking
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"job_id": jobID,
|
"job_id": jobID,
|
||||||
"message": "Graph extraction started",
|
"message": "Graph extraction started",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
}
|
}
|
||||||
|
|
||||||
response.RespondWithSuccess(c, response.StatusCreated, result)
|
response.RespondWithSuccess(c, response.StatusCreated, result)
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ func ScrollHits(c *gin.Context) {
|
||||||
|
|
||||||
// Parse query parameters for scroll options
|
// Parse query parameters for scroll options
|
||||||
options := map[string]interface{}{
|
options := map[string]interface{}{
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"limit": 100, // Default limit
|
"limit": 100, // Default limit
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse limit (default: 100)
|
// Parse limit (default: 100)
|
||||||
|
|
@ -145,10 +145,10 @@ func GetHits(c *gin.Context) {
|
||||||
|
|
||||||
// Return mock response for now
|
// Return mock response for now
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"hits": []interface{}{},
|
"hits": []interface{}{},
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"total": 0,
|
"total": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(filter) > 0 {
|
if len(filter) > 0 {
|
||||||
|
|
@ -199,10 +199,10 @@ func GetHit(c *gin.Context) {
|
||||||
// TODO: Implement document permission validation for docID
|
// TODO: Implement document permission validation for docID
|
||||||
// TODO: Implement get hit detail logic
|
// TODO: Implement get hit detail logic
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"hit": nil,
|
"hit": nil,
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"hit_id": hitID,
|
"hit_id": hitID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,10 +233,10 @@ func AddHits(c *gin.Context) {
|
||||||
// TODO: Implement document permission validation for docID
|
// TODO: Implement document permission validation for docID
|
||||||
// TODO: Implement add hit logic
|
// TODO: Implement add hit logic
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": "Hit added successfully",
|
"message": "Hit added successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"hit_id": "placeholder-hit-id",
|
"hit_id": "placeholder-hit-id",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@ func UpdateHits(c *gin.Context) {
|
||||||
|
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"message": "Hits updated successfully",
|
"message": "Hits updated successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"updated_count": len(hitIDs),
|
"updated_count": len(hitIDs),
|
||||||
}
|
}
|
||||||
|
|
@ -352,7 +352,7 @@ func RemoveHits(c *gin.Context) {
|
||||||
|
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"message": "Hits removed successfully",
|
"message": "Hits removed successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"hit_ids": validHitIDs,
|
"hit_ids": validHitIDs,
|
||||||
"removed_count": len(validHitIDs),
|
"removed_count": len(validHitIDs),
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func UpdateScores(c *gin.Context) {
|
||||||
|
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"message": "Scores updated successfully",
|
"message": "Scores updated successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"scores": req.Scores,
|
"scores": req.Scores,
|
||||||
"updated_count": len(req.Scores),
|
"updated_count": len(req.Scores),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,7 @@ func RemoveSegments(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform remove segments operation
|
// Perform remove segments operation
|
||||||
removedCount, err := kb.Instance.RemoveSegments(c.Request.Context(), validSegmentIDs)
|
removedCount, err := kb.Instance.RemoveSegments(c.Request.Context(), docID, validSegmentIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorResp := &response.ErrorResponse{
|
errorResp := &response.ErrorResponse{
|
||||||
Code: response.ErrServerError.Code,
|
Code: response.ErrServerError.Code,
|
||||||
|
|
@ -411,8 +411,8 @@ func GetSegments(c *gin.Context) {
|
||||||
// TODO: Implement document permission validation for docID
|
// TODO: Implement document permission validation for docID
|
||||||
// TODO: Implement get segments logic
|
// TODO: Implement get segments logic
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"segments": []interface{}{},
|
"segments": []interface{}{},
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -440,13 +440,55 @@ func GetSegment(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if KB instance exists
|
||||||
|
if kb.Instance == nil {
|
||||||
|
errorResp := &response.ErrorResponse{
|
||||||
|
Code: response.ErrServerError.Code,
|
||||||
|
ErrorDescription: "Knowledge base instance is not initialized",
|
||||||
|
}
|
||||||
|
response.RespondWithError(c, response.StatusInternalServerError, errorResp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Implement document permission validation for docID
|
// TODO: Implement document permission validation for docID
|
||||||
// TODO: Implement get single segment logic
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
// Get the segment using KB interface
|
||||||
"segment": nil,
|
segment, err := kb.Instance.GetSegment(c.Request.Context(), docID, segmentID)
|
||||||
"document_id": docID,
|
if err != nil {
|
||||||
"segment_id": segmentID,
|
errorResp := &response.ErrorResponse{
|
||||||
})
|
Code: response.ErrServerError.Code,
|
||||||
|
ErrorDescription: fmt.Sprintf("Failed to get segment: %v", err),
|
||||||
|
}
|
||||||
|
response.RespondWithError(c, response.StatusInternalServerError, errorResp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if segment == nil {
|
||||||
|
errorResp := &response.ErrorResponse{
|
||||||
|
Code: response.ErrInvalidRequest.Code,
|
||||||
|
ErrorDescription: "Segment not found",
|
||||||
|
}
|
||||||
|
response.RespondWithError(c, response.StatusNotFound, errorResp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that the segment belongs to the specified document
|
||||||
|
if segment.DocumentID != docID {
|
||||||
|
errorResp := &response.ErrorResponse{
|
||||||
|
Code: response.ErrAccessDenied.Code,
|
||||||
|
ErrorDescription: "Segment does not belong to the specified document",
|
||||||
|
}
|
||||||
|
response.RespondWithError(c, response.StatusForbidden, errorResp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result := gin.H{
|
||||||
|
"segment": segment,
|
||||||
|
"doc_id": docID,
|
||||||
|
"segment_id": segmentID,
|
||||||
|
}
|
||||||
|
|
||||||
|
response.RespondWithSuccess(c, response.StatusOK, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScrollSegments scrolls segments with iterator-style pagination
|
// ScrollSegments scrolls segments with iterator-style pagination
|
||||||
|
|
@ -621,9 +663,9 @@ func AddSegmentsAsync(c *gin.Context) {
|
||||||
|
|
||||||
// Return job ID for status tracking
|
// Return job ID for status tracking
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"job_id": jobID,
|
"job_id": jobID,
|
||||||
"message": "Segments addition started",
|
"message": "Segments addition started",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
}
|
}
|
||||||
|
|
||||||
response.RespondWithSuccess(c, response.StatusCreated, result)
|
response.RespondWithSuccess(c, response.StatusCreated, result)
|
||||||
|
|
@ -680,9 +722,9 @@ func UpdateSegmentsAsync(c *gin.Context) {
|
||||||
|
|
||||||
// Return job ID for status tracking
|
// Return job ID for status tracking
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"job_id": jobID,
|
"job_id": jobID,
|
||||||
"message": "Segments update started",
|
"message": "Segments update started",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
}
|
}
|
||||||
|
|
||||||
response.RespondWithSuccess(c, response.StatusCreated, result)
|
response.RespondWithSuccess(c, response.StatusCreated, result)
|
||||||
|
|
@ -747,11 +789,11 @@ func GetSegmentParents(c *gin.Context) {
|
||||||
|
|
||||||
// Return mock response for now
|
// Return mock response for now
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"parents": []interface{}{},
|
"parents": []interface{}{},
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"depth": depth,
|
"depth": depth,
|
||||||
"total": 0,
|
"total": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
response.RespondWithSuccess(c, response.StatusOK, result)
|
response.RespondWithSuccess(c, response.StatusOK, result)
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ func ScrollVotes(c *gin.Context) {
|
||||||
|
|
||||||
// Parse query parameters for scroll options
|
// Parse query parameters for scroll options
|
||||||
options := map[string]interface{}{
|
options := map[string]interface{}{
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"limit": 100, // Default limit
|
"limit": 100, // Default limit
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse limit (default: 100)
|
// Parse limit (default: 100)
|
||||||
|
|
@ -139,10 +139,10 @@ func GetVotes(c *gin.Context) {
|
||||||
|
|
||||||
// Return mock response for now
|
// Return mock response for now
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"votes": []interface{}{},
|
"votes": []interface{}{},
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"total": 0,
|
"total": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(filter) > 0 {
|
if len(filter) > 0 {
|
||||||
|
|
@ -193,10 +193,10 @@ func GetVote(c *gin.Context) {
|
||||||
// TODO: Implement document permission validation for docID
|
// TODO: Implement document permission validation for docID
|
||||||
// TODO: Implement get vote detail logic
|
// TODO: Implement get vote detail logic
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"vote": nil,
|
"vote": nil,
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"vote_id": voteID,
|
"vote_id": voteID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,10 +227,10 @@ func AddVotes(c *gin.Context) {
|
||||||
// TODO: Implement document permission validation for docID
|
// TODO: Implement document permission validation for docID
|
||||||
// TODO: Implement add vote logic
|
// TODO: Implement add vote logic
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": "Vote added successfully",
|
"message": "Vote added successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"vote_id": "placeholder-vote-id",
|
"vote_id": "placeholder-vote-id",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,7 +275,7 @@ func UpdateVotes(c *gin.Context) {
|
||||||
|
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"message": "Votes updated successfully",
|
"message": "Votes updated successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"updated_count": len(voteIDs),
|
"updated_count": len(voteIDs),
|
||||||
}
|
}
|
||||||
|
|
@ -346,7 +346,7 @@ func RemoveVotes(c *gin.Context) {
|
||||||
|
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"message": "Votes removed successfully",
|
"message": "Votes removed successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"segment_id": segmentID,
|
"segment_id": segmentID,
|
||||||
"vote_ids": validVoteIDs,
|
"vote_ids": validVoteIDs,
|
||||||
"removed_count": len(validVoteIDs),
|
"removed_count": len(validVoteIDs),
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func UpdateWeights(c *gin.Context) {
|
||||||
// TODO: Implement document permission validation for docID
|
// TODO: Implement document permission validation for docID
|
||||||
|
|
||||||
// Perform batch update weight operation
|
// Perform batch update weight operation
|
||||||
updatedCount, err := kb.Instance.UpdateWeight(c.Request.Context(), req.Weights)
|
updatedCount, err := kb.Instance.UpdateWeight(c.Request.Context(), docID, req.Weights)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorResp := &response.ErrorResponse{
|
errorResp := &response.ErrorResponse{
|
||||||
Code: response.ErrServerError.Code,
|
Code: response.ErrServerError.Code,
|
||||||
|
|
@ -69,7 +69,7 @@ func UpdateWeights(c *gin.Context) {
|
||||||
// Return success response
|
// Return success response
|
||||||
result := gin.H{
|
result := gin.H{
|
||||||
"message": "Segment weights updated successfully",
|
"message": "Segment weights updated successfully",
|
||||||
"document_id": docID,
|
"doc_id": docID,
|
||||||
"weights": req.Weights,
|
"weights": req.Weights,
|
||||||
"updated_count": updatedCount,
|
"updated_count": updatedCount,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue