refactor: rename BroadcastMessage model to ServerMessage

🤖
This commit is contained in:
Sebastian Mark 2024-10-20 21:59:18 +02:00
parent d2e34e84f8
commit 337e5b0ed3
4 changed files with 6 additions and 6 deletions

View file

@ -8,7 +8,7 @@ import (
) )
// BroadcastMessage sends a message to all connected WebSocket clients. // BroadcastMessage sends a message to all connected WebSocket clients.
func BroadcastMessage(clients map[*websocket.Conn]*models.Client, message models.BroadcastMessage) { func BroadcastMessage(clients map[*websocket.Conn]*models.Client, message models.ServerMessage) {
// Marshal the message into JSON format // Marshal the message into JSON format
jsonMessage, err := json.Marshal(message) jsonMessage, err := json.Marshal(message)
if err != nil { if err != nil {

View file

@ -58,7 +58,7 @@ func ResetPomodoro(clients map[*websocket.Conn]*models.Client) {
mu.Unlock() mu.Unlock()
// Broadcast the reset message to all clients // Broadcast the reset message to all clients
broadcast.BroadcastMessage(clients, models.BroadcastMessage{ broadcast.BroadcastMessage(clients, models.ServerMessage{
Mode: "none", Mode: "none",
Session: 0, Session: 0,
MaxSession: 0, MaxSession: 0,

View file

@ -20,7 +20,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
default: default:
// Broadcast the current state to all clients // Broadcast the current state to all clients
if !IsPomodoroPaused() { if !IsPomodoroPaused() {
broadcast.BroadcastMessage(clients, models.BroadcastMessage{ broadcast.BroadcastMessage(clients, models.ServerMessage{
Mode: mode, Mode: mode,
Session: session, Session: session,
MaxSession: PomodoroConfig.Sessions, MaxSession: PomodoroConfig.Sessions,
@ -33,7 +33,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
} }
// Final broadcast when time reaches zero // Final broadcast when time reaches zero
broadcast.BroadcastMessage(clients, models.BroadcastMessage{ broadcast.BroadcastMessage(clients, models.ServerMessage{
Mode: mode, Mode: mode,
Session: session, Session: session,
MaxSession: PomodoroConfig.Sessions, MaxSession: PomodoroConfig.Sessions,

View file

@ -1,7 +1,7 @@
package models package models
// BroadcastMessage represents the data sent to the client via WebSocket. // ServerMessage represents the data sent to the client via WebSocket.
type BroadcastMessage struct { type ServerMessage struct {
Mode string `json:"mode"` // "Work", "ShortBreak", or "LongBreak" Mode string `json:"mode"` // "Work", "ShortBreak", or "LongBreak"
Session int `json:"session"` // Current session number Session int `json:"session"` // Current session number
MaxSession int `json:"max_session"` // Total number of sessions MaxSession int `json:"max_session"` // Total number of sessions