sojorn/go-backend/internal/handlers/analysis_handler.go
Patrick Britton da5984d67c refactor: rename Go module from github.com/patbritton to gitlab.com/patrickbritton3
- Rename module path from github.com/patbritton/sojorn-backend to gitlab.com/patrickbritton3/sojorn/go-backend
- Updated 78 references across 41 files
- Matches new GitLab repository structure
2026-02-16 23:58:39 -06:00

48 lines
1.1 KiB
Go

package handlers
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
"gitlab.com/patrickbritton3/sojorn/go-backend/internal/models"
)
type AnalysisHandler struct{}
func NewAnalysisHandler() *AnalysisHandler {
return &AnalysisHandler{}
}
func (h *AnalysisHandler) CheckTone(c *gin.Context) {
var req models.ToneCheckRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
return
}
// Basic native Go logic for tone analysis
// We can expand this with AI models or sentiment libraries later
result := models.ToneCheckResult{
Flagged: false,
Category: nil,
Flags: []string{},
Reason: "Content analyzed and found safe.",
}
// Example: Simple keyword check
forbidden := []string{"badword1", "badword2"}
for _, word := range forbidden {
if strings.Contains(strings.ToLower(req.Text), word) {
result.Flagged = true
category := "offensive"
result.Category = &category
result.Flags = append(result.Flags, "toxic")
result.Reason = "Content contains restricted language."
break
}
}
c.JSON(http.StatusOK, result)
}