feat: first init

This commit is contained in:
Cereska
2026-02-26 08:21:58 -05:00
commit a1b599d030
11 changed files with 188 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
package repositories
import (
"chat/internal/models"
"fmt"
"time"
)
func SendChatMessage(msg string, user *models.User, channel *models.Channel) error {
// Handle empty message
if len(msg) < 1 {
return fmt.Errorf("message cannot be empty")
}
// Handle long message
if len(msg) > 500 {
return fmt.Errorf("message too long")
}
// Check if user is banned
banned := user.IsBanned
if banned {
return fmt.Errorf("user: %s, is banned", user.ID)
}
// Send message to channel
channel.Send(models.Message{
Content: msg,
Sender: user,
Timestamp: time.Now(),
})
return nil
}