initial commit

This commit is contained in:
2026-03-12 19:17:00 +01:00
commit 9030f2001e
25 changed files with 5089 additions and 0 deletions

51
internal/api/handler.go Normal file
View File

@@ -0,0 +1,51 @@
package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/paramah/ai_devs4/s01e03/internal/usecase"
)
// Handler handles HTTP requests
type Handler struct {
conversationUC *usecase.ConversationUseCase
}
// NewHandler creates a new API handler
func NewHandler(conversationUC *usecase.ConversationUseCase) *Handler {
return &Handler{
conversationUC: conversationUC,
}
}
// ShadowRequest represents the request for /shadow endpoint
type ShadowRequest struct {
SessionID string `json:"sessionID" binding:"required"`
Msg string `json:"msg" binding:"required"`
}
// ShadowResponse represents the response for /shadow endpoint
type ShadowResponse struct {
Msg string `json:"msg"`
}
// Shadow handles the /shadow endpoint
func (h *Handler) Shadow(c *gin.Context) {
var req ShadowRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
// Process message
response, err := h.conversationUC.ProcessMessage(c.Request.Context(), req.SessionID, req.Msg)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, ShadowResponse{
Msg: response,
})
}