add test story

This commit is contained in:
Владимир Фёдоров 2025-06-14 21:28:46 +07:00
parent 77854681a0
commit 3a2980e9d0
7 changed files with 50 additions and 5 deletions

15
.vscode/launch.json vendored
View File

@ -15,6 +15,21 @@
],
"cwd": "${workspaceFolder}",
"buildFlags": "-tags local"
},
{
"name": "Local Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/evening_detective",
"args": [
"--local"
],
"cwd": "${workspaceFolder}",
"buildFlags": "-tags local",
"env": {
"STORY_FILENAME": "./internal/tests/story.json"
}
}
]
}

View File

@ -1,8 +1,12 @@
{
"cSpell.words": [
"Приложение",
"Текст",
"Точка",
"точки",
"AUTOINCREMENT",
"gwmux",
"localtime",
"palces"
]
}

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"evening_detective/internal/app"
"evening_detective/internal/config"
"evening_detective/internal/services"
"evening_detective/internal/services/story_service"
proto "evening_detective/proto"
@ -30,7 +31,9 @@ func main() {
if err != nil {
panic(err)
}
storyService, err := story_service.NewStoryService()
storyFilepath := config.GetStoryFilePath()
storyService, err := story_service.NewStoryService(storyFilepath)
if err != nil {
log.Fatalln(err)
}

BIN
data/db/store_09.06.2025.db Normal file

Binary file not shown.

11
internal/config/config.go Normal file
View File

@ -0,0 +1,11 @@
package config
import "os"
func GetStoryFilePath() string {
storyFilename := os.Getenv("STORY_FILENAME")
if storyFilename != "" {
return storyFilename
}
return "./data/story/story.json"
}

View File

@ -2,7 +2,8 @@ package story_service
import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"strings"
)
@ -44,11 +45,12 @@ type StoryService struct {
story *Story
}
func NewStoryService() (*StoryService, error) {
data, err := os.ReadFile("./data/story/story.json")
func NewStoryService(filepath string) (*StoryService, error) {
data, err := os.ReadFile(filepath)
if err != nil {
return nil, errors.New("Файл истории не найден")
return nil, fmt.Errorf("story file %s not found", filepath)
}
log.Printf("load story from: %s", filepath)
story := &Story{}
if err := json.Unmarshal(data, story); err != nil {
return nil, err

10
internal/tests/story.json Normal file
View File

@ -0,0 +1,10 @@
{
"places": [
{
"code": "Т-1",
"name": "Точка 1",
"text": "Текст точки 1",
"applications": [{ "name": "application 1" }]
}
]
}