Replace all infra services with interfaces
This commit is contained in:
78
internal/entity/recognition.go
Normal file
78
internal/entity/recognition.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package entity
|
||||
|
||||
// RecognitionStatus представляет статус операции транскрипции
|
||||
type RecognitionStatus int
|
||||
|
||||
const (
|
||||
// RecognitionStatusInProgress - операция в процессе выполнения
|
||||
RecognitionStatusInProgress RecognitionStatus = iota
|
||||
// RecognitionStatusCompleted - операция завершена успешно
|
||||
RecognitionStatusCompleted
|
||||
// RecognitionStatusFailed - операция завершена с ошибкой
|
||||
RecognitionStatusFailed
|
||||
)
|
||||
|
||||
// String возвращает строковое представление статуса
|
||||
func (s RecognitionStatus) String() string {
|
||||
switch s {
|
||||
case RecognitionStatusInProgress:
|
||||
return "in_progress"
|
||||
case RecognitionStatusCompleted:
|
||||
return "completed"
|
||||
case RecognitionStatusFailed:
|
||||
return "failed"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// RecognitionResult представляет результат операции транскрипции
|
||||
type RecognitionResult struct {
|
||||
Status RecognitionStatus
|
||||
Error string // Текст ошибки (заполняется при StatusFailed)
|
||||
}
|
||||
|
||||
// NewInProgressResult создает результат для операции в процессе выполнения
|
||||
func NewInProgressResult() *RecognitionResult {
|
||||
return &RecognitionResult{
|
||||
Status: RecognitionStatusInProgress,
|
||||
}
|
||||
}
|
||||
|
||||
// NewCompletedResult создает результат для успешно завершенной операции
|
||||
func NewCompletedResult() *RecognitionResult {
|
||||
return &RecognitionResult{
|
||||
Status: RecognitionStatusCompleted,
|
||||
}
|
||||
}
|
||||
|
||||
// NewFailedResult создает результат для операции, завершенной с ошибкой
|
||||
func NewFailedResult(errorText string) *RecognitionResult {
|
||||
return &RecognitionResult{
|
||||
Status: RecognitionStatusFailed,
|
||||
Error: errorText,
|
||||
}
|
||||
}
|
||||
|
||||
// IsInProgress проверяет, находится ли операция в процессе выполнения
|
||||
func (r *RecognitionResult) IsInProgress() bool {
|
||||
return r.Status == RecognitionStatusInProgress
|
||||
}
|
||||
|
||||
// IsCompleted проверяет, завершена ли операция успешно
|
||||
func (r *RecognitionResult) IsCompleted() bool {
|
||||
return r.Status == RecognitionStatusCompleted
|
||||
}
|
||||
|
||||
// IsFailed проверяет, завершена ли операция с ошибкой
|
||||
func (r *RecognitionResult) IsFailed() bool {
|
||||
return r.Status == RecognitionStatusFailed
|
||||
}
|
||||
|
||||
// GetError возвращает текст ошибки (только для операций, завершенных с ошибкой)
|
||||
func (r *RecognitionResult) GetError() string {
|
||||
if r.IsFailed() {
|
||||
return r.Error
|
||||
}
|
||||
return ""
|
||||
}
|
Reference in New Issue
Block a user