39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package usecase
|
|
|
|
import (
|
|
"chat/internal/domain/repository"
|
|
"chat/internal/domain/usecase"
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
type matchmakingUseCase struct {
|
|
matchmakingRepo repository.MatchmakingRepository
|
|
}
|
|
|
|
// NewMatchmakingUseCase 創建新的配對 UseCase
|
|
func NewMatchmakingUseCase(matchmakingRepo repository.MatchmakingRepository) usecase.MatchmakingUseCase {
|
|
return &matchmakingUseCase{
|
|
matchmakingRepo: matchmakingRepo,
|
|
}
|
|
}
|
|
|
|
// JoinQueue 加入配對佇列
|
|
func (u *matchmakingUseCase) JoinQueue(ctx context.Context, uid string) (status string, err error) {
|
|
status, _, err = u.matchmakingRepo.JoinQueue(ctx, uid)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to join queue: %w", err)
|
|
}
|
|
return status, nil
|
|
}
|
|
|
|
// GetStatus 查詢配對狀態
|
|
func (u *matchmakingUseCase) GetStatus(ctx context.Context, uid string) (status string, roomID string, err error) {
|
|
status, roomID, err = u.matchmakingRepo.GetMatchStatus(ctx, uid)
|
|
if err != nil {
|
|
return "", "", fmt.Errorf("failed to get match status: %w", err)
|
|
}
|
|
return status, roomID, nil
|
|
}
|
|
|