Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*.local
*.local
.DS_Store
backend/config/config.dev.yml
**/__pycache__/
*.pyc
20 changes: 12 additions & 8 deletions backend/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import (

func main() {
// Load the configuration from the specified YAML file
cfg, err := config.LoadConfig("./config/config.prod.yml")
configPath := os.Getenv("CONFIG_PATH")
if configPath == "" {
configPath = "./config/config.dev.yml"
}
cfg, err := config.LoadConfig(configPath)
if err != nil {
panic("Failed to load config: " + err.Error())
}
Expand All @@ -36,14 +40,14 @@ func main() {
log.Println("Connected to MongoDB")

// Initialize Casbin RBAC
if err := middlewares.InitCasbin("./config/config.prod.yml"); err != nil {
if err := middlewares.InitCasbin(configPath); err != nil {
log.Fatalf("Failed to initialize Casbin: %v", err)
}
log.Println("Casbin RBAC initialized")

// Connect to Redis if configured
if cfg.Redis.URL != "" {
redisURL := cfg.Redis.URL
if cfg.Redis.Addr != "" {
redisURL := cfg.Redis.Addr
if redisURL == "" {
redisURL = "localhost:6379"
}
Expand All @@ -69,15 +73,15 @@ func main() {
os.MkdirAll("uploads", os.ModePerm)

// Set up the Gin router and configure routes
router := setupRouter(cfg)
router := setupRouter(cfg, configPath)
port := strconv.Itoa(cfg.Server.Port)

if err := router.Run(":" + port); err != nil {
panic("Failed to start server: " + err.Error())
}
}

func setupRouter(cfg *config.Config) *gin.Engine {
func setupRouter(cfg *config.Config, configPath string) *gin.Engine {
router := gin.Default()

// Set trusted proxies (adjust as needed)
Expand Down Expand Up @@ -111,7 +115,7 @@ func setupRouter(cfg *config.Config) *gin.Engine {

// Protected routes (JWT auth)
auth := router.Group("/")
auth.Use(middlewares.AuthMiddleware("./config/config.prod.yml"))
auth.Use(middlewares.AuthMiddleware(configPath))
{
auth.GET("/user/fetchprofile", routes.GetProfileRouteHandler)
auth.PUT("/user/updateprofile", routes.UpdateProfileRouteHandler)
Expand Down Expand Up @@ -158,7 +162,7 @@ func setupRouter(cfg *config.Config) *gin.Engine {
router.GET("/ws/team", websocket.TeamWebsocketHandler)

// Admin routes
routes.SetupAdminRoutes(router, "./config/config.prod.yml")
routes.SetupAdminRoutes(router, configPath)
log.Println("Admin routes registered")

// Debate spectator WebSocket handler (no auth required for anonymous spectators)
Expand Down
37 changes: 37 additions & 0 deletions backend/config/config.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
server:
port: 8080 # The port number your backend server will run on

database:
uri: "mongodb://localhost:27017/arguehub" # Local MongoDB or replace with Atlas URI

gemini:
apiKey: 'PLACEHOLDER_GEMINI_API_KEY' # API key for Gemini model access

openai:
gptApiKey: 'PLACEHOLDER_OPENAI_API_KEY'

cognito:
appClientId: 'PLACEHOLDER_APP_CLIENT_ID'
appClientSecret: 'PLACEHOLDER_APP_CLIENT_SECRET'
userPoolId: 'PLACEHOLDER_USER_POOL_ID'
region: 'us-east-1'

jwt:
secret: 'development_secret_key_change_in_prod' # A secret string used to sign JWT tokens
expiry: 1440 # Token expiry time in minutes (e.g. 1440 = 24 hours)

smtp:
host: 'smtp.gmail.com' # SMTP server host for sending emails (example is Gmail SMTP)
port: 587 # SMTP server port (587 for TLS)
username: '[email protected]' # Email username (your email address)
password: 'PLACEHOLDER_APP_PASSWORD' # Password for the email or app-specific password if 2FA is enabled
senderEmail: '[email protected]' # The 'from' email address used when sending mails
senderName: 'DebateAI Team'

googleOAuth:
clientID: 'PLACEHOLDER_GOOGLE_CLIENT_ID' # Google OAuth Client ID for OAuth login

redis:
addr: 'localhost:6379'
password: ''
db: 0
18 changes: 7 additions & 11 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,17 @@ type Config struct {
}

SMTP struct { // Add SMTP configuration
Host string
Port int
Username string // Gmail address
Password string // App Password
SenderEmail string // Same as Username for Gmail
SenderName string
Host string `yaml:"host"`
Port int `yaml:"port"`
Username string `yaml:"username"` // Gmail address
Password string `yaml:"password"` // App Password
SenderEmail string `yaml:"senderEmail"` // Same as Username for Gmail
SenderName string `yaml:"senderName"`
}
GoogleOAuth struct {
ClientID string `yaml:"clientID"`
}
Redis struct {
URL string `yaml:"url"`
Password string `yaml:"password"`
DB int `yaml:"db"`
}

}

// LoadConfig reads the configuration file
Expand Down
6 changes: 3 additions & 3 deletions backend/controllers/admin_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func GetComments(ctx *gin.Context) {
dbCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var comments []models.Comment
var comments []models.ModeratedComment

// Get team debate messages
teamDebateCollection := db.MongoDatabase.Collection("team_debate_messages")
Expand All @@ -359,7 +359,7 @@ func GetComments(ctx *gin.Context) {
var messages []models.TeamDebateMessage
if err := cursor1.All(dbCtx, &messages); err == nil {
for _, msg := range messages {
comments = append(comments, models.Comment{
comments = append(comments, models.ModeratedComment{
ID: msg.ID,
Type: "team_debate_message",
Content: msg.Message,
Expand All @@ -383,7 +383,7 @@ func GetComments(ctx *gin.Context) {
var chatMessages []models.TeamChatMessage
if err := cursor2.All(dbCtx, &chatMessages); err == nil {
for _, msg := range chatMessages {
comments = append(comments, models.Comment{
comments = append(comments, models.ModeratedComment{
ID: msg.ID,
Type: "team_chat_message",
Content: msg.Message,
Expand Down
17 changes: 9 additions & 8 deletions backend/controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"context"
"fmt"
"log"
"math"
"net/http"
"os"
Expand Down Expand Up @@ -84,9 +85,9 @@ func GoogleLogin(ctx *gin.Context) {
LastRatingUpdate: now,
AvatarURL: avatarURL,
IsVerified: true,
Score: 0, // Initialize gamification score
Score: 0, // Initialize gamification score
Badges: []string{}, // Initialize badges array
CurrentStreak: 0, // Initialize streak
CurrentStreak: 0, // Initialize streak
CreatedAt: now,
UpdatedAt: now,
}
Expand Down Expand Up @@ -171,9 +172,9 @@ func SignUp(ctx *gin.Context) {
Password: string(hashedPassword),
IsVerified: false,
VerificationCode: verificationCode,
Score: 0, // Initialize gamification score
Score: 0, // Initialize gamification score
Badges: []string{}, // Initialize badges array
CurrentStreak: 0, // Initialize streak
CurrentStreak: 0, // Initialize streak
CreatedAt: now,
UpdatedAt: now,
}
Expand Down Expand Up @@ -541,9 +542,9 @@ func VerifyToken(ctx *gin.Context) {
func generateJWT(email, secret string, expiryMinutes int) (string, error) {
now := time.Now()
expirationTime := now.Add(time.Minute * time.Duration(expiryMinutes))
log.Printf("JWT Generation - Email: %s, Now: %s, Expiry: %s (in %d minutes)", email, now.Format(time.RFC3339), expirationTime.Format(time.RFC3339), expiryMinutes)

log.Printf("JWT Generation - Now: %s, Expiry: %s (in %d minutes)", now.Format(time.RFC3339), expirationTime.Format(time.RFC3339), expiryMinutes)

claims := jwt.MapClaims{
"sub": email,
"exp": expirationTime.Unix(),
Expand All @@ -555,7 +556,7 @@ func generateJWT(email, secret string, expiryMinutes int) (string, error) {
log.Printf("JWT signing error: %v", err)
return "", err
}

log.Printf("JWT Generated successfully - Expiration Unix: %d", expirationTime.Unix())
return signedToken, nil
}
Expand Down
21 changes: 1 addition & 20 deletions backend/controllers/team_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,7 @@ func JoinTeam(c *gin.Context) {
for _, member := range team.Members {
totalElo += member.Elo
}
<<<<<<< HEAD
if len(team.Members) >= team.MaxSize {
=======
capacity := team.MaxSize
if capacity <= 0 {
capacity = 4
}
if len(team.Members) >= capacity {
>>>>>>> main
c.JSON(http.StatusBadRequest, gin.H{"error": "Team is already full"})
return
}

totalElo += newMember.Elo
newAverageElo := totalElo / float64(len(team.Members)+1)

Expand Down Expand Up @@ -630,19 +619,11 @@ func GetAvailableTeams(c *gin.Context) {
collection := db.GetCollection("teams")
cursor, err := collection.Find(context.Background(), bson.M{
"$expr": bson.M{
<<<<<<< HEAD
"$lt": []interface{}{
bson.M{"$size": "$members"},
"$maxSize",
},
},
=======
"$lt": bson.A{
bson.M{"$size": "$members"},
"$maxSize",
},
},
>>>>>>> main
})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to retrieve teams"})
Expand Down
7 changes: 3 additions & 4 deletions backend/controllers/transcript_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"arguehub/services"
"arguehub/utils"

"os"

"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"os"
)

// SubmitTranscriptsRequest represents the request to submit debate transcripts
Expand Down Expand Up @@ -48,7 +49,7 @@ func SubmitTranscripts(c *gin.Context) {

token = strings.TrimPrefix(token, "Bearer ")
valid, email, err := utils.ValidateTokenAndFetchEmail("./config/config.prod.yml", token, c)
if err != nil || !valid || email == "" {
if err != nil || !valid || email == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid or expired token"})
return
}
Expand Down Expand Up @@ -411,8 +412,6 @@ func UpdatePendingTranscriptsHandler(c *gin.Context) {
return
}

_ = email

err = services.UpdatePendingTranscripts()
if err != nil {
c.JSON(500, gin.H{"error": "Failed to update pending transcripts"})
Expand Down
1 change: 1 addition & 0 deletions backend/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"arguehub/models"
"context"
"fmt"
"log"
"net/url"
"time"

Expand Down
12 changes: 7 additions & 5 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@ go 1.24
toolchain go1.24.4

require (
github.com/casbin/casbin/v2 v2.132.0
github.com/casbin/mongodb-adapter/v3 v3.7.0
github.com/gin-contrib/cors v1.7.2
github.com/gin-gonic/gin v1.10.0
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/google/generative-ai-go v0.20.1
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
github.com/redis/go-redis/v9 v9.16.0
go.mongodb.org/mongo-driver v1.17.3
golang.org/x/crypto v0.36.0
google.golang.org/api v0.228.0
google.golang.org/genai v1.34.0
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/ai v0.8.0 // indirect
cloud.google.com/go/auth v0.15.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
cloud.google.com/go/longrunning v0.5.7 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/casbin/casbin/v2 v2.132.0 // indirect
github.com/casbin/govaluate v1.3.0 // indirect
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
Expand All @@ -44,7 +45,6 @@ require (
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/s2a-go v0.1.9 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
Expand All @@ -57,14 +57,14 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/redis/go-redis/v9 v9.16.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
Expand All @@ -75,6 +75,8 @@ require (
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/time v0.11.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect
google.golang.org/grpc v1.71.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
Expand Down
Loading