feat: implement chat and conversation history management with database schema and API endpoints
All checks were successful
Build and Release / release (push) Successful in 1m30s

This commit is contained in:
2026-05-08 21:03:26 +07:00
parent 4d4640c20a
commit 600246426b
17 changed files with 1306 additions and 33 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"history-api/internal/dtos/request"
"history-api/internal/dtos/response"
"history-api/internal/models"
"history-api/internal/services"
"history-api/pkg/validator"
"time"
@@ -67,3 +68,51 @@ func (cx *ChatbotController) Chat(c fiber.Ctx) error {
Data: answer,
})
}
// GetHistory godoc
// @Summary Get chatbot history
// @Description Get chatbot history for the current user
// @Tags Chatbot
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param cursor query string false "Cursor ID for pagination"
// @Param limit query int false "Limit number of items returned, default 10"
// @Success 200 {object} response.CommonResponse{data=response.GetChatbotHistoryResponse} "Successful response"
// @Failure 400 {object} response.CommonResponse "Invalid request"
// @Failure 500 {object} response.CommonResponse "Internal server error"
// @Router /chatbot/history [get]
func (cx *ChatbotController) GetHistory(c fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dto := &request.GetChatbotHistoryDto{}
if err := validator.ValidateQueryDto(c, dto); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(response.CommonResponse{
Status: false,
Errors: err,
})
}
uid := c.Locals("uid").(string)
histories, err := cx.chatbotService.GetHistory(ctx, uid, dto)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
Status: false,
Message: err.Error(),
})
}
var preCursor string
if len(histories) > 0 {
preCursor = histories[0].ID
}
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
Status: true,
Data: response.GetChatbotHistoryResponse{
Items: models.ChatbotHistoryEntitiesToResponse(histories),
PreCursor: preCursor,
},
})
}