Feat: remove rooms with no action
This commit is contained in:
		| @@ -3,6 +3,7 @@ package repos | ||||
| import ( | ||||
| 	"context" | ||||
| 	"gralias/models" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/jmoiron/sqlx" | ||||
| ) | ||||
| @@ -13,6 +14,7 @@ type ActionsRepo interface { | ||||
| 	ActionGetLastClue(ctx context.Context, roomID string) (*models.Action, error) | ||||
| 	ActionDeleteByRoomID(ctx context.Context, roomID string) error | ||||
| 	ActionDeleteOrphaned(ctx context.Context) error | ||||
| 	ActionGetLastTimeByRoomID(ctx context.Context, roomID string) (time.Time, error) | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) ActionList(ctx context.Context, roomID string) ([]models.Action, error) { | ||||
| @@ -26,10 +28,20 @@ func (p *RepoProvider) ActionList(ctx context.Context, roomID string) ([]models. | ||||
|  | ||||
| func (p *RepoProvider) ActionCreate(ctx context.Context, a *models.Action) error { | ||||
| 	db := getDB(ctx, p.DB) | ||||
| 	_, err := db.ExecContext(ctx, `INSERT INTO actions (room_id, actor, actor_color, action_type, word, word_color, number_associated, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, a.RoomID, a.Actor, a.ActorColor, a.Action, a.Word, a.WordColor, a.Number, a.CreatedAt.UnixNano()) | ||||
| 	_, err := db.ExecContext(ctx, `INSERT INTO actions (room_id, actor, actor_color, action_type, word, word_color, number_associated, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, a.RoomID, a.Actor, a.ActorColor, a.Action, a.Word, a.WordColor, a.Number, time.Now()) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) ActionGetLastTimeByRoomID(ctx context.Context, roomID string) (time.Time, error) { | ||||
| 	lastTime := time.Time{} | ||||
| 	err := sqlx.GetContext(ctx, p.DB, &lastTime, | ||||
| 		`SELECT created_at FROM actions WHERE room_id = ? ORDER BY created_at DESC LIMIT 1`, roomID) | ||||
| 	if err != nil { | ||||
| 		return lastTime, err | ||||
| 	} | ||||
| 	return lastTime, nil | ||||
| } | ||||
|  | ||||
| func (p *RepoProvider) ActionGetLastClue(ctx context.Context, roomID string) (*models.Action, error) { | ||||
| 	action := &models.Action{} | ||||
| 	err := sqlx.GetContext(ctx, p.DB, action, `SELECT actor, actor_color, action_type, word, word_color, number_associated, created_at FROM actions WHERE room_id = ? AND action_type = 'gave_clue' ORDER BY created_at DESC LIMIT 1`, roomID) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder