feat:knowledgebase doc id
This commit is contained in:
parent
00e3502c2d
commit
3b31156856
|
|
@ -11,6 +11,8 @@ type KnowledgeBase struct {
|
|||
AgentName *string `json:"agent_name" gorm:"type:varchar"`
|
||||
CreatedById uint `json:"created_by_id" gorm:"type:int4;not null"`
|
||||
Status int `json:"status" gorm:"type:int4;default:0"` // 0=wating,1=approved,2=reject
|
||||
DocumentId int `json:"documentId" gorm:"column:document_id;type:int4;not null;default:0"`
|
||||
|
||||
|
||||
Title *string `json:"title" gorm:"type:varchar"`
|
||||
|
||||
|
|
@ -22,4 +24,5 @@ type KnowledgeBase struct {
|
|||
|
||||
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ type KnowledgeBaseControllerInterface interface {
|
|||
Delete(c *fiber.Ctx) error
|
||||
Viewer(c *fiber.Ctx) error
|
||||
UpdateStatus(c *fiber.Ctx) error
|
||||
UpdateDocumentId(c *fiber.Ctx) error
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -39,7 +40,7 @@ func NewKnowledgeBaseController(svc service.KnowledgeBaseServiceInterface) Knowl
|
|||
// @Security Bearer
|
||||
// @Param agentId query string false "Agent ID"
|
||||
// @Param title query string false "Search title"
|
||||
// @Param status query int false "Status (0=draft,1=published,2=archived)"
|
||||
// @Param status query int false "Status (0=waitingdraft,1=approved,2=rejected)"
|
||||
// @Param createdById query int false "Created By ID"
|
||||
// @Param isActive query bool false "Is active"
|
||||
// @Param page query int false "Page"
|
||||
|
|
@ -238,4 +239,35 @@ func (ctl *KnowledgeBaseController) UpdateStatus(c *fiber.Ctx) error {
|
|||
Messages: utilRes.Messages{"KnowledgeBase status successfully updated"},
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
// @Summary Update KnowledgeBase DocumentId
|
||||
// @Description API untuk menambahkan/mengubah documentId ke KnowledgeBase
|
||||
// @Tags Knowledge Base
|
||||
// @Security Bearer
|
||||
// @Param id path int true "KnowledgeBase ID"
|
||||
// @Param payload body request.KnowledgeBaseUpdateDocumentRequest true "Required payload"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /knowledge-base/{id}/document [patch]
|
||||
func (ctl *KnowledgeBaseController) UpdateDocumentId(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := new(request.KnowledgeBaseUpdateDocumentRequest)
|
||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := ctl.KnowledgeBaseService.UpdateDocumentId(uint(id), req.DocumentId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utilRes.Resp(c, utilRes.Response{
|
||||
Success: true,
|
||||
Messages: utilRes.Messages{"KnowledgeBase documentId successfully updated"},
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
|
@ -50,6 +50,7 @@ func (r *KnowledgeBaseRouter) RegisterKnowledgeBaseRoutes() {
|
|||
router.Delete("/:id", kbController.Delete)
|
||||
router.Get("/viewer/:filename", kbController.Viewer)
|
||||
router.Patch("/:id/status", kbController.UpdateStatus)
|
||||
router.Patch("/:id/document", kbController.UpdateDocumentId)
|
||||
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"narasi-ahli-be/utils/paginator"
|
||||
utilSvc "narasi-ahli-be/utils/service"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type KnowledgeBaseRepository struct {
|
||||
|
|
@ -23,6 +24,8 @@ type KnowledgeBaseRepositoryInterface interface {
|
|||
Create(data *entity.KnowledgeBase) (err error)
|
||||
Update(id uint, data *entity.KnowledgeBase) (err error)
|
||||
Delete(id uint) (err error)
|
||||
UpdateDocumentId(id uint, documentId int) error
|
||||
|
||||
}
|
||||
|
||||
func NewKnowledgeBaseRepository(db *database.Database) KnowledgeBaseRepositoryInterface {
|
||||
|
|
@ -144,3 +147,12 @@ func (r *KnowledgeBaseRepository) FindByFilename(filename string) (data *entity.
|
|||
|
||||
return nil, "", fmt.Errorf("file not found")
|
||||
}
|
||||
|
||||
func (r *KnowledgeBaseRepository) UpdateDocumentId(id uint, documentId int) error {
|
||||
return r.DB.DB.Model(&entity.KnowledgeBase{}).
|
||||
Where("id = ?", id).
|
||||
Updates(map[string]interface{}{
|
||||
"document_id": documentId,
|
||||
"updated_at": time.Now(),
|
||||
}).Error
|
||||
}
|
||||
|
|
@ -24,6 +24,10 @@ type KnowledgeBaseUpdateStatusRequest struct {
|
|||
Status int `json:"status" validate:"required"`
|
||||
}
|
||||
|
||||
type KnowledgeBaseUpdateDocumentRequest struct {
|
||||
DocumentId int `json:"documentId" validate:"required"`
|
||||
}
|
||||
|
||||
type KnowledgeBaseCreateRequest struct {
|
||||
AgentId *string `form:"agentId" validate:"required"`
|
||||
AgentName *string `form:"agentName" validate:"required"`
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ type KnowledgeBaseServiceInterface interface {
|
|||
Delete(id uint) error
|
||||
Viewer(c *fiber.Ctx) error
|
||||
UpdateStatus(id uint, status int) (data *response.KnowledgeBaseResponse, err error)
|
||||
UpdateDocumentId(id uint, documentId int) (data *response.KnowledgeBaseResponse, err error)
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -335,3 +337,25 @@ func (s *KnowledgeBaseService) UpdateStatus(id uint, status int) (data *response
|
|||
host := s.Cfg.App.Domain
|
||||
return mapper.KnowledgeBaseResponseMapper(updated, host), nil
|
||||
}
|
||||
|
||||
func (s *KnowledgeBaseService) UpdateDocumentId(id uint, documentId int) (data *response.KnowledgeBaseResponse, err error) {
|
||||
// cek data exist
|
||||
_, err = s.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = s.Repo.UpdateDocumentId(id, documentId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
updated, err := s.Repo.FindOne(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
host := s.Cfg.App.Domain
|
||||
return mapper.KnowledgeBaseResponseMapper(updated, host), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10283,7 +10283,7 @@ const docTemplate = `{
|
|||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Status (0=draft,1=published,2=archived)",
|
||||
"description": "Status (0=waitingdraft,1=approved,2=rejected)",
|
||||
"name": "status",
|
||||
"in": "query"
|
||||
},
|
||||
|
|
@ -10589,6 +10589,46 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/knowledge-base/{id}/document": {
|
||||
"patch": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"description": "API untuk menambahkan/mengubah documentId ke KnowledgeBase",
|
||||
"tags": [
|
||||
"Knowledge Base"
|
||||
],
|
||||
"summary": "Update KnowledgeBase DocumentId",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "KnowledgeBase ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Required payload",
|
||||
"name": "payload",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.KnowledgeBaseUpdateDocumentRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/knowledge-base/{id}/status": {
|
||||
"patch": {
|
||||
"security": [
|
||||
|
|
@ -17003,6 +17043,17 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"request.KnowledgeBaseUpdateDocumentRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"documentId"
|
||||
],
|
||||
"properties": {
|
||||
"documentId": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"request.KnowledgeBaseUpdateRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
|
|||
|
|
@ -10272,7 +10272,7 @@
|
|||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Status (0=draft,1=published,2=archived)",
|
||||
"description": "Status (0=waitingdraft,1=approved,2=rejected)",
|
||||
"name": "status",
|
||||
"in": "query"
|
||||
},
|
||||
|
|
@ -10578,6 +10578,46 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/knowledge-base/{id}/document": {
|
||||
"patch": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"description": "API untuk menambahkan/mengubah documentId ke KnowledgeBase",
|
||||
"tags": [
|
||||
"Knowledge Base"
|
||||
],
|
||||
"summary": "Update KnowledgeBase DocumentId",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "KnowledgeBase ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Required payload",
|
||||
"name": "payload",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/request.KnowledgeBaseUpdateDocumentRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/response.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/knowledge-base/{id}/status": {
|
||||
"patch": {
|
||||
"security": [
|
||||
|
|
@ -16992,6 +17032,17 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"request.KnowledgeBaseUpdateDocumentRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"documentId"
|
||||
],
|
||||
"properties": {
|
||||
"documentId": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"request.KnowledgeBaseUpdateRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
|
|||
|
|
@ -812,6 +812,13 @@ definitions:
|
|||
- id
|
||||
- message
|
||||
type: object
|
||||
request.KnowledgeBaseUpdateDocumentRequest:
|
||||
properties:
|
||||
documentId:
|
||||
type: integer
|
||||
required:
|
||||
- documentId
|
||||
type: object
|
||||
request.KnowledgeBaseUpdateRequest:
|
||||
properties:
|
||||
agentId:
|
||||
|
|
@ -7976,7 +7983,7 @@ paths:
|
|||
in: query
|
||||
name: title
|
||||
type: string
|
||||
- description: Status (0=draft,1=published,2=archived)
|
||||
- description: Status (0=waitingdraft,1=approved,2=rejected)
|
||||
in: query
|
||||
name: status
|
||||
type: integer
|
||||
|
|
@ -8148,6 +8155,31 @@ paths:
|
|||
summary: Update KnowledgeBase
|
||||
tags:
|
||||
- Knowledge Base
|
||||
/knowledge-base/{id}/document:
|
||||
patch:
|
||||
description: API untuk menambahkan/mengubah documentId ke KnowledgeBase
|
||||
parameters:
|
||||
- description: KnowledgeBase ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
- description: Required payload
|
||||
in: body
|
||||
name: payload
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/request.KnowledgeBaseUpdateDocumentRequest'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/response.Response'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Update KnowledgeBase DocumentId
|
||||
tags:
|
||||
- Knowledge Base
|
||||
/knowledge-base/{id}/status:
|
||||
patch:
|
||||
description: API untuk update status KnowledgeBase
|
||||
|
|
|
|||
Loading…
Reference in New Issue