Feat: settings repo
This commit is contained in:
		
							
								
								
									
										35
									
								
								repos/settings.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								repos/settings.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| package repos | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"gralias/models" | ||||
|  | ||||
| 	"github.com/jmoiron/sqlx" | ||||
| ) | ||||
|  | ||||
| type SettingsRepo interface { | ||||
| 	SettingsGetByRoomID(ctx context.Context, roomID string) (*models.GameSettings, error) | ||||
| 	SettingsUpdate(ctx context.Context, settings *models.GameSettings) error | ||||
| 	SettingsDeleteByRoomID(ctx context.Context, roomID string) error | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) SettingsGetByRoomID(ctx context.Context, roomID string) (*models.GameSettings, error) { | ||||
| 	settings := &models.GameSettings{} | ||||
| 	err := sqlx.GetContext(ctx, p.DB, settings, `SELECT * FROM settings WHERE room_id = ?`, roomID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return settings, nil | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) SettingsUpdate(ctx context.Context, s *models.GameSettings) error { | ||||
| 	db := getDB(ctx, p.DB) | ||||
| 	_, err := db.ExecContext(ctx, `UPDATE settings SET language = ?, room_pass = ?, turn_time = ?, turn_seconds_left = ? WHERE room_id = ?`, s.Language, s.RoomPass, s.RoundTime, s.TurnSecondsLeft, s.RoomID) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) SettingsDeleteByRoomID(ctx context.Context, roomID string) error { | ||||
| 	db := getDB(ctx, p.DB) | ||||
| 	_, err := db.ExecContext(ctx, `DELETE FROM settings WHERE room_id = ?`, roomID) | ||||
| 	return err | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder