generated from VLADIMIR/template
add tests
This commit is contained in:
+5
-5
@@ -9,17 +9,17 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
type fileService struct {
|
||||
filepath string
|
||||
}
|
||||
|
||||
func NewStoryStorage(filepath string) story_service.IStoryStorage {
|
||||
return &service{
|
||||
func NewFileStoryStorage(filepath string) story_service.IStoryStorage {
|
||||
return &fileService{
|
||||
filepath: filepath,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *service) Load(ctx context.Context) (*story_service.Story, error) {
|
||||
func (s *fileService) Load(ctx context.Context) (*story_service.Story, error) {
|
||||
data, err := os.ReadFile(s.filepath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("story file %s not found", s.filepath)
|
||||
@@ -32,7 +32,7 @@ func (s *service) Load(ctx context.Context) (*story_service.Story, error) {
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (s *service) Save(ctx context.Context, story *story_service.Story) error {
|
||||
func (s *fileService) Save(ctx context.Context, story *story_service.Story) error {
|
||||
data, err := json.Marshal(story)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -0,0 +1,25 @@
|
||||
package story_storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"evening_detective/internal/services/story_service"
|
||||
)
|
||||
|
||||
type varService struct {
|
||||
story *story_service.Story
|
||||
}
|
||||
|
||||
func NewVarStoryStorage(story *story_service.Story) story_service.IStoryStorage {
|
||||
return &varService{
|
||||
story: story,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *varService) Load(ctx context.Context) (*story_service.Story, error) {
|
||||
return s.story, nil
|
||||
}
|
||||
|
||||
func (s *varService) Save(ctx context.Context, story *story_service.Story) error {
|
||||
s.story = story
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user