Feat: styles and session

This commit is contained in:
Grail Finder
2025-05-02 12:34:58 +03:00
parent d18855cd49
commit cd1100d4b1
10 changed files with 164 additions and 13 deletions

44
handlers/game.go Normal file
View File

@ -0,0 +1,44 @@
package handlers
import (
"context"
"golias/models"
"html/template"
"net/http"
)
func HandleCreateRoom(w http.ResponseWriter, r *http.Request) {
// parse payload
payload := &models.RoomReq{
RoomPass: r.PostFormValue("room_pass"),
RoomName: r.PostFormValue("room_name"),
}
// create a room
room, err := createRoom(r.Context(), payload)
if err != nil {
msg := "failed to create a room"
log.Error(msg, "error", err)
abortWithError(w, msg)
return
}
ctx := context.WithValue(r.Context(), "current_room", room.ID)
ctx, err = updateRoomInSession(ctx, room.ID)
if err != nil {
msg := "failed to set current room to session"
log.Error(msg, "error", err)
abortWithError(w, msg)
return
}
// send msg of created room
// h.Broker.Notifier <- broker.NotificationEvent{
// EventName: models.MsgRoomListUpdate,
// Payload: fmt.Sprintf("%s created a room named %s", r.CreatorName, r.RoomName),
// }
// return html
tmpl, err := template.ParseGlob("components/*.html")
if err != nil {
abortWithError(w, err.Error())
return
}
tmpl.ExecuteTemplate(w, "main", nil)
}