Enha: use of db methods

This commit is contained in:
Grail Finder
2025-07-02 12:55:50 +03:00
parent b66f9c4c06
commit 9973546aad
6 changed files with 89 additions and 78 deletions

View File

@ -42,17 +42,20 @@ func HandleCreateRoom(w http.ResponseWriter, r *http.Request) {
}
fi.State.RoomID = room.ID
fi.Room = room
fi.Room.IsPublic = true // hardcode for local test; move to form
if err := repo.CreateRoom(r.Context(), room); err != nil {
if err := repo.RoomCreate(r.Context(), room); err != nil {
abortWithError(w, err.Error())
return
}
if err := saveFullInfo(fi); err != nil {
msg := "failed to set current room to session"
log.Error(msg, "error", err)
abortWithError(w, msg)
if err := repo.PlayerSetRoomID(fi.State.Username, room.ID); err != nil {
abortWithError(w, err.Error())
return
}
// if err := saveFullInfo(fi); err != nil {
// msg := "failed to set current room to session"
// log.Error(msg, "error", err)
// abortWithError(w, msg)
// return
// }
notify(models.NotifyRoomListUpdate, "")
tmpl, err := template.ParseGlob("components/*.html")
if err != nil {
@ -198,7 +201,7 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
func HandleJoinRoom(w http.ResponseWriter, r *http.Request) {
roomID := r.URL.Query().Get("id")
room, err := getRoomByID(roomID)
room, err := repo.RoomGetByID(r.Context(), roomID)
if err != nil {
abortWithError(w, err.Error())
return