mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
Repository Structure:
- Move files from cluttered root directory into organized structure
- Create archive/ for archived data and scraper results
- Create bugulma/ for the complete application (frontend + backend)
- Create data/ for sample datasets and reference materials
- Create docs/ for comprehensive documentation structure
- Create scripts/ for utility scripts and API tools
Backend Implementation:
- Implement 3 missing backend endpoints identified in gap analysis:
* GET /api/v1/organizations/{id}/matching/direct - Direct symbiosis matches
* GET /api/v1/users/me/organizations - User organizations
* POST /api/v1/proposals/{id}/status - Update proposal status
- Add complete proposal domain model, repository, and service layers
- Create database migration for proposals table
- Fix CLI server command registration issue
API Documentation:
- Add comprehensive proposals.md API documentation
- Update README.md with Users and Proposals API sections
- Document all request/response formats, error codes, and business rules
Code Quality:
- Follow existing Go backend architecture patterns
- Add proper error handling and validation
- Match frontend expected response schemas
- Maintain clean separation of concerns (handler -> service -> repository)
170 lines
4.7 KiB
Go
170 lines
4.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"bugulma/backend/internal/domain"
|
|
"bugulma/backend/internal/service"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// TrustHandler handles trust metrics and data quality endpoints
|
|
type TrustHandler struct {
|
|
trustService *service.TrustService
|
|
}
|
|
|
|
// NewTrustHandler creates a new trust handler
|
|
func NewTrustHandler(trustService *service.TrustService) *TrustHandler {
|
|
return &TrustHandler{
|
|
trustService: trustService,
|
|
}
|
|
}
|
|
|
|
// GetTrustScore retrieves trust score for an organization
|
|
func (h *TrustHandler) GetTrustScore(c *gin.Context) {
|
|
orgID := c.Param("organizationId")
|
|
|
|
trustScore, err := h.trustService.CalculateTrustScore(c.Request.Context(), orgID)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, trustScore)
|
|
}
|
|
|
|
// GetDataQualityProfile retrieves data quality profile for an organization
|
|
func (h *TrustHandler) GetDataQualityProfile(c *gin.Context) {
|
|
orgID := c.Param("organizationId")
|
|
|
|
profile, err := h.trustService.AssessDataQuality(c.Request.Context(), orgID)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, profile)
|
|
}
|
|
|
|
// UpdateTrustMetrics updates trust metrics for an organization
|
|
func (h *TrustHandler) UpdateTrustMetrics(c *gin.Context) {
|
|
orgID := c.Param("organizationId")
|
|
|
|
var metrics []*domain.TrustMetrics
|
|
if err := c.ShouldBindJSON(&metrics); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if err := h.trustService.UpdateTrustMetrics(c.Request.Context(), orgID, metrics); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "Trust metrics updated successfully"})
|
|
}
|
|
|
|
// SubmitForVerification submits data for verification
|
|
func (h *TrustHandler) SubmitForVerification(c *gin.Context) {
|
|
var verifiedData domain.VerifiedData
|
|
if err := c.ShouldBindJSON(&verifiedData); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if err := h.trustService.SubmitForVerification(c.Request.Context(), &verifiedData); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusCreated, gin.H{"message": "Data submitted for verification"})
|
|
}
|
|
|
|
// VerifyData verifies data element
|
|
func (h *TrustHandler) VerifyData(c *gin.Context) {
|
|
dataID := c.Param("dataId")
|
|
|
|
var req struct {
|
|
VerifiedBy string `json:"verified_by" binding:"required"`
|
|
Notes string `json:"notes"`
|
|
}
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if err := h.trustService.VerifyData(c.Request.Context(), dataID, req.VerifiedBy, req.Notes); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": "Data verified successfully"})
|
|
}
|
|
|
|
// RecordHistoricalSuccess records historical success metrics
|
|
func (h *TrustHandler) RecordHistoricalSuccess(c *gin.Context) {
|
|
var success domain.HistoricalSuccess
|
|
if err := c.ShouldBindJSON(&success); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if err := h.trustService.RecordHistoricalSuccess(c.Request.Context(), &success); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusCreated, gin.H{"message": "Historical success recorded"})
|
|
}
|
|
|
|
// GetTrustDashboard retrieves comprehensive trust dashboard
|
|
func (h *TrustHandler) GetTrustDashboard(c *gin.Context) {
|
|
orgID := c.Param("organizationId")
|
|
|
|
dashboard, err := h.trustService.GetTrustDashboard(c.Request.Context(), orgID)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, dashboard)
|
|
}
|
|
|
|
// GetTrustMetrics retrieves trust metrics with pagination
|
|
func (h *TrustHandler) GetTrustMetrics(c *gin.Context) {
|
|
orgID := c.Param("organizationId")
|
|
metricType := c.Query("type")
|
|
|
|
limitStr := c.DefaultQuery("limit", "50")
|
|
limit, err := strconv.Atoi(limitStr)
|
|
if err != nil || limit < 1 {
|
|
limit = 50
|
|
}
|
|
|
|
var metrics []*domain.TrustMetrics
|
|
if metricType != "" {
|
|
metrics, err = h.trustService.GetTrustRepository().GetByType(c.Request.Context(), orgID, metricType)
|
|
} else {
|
|
metrics, err = h.trustService.GetTrustRepository().GetByOrganization(c.Request.Context(), orgID)
|
|
}
|
|
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
// Apply limit
|
|
if len(metrics) > limit {
|
|
metrics = metrics[:limit]
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"organization_id": orgID,
|
|
"metrics": metrics,
|
|
"count": len(metrics),
|
|
"limit": limit,
|
|
})
|
|
}
|