add actions and auth

This commit is contained in:
2025-05-17 12:08:44 +07:00
parent 4bd18ee756
commit e1b342d12c
14 changed files with 487 additions and 246 deletions
@@ -0,0 +1,41 @@
package story_service
import (
"encoding/json"
"errors"
"os"
)
type Story struct {
Places []*Place `json:"places"`
}
type Place struct {
Code string `json:"code"`
Text string `json:"text"`
}
type StoryService struct {
story *Story
}
func NewStoryService() (*StoryService, error) {
data, err := os.ReadFile("./story/story.json")
if err != nil {
return nil, err
}
story := &Story{}
if err := json.Unmarshal(data, story); err != nil {
return nil, err
}
return &StoryService{story: story}, nil
}
func (s *StoryService) GetPlace(code string) (*Place, error) {
for _, place := range s.story.Places {
if place.Code == code {
return place, nil
}
}
return nil, errors.New("place not found")
}