forked from mtusi2026/mtusi2026lab3
refactor: разделил приложение на domain application adapters и HTTP DTO
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
repository Repository
|
||||
cursors *CursorCodec
|
||||
sessionTTL time.Duration
|
||||
now func() time.Time
|
||||
}
|
||||
|
||||
func NewService(repository Repository, cursors *CursorCodec, sessionTTL time.Duration) (*Service, error) {
|
||||
if repository == nil {
|
||||
return nil, fmt.Errorf("repository is required")
|
||||
}
|
||||
if cursors == nil {
|
||||
return nil, fmt.Errorf("cursor codec is required")
|
||||
}
|
||||
if sessionTTL <= 0 {
|
||||
return nil, fmt.Errorf("session TTL must be positive")
|
||||
}
|
||||
return &Service{
|
||||
repository: repository,
|
||||
cursors: cursors,
|
||||
sessionTTL: sessionTTL,
|
||||
now: func() time.Time { return time.Now().UTC() },
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user